Skip to content

Commit

Permalink
fix(build-std): always link to std when testing/running proc-macros
Browse files Browse the repository at this point in the history
  • Loading branch information
weihanglo committed Nov 22, 2024
1 parent 33e6b33 commit 4527567
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
5 changes: 4 additions & 1 deletion src/cargo/core/compiler/compilation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,10 @@ impl<'gctx> Compilation<'gctx> {
// libs from the sysroot that ships with rustc. This may not be
// required (at least I cannot craft a situation where it
// matters), but is here to be safe.
if self.gctx.cli_unstable().build_std.is_none() {
if self.gctx.cli_unstable().build_std.is_none() ||
// Proc macros dynamically link to std, so set it anyway.
pkg.proc_macro()
{
search_path.push(self.sysroot_target_libdir[&kind].clone());
}
}
Expand Down
8 changes: 0 additions & 8 deletions tests/build-std/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,15 +386,7 @@ fn test_proc_macro() {
[COMPILING] foo v0.0.0 ([ROOT]/foo)
[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[RUNNING] unittests src/lib.rs (target/debug/deps/foo-[HASH])
dyld[[..]]: Library not loaded: @rpath/libstd-[HASH].dylib
Referenced from: <[..]> [ROOT]/foo/target/debug/deps/foo-[HASH]
Reason: tried: '[ROOT]/foo/target/debug/deps/libstd-[HASH].dylib' (no such file), '[ROOT]/foo/target/debug/libstd-[HASH].dylib' (no such file), '/usr/local/lib/libstd-[HASH].dylib' (no such file), '/usr/lib/libstd-[HASH].dylib' (no such file, not in dyld cache)
[ERROR] test failed, to rerun pass `--lib`
Caused by:
process didn't exit successfully: `[ROOT]/foo/target/debug/deps/foo-[HASH]` ([..])
"#]])
.with_status(101)
.run();
}

0 comments on commit 4527567

Please sign in to comment.