-
Notifications
You must be signed in to change notification settings - Fork 447
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(test_env): export canonical CARGO_BIN_EXE env variable #842
Conversation
@@ -8,3 +8,6 @@ build:rustfmt --output_groups=+rustfmt_checks | |||
# Enable clippy for all targets in the workspace | |||
build:clippy --aspects=//rust:defs.bzl%rust_clippy_aspect | |||
build:clippy --output_groups=+clippy_checks | |||
|
|||
# https://bazel.googlesource.com/bazel/+/master/site/docs/windows.md#enable-symlink-support |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
while doc suggests to enable runfiles (build --enable_runfiles
), enabling it makes process_wrapper/std_err
test fails somehow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the failure you see when enabling this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I ran some tests and it seems to test no problem for me. Though I used
# https://bazel.googlesource.com/bazel/+/master/site/docs/windows.md#enable-symlink-support | |
# https://bazel.googlesource.com/bazel/+/master/site/docs/windows.md#enable-symlink-support | |
startup --windows_enable_symlinks |
Per the recommendation from https://docs.bazel.build/versions/main/windows.html
Does that help here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
weirdly I tried again and couldn't repro the error. maybe one off from the system I used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these test failures are by enabling runfiles, which is outside of test_env/.
(03:37:10) FAIL: //test/process_wrapper:stdout_test (see C:/b/h3ziskxk/execroot/rules_rust/bazel-out/x64_windows-fastbuild/testlogs/test/process_wrapper/stdout_test/test_attempts/attempt_1.log)
Hmmm, could you try to use https://github.com/bazelbuild/rules_rust/blob/main/tools/runfiles/runfiles.rs#L55 in the test? Using runfiles library is how everything rusty should find runfiles. If that works you don't need symlinks on Windows. Warning, I've never testing that code on Windows, I was just hoping it would work :) |
@hlopko Happy to try, but mind elaborate bit as I may misunderstand few things? It looks like current test want to verify path to binary via env variable (https://github.com/bazelbuild/rules_rust/pull/842/files#diff-1bf83a2d7f83a35ad4c8411142f1bd35af8656c4ac54beb38bd291018e29f9e9R3). This fails on Windows, due to symlink does not created to relative path to runfiles while env variable is set to short_path, which is relative to cwd test is running.
|
Oh just ignore me, I misinterpreted the problem and the test. Now I'm taking a deeper look.
CC @UebelAndre |
|
No, Can anyone describe what's the purpose of |
The docs say:
So seems it's intended to be an absolute path which I'd expect to be something from |
Then sounds like you should use Or you can still use |
|
|
Friendly ping on this PR 😄 What's the remaining actions for it? |
Sorry to get back late. I think process_wrapper solves partially. For example, this test https://github.com/bazelbuild/rules_rust/pull/842/files#diff-1bf83a2d7f83a35ad4c8411142f1bd35af8656c4ac54beb38bd291018e29f9e9R27 expected $rootpath expanded path should be relative to cwd, which hits same issues as CARGO_BIN_EXE (without help of process_wrapper). This test fails on Windows as relative path is constructed to runfiles points to symlinked binary which doesn't exist. |
@@ -8,3 +8,6 @@ build:rustfmt --output_groups=+rustfmt_checks | |||
# Enable clippy for all targets in the workspace | |||
build:clippy --aspects=//rust:defs.bzl%rust_clippy_aspect | |||
build:clippy --output_groups=+clippy_checks | |||
|
|||
# https://bazel.googlesource.com/bazel/+/master/site/docs/windows.md#enable-symlink-support |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I ran some tests and it seems to test no problem for me. Though I used
# https://bazel.googlesource.com/bazel/+/master/site/docs/windows.md#enable-symlink-support | |
# https://bazel.googlesource.com/bazel/+/master/site/docs/windows.md#enable-symlink-support | |
startup --windows_enable_symlinks |
Per the recommendation from https://docs.bazel.build/versions/main/windows.html
Does that help here?
rust/private/rustc.bzl
Outdated
env["CARGO_BIN_EXE_" + dep_crate_info.output.basename] = dep_crate_info.output.short_path | ||
# Trying to make CARGO_BIN_EXE_{} canonical across platform by strip out extension if exists | ||
env_basename = dep_crate_info.output.basename[:-(1 + len(dep_crate_info.output.extension))] if len(dep_crate_info.output.extension) > 0 else dep_crate_info.output.basename | ||
env["CARGO_BIN_EXE_" + env_basename] = "${{pwd}}/{}".format(dep_crate_info.output.short_path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this needs to be output.path
since ${pwd}
points to the exec root
env["CARGO_BIN_EXE_" + env_basename] = "${{pwd}}/{}".format(dep_crate_info.output.short_path) | |
env["CARGO_BIN_EXE_" + env_basename] = "${{pwd}}/{}".format(dep_crate_info.output.path) |
Ok, I think I understand what's happening now. I think this is incorrect rules_rust/test/test_env/tests/run.rs Line 3 in c2f5701
The rules do not really have a distinction between unit and integration test targets so I don't know that it's currently possible to match the behavior of @kwonoj What do you think of that? Also (slight tangent), I'm not sure how the variable manages to only be set for tests. That block of code is a bit confusing... rules_rust/rust/private/rustc.bzl Lines 501 to 506 in c2f5701
|
As long as It is more desirable if rule itself works without enabling symlink for the Windows, but current impression is existing rules are heavily relying on it and changing those behaviors might cause big breaking changes unfortunately. |
I think #861 is probably the most reasonable state for My opinion is that windows should be expected to enable symlinking unless there's a sizable surge in windows users who are willing to contribute to the rules and change that. In a perfect world we wouldn't require symlinking but there's currently not enough windows expertise or bandwidth to handle all those cases 😞. The best we can currently offer is to try to make the rules work with windows systems that conform to linux-style things (like symlinks). Does that help advance the PR and solve for the functionality you're after? |
Hey, friendly ping here. Is there anything I can do to help with this PR? |
Sorry, on a sick leave couldn't have access for a while. I'll try to get back asap. |
Sorry for taking this long, tied with daily work and had sick leave as well. I have updated PR for cargo_env variable as suggested. It requires symlink still, backs to relative path calculation instead of
I agree with this, and the reason I brought PR with enable symlink for Windows as well. I do agree if this is greenfield implementation, or relatively easy to change without symlink it is much desired behavior. Eventually that'd be ideal goal, but I do expect it'll require non trivial size of effort with potentially noticeable breaking changes to existing platforms. For now, the best path seems to let Windows users aware of the prerequisites to enable symlink. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me! Thank you so much!
Hey, no need to apologize at all. Health has to come first and then you gotta pay the bills. Hope all is well with you 😄
Again, this looks good to me, thanks so much for putting this together!
Yeah, hopefully maintainers and contributors can work on achieving this goal together! |
This PR attempts to support
test_env
test on Windows platform. Mainly, PR includes changes to export canonical env variableCARGO_BIN_EXE_[basename]
without file extension regardless on platforms.One thing this PR doesn't change is behavior around runfiles. Current test, and path expectation around exported
CARGO_BIN_EXE
relies on runfiles with symlink which is not enabled by default on Windows (https://bazel.googlesource.com/bazel/+/master/site/docs/windows.md#enable-symlink-support). Instead of fixing those, PR attempts to workaround by enabling symlink viabazelrc
, which consumers of this rule also required to enable symlink support. I am not sure if this is expected or not - but probably worth separate discussion.