Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
30 changes: 30 additions & 0 deletions tests/build-std/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,3 +360,33 @@ fn remap_path_scope() {
)
.run();
}

#[cargo_test(build_std_real)]
fn test_proc_macro() {
// See rust-lang/cargo#14735
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
edition = "2021"

[lib]
proc-macro = true
"#,
)
.file("src/lib.rs", "")
.build();

p.cargo("test --lib")
.env_remove(cargo_util::paths::dylib_path_envvar())
.build_std()
.with_stderr_data(str![[r#"
[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])

"#]])
.run();
}