Skip to content

Conversation

@tommantonclery
Copy link

Fixes #16000.

When running cargo test --no-run on a proc-macro crate with a dev-dependency on a dylib, Cargo was incorrectly passing -C prefer-dynamic to the test harness.

That caused rustc to try to link both rlib and dylib forms of std and its transitive crates, resulting in errors like:

error: cannot satisfy dependencies so `std` only shows up once

What changed

  • Adjusted the logic in core/compiler so that -C prefer-dynamic is only applied when compiling an actual proc-macro crate.
  • Test harnesses (even for proc-macro crates) no longer receive -C prefer-dynamic.

Why

This resolves the duplicate std/core/alloc linkage errors and makes cargo test --no-run consistent with cargo build.

@rustbot rustbot added A-build-execution Area: anything dealing with executing the compiler S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 30, 2025
@rustbot
Copy link
Collaborator

rustbot commented Sep 30, 2025

r? @epage

rustbot has assigned @epage.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 30, 2025
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 30, 2025
@Firestar99
Copy link

Just noticed this PR fixing my issue, could we get it reviewed and merged?

Copy link
Member

@weihanglo weihanglo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't yet thought hard on this, but it at leaste requires a test to make sure it fixes the real issue

BTW, we usually follow a variant of atomic commit pattern:

  1. Commit a test that asserts the current buggy behavior (passes).
  2. In the next commit, fix the bug and update the test/snapshot.

Every commit passes, and the test/snapshot diff shows the behavior change.

View changes since this review

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

Labels

A-build-execution Area: anything dealing with executing the compiler S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cargo test fails to build when downstream crate declares crate-type = ["rlib", "dylib"]

5 participants