Skip to content

--sysroot from rustflags is ignored for proc-macro runtime lib search paths #17351

Description

@weihanglo

Problem

cargo careful test fails to run unit tests for proc-macro crates since rust-lang/rust@887804d5686
The test executable is compiled successfully,
but the dynamic loader cannot find the libstd built by cargo-careful:

     Running unittests src/lib.rs (target/debug/build/pm-repro/e6767d554e5978c6/out/pm_repro-e6767d554e5978c6)
.../pm_repro-e6767d554e5978c6: error while loading shared libraries: libstd-120c9d4d8f02a466.so: cannot open shared object file: No such file or directory
error: test failed, to rerun pass `--lib`

This is likely due to #17276.

Before that PR,
Cargo probed --print=sysroot as part of the target probe, which passed custom rustflags to the probing invocation:

rustc <rustflags> [--target <target>] --print=sysroot ...

After, it became a plain rustc --print=sysroot

cargo-careful seems to use https://crates.io/crates/rustc_build_sysroot to build a custom std
and invokes Cargo with --sysroot <careful-sysroot>.
The actual test binary is linked against the custom libstd from cargo-careful sysroot, hence the failure.

Steps

cargo install cargo-careful@0.4.10 --locked
rustup component add rust-src --toolchain nightly

cargo new --lib pm-repro
printf '\n[lib]\nproc-macro = true\n' >> pm-repro/Cargo.toml
cd pm-repro && cargo +nightly careful test

Possible Solution(s)

A few options in my mind:

  • Revert refactor: move sysroot lookup to GlobalContext #17276

  • Respect custom rustflags, though we then need to think about target rustflags and host rustflags interacdtion, which is a bit annoying. Otherwise we couldn't cover below settings.

     [target.aarch64-unknown-linux-gnu]
     rustflags = ["--sysroot", "/opt/sysroots/aarch64"]
     [target.x86_64-unknown-linux-gnu]
     rustflags = ["--sysroot", "/opt/sysroots/x86_64"]

Notes

Original downstream report: RalfJung/cargo-careful#55

Version

GOOD rustc 1.99.0-nightly (7608eb7b0 2026-08-05)
Cargo 7c83d4cc0953b81d823e47d640c64da9b8bd4fac (2026-07-29)

BAD rustc 1.99.0-nightly (84b36a78a 2026-08-06)
Cargo c79e8f89441b3e73d6d65d125c0c745792808c74 (2026-08-04)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions