-
Notifications
You must be signed in to change notification settings - Fork 481
Replace SYSROOT env var with --sysroot flag #2039
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
Comments
I think this would be a great change! Would you be willing to make a pull-request for it where a new build flag is added ( |
@UebelAndre I'll be more than happy to contribute a PR. I'm not 100% sure but the fix might also remove the need for the custom handling in #1500. I'll verify that. |
Hi @UebelAndre . I finally got some time for this issue. Please take a look #2223. |
rust_toolchain
generates a rust sysroot from collection of toolchain components. The sysroot path is then assigned toRUST_SYSROOT
make variable and ToolchainInfo.sysroot. When constructing rustc compile action, we setToolchainInfo.sysroot
toSYSROOT
env var.Apparently,
SYSROOT
env var isn't read by rustc and I suspect it is currently a no-op. To reproduce the no-op ofSYSROOT
, simply change it to any random string and expect the builds to still succeed.Per rustc doc, we can set
--sysroot
to override the system sysroot (i.e. `rustc --print sysroot). I believe this is needed to prevent rustc from managing to escape the Bazel sandbox and seeing unspecified inputs.As a concrete example, say we have a toolchain defined as
The system sysroot is
Under
~/prebuilt
, there are prebuilt stdlibsSo in addition to the system sysroot which always points to prebuilt stdlibs, rustc compile action sets
-L
to the path of stdlibs built from source. Hence, it fails withFortunately, we can fix this by setting
rustc_flags = ["--sysroot=$(RUST_SYSROOT)"]
to therust_toolchain
. However, the error with multiple std candidates can be confusing because we don't specify the prebuiltlibstd
inrust_toolchain
at all. rustc should not be able to escape the Bazel sandbox.To sort-of fix this issue, one solution is to add
--sysroot
rustc flag to point to the generated sysroot to avoid this issue.The text was updated successfully, but these errors were encountered: