Skip to content

Prevent compiletest from overriding the linker for cross-built tests#159059

Open
kulst wants to merge 1 commit into
rust-lang:mainfrom
kulst:compiletest-cross-build-linker-fix
Open

Prevent compiletest from overriding the linker for cross-built tests#159059
kulst wants to merge 1 commit into
rust-lang:mainfrom
kulst:compiletest-cross-build-linker-fix

Conversation

@kulst

@kulst kulst commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Compiletest already avoids passing its default --target when a test provides one explicitly through compile-flags. However, it would still pass the globally configured target linker via -Clinker.

This is problematic for cross-built tests, where the effective compilation target can differ from compiletest's configured target. For example, when compiletest is running with x86_64-unknown-linux-musl as its configured target, a test that explicitly compiles for nvptx64-nvidia-cuda can incorrectly inherit the musl linker (reference).

With this patch the configured target linker is only passed, when the test does not contain a custom --target.

In terms of testing compiletest, a direct unit test would be ideal here. However, make_compile_args is currently difficult to exercise in isolation because it depends on a fully constructed TestCx. Adding such a test would require either non-trivial test setup or a refactor to make the argument construction testable. Therefore, I did not add a test here.

Compiletest already avoids passing its default `--target` when a test
provides one explicitly through compile-flags. However, it would still
pass the globally configured target linker via `-Clinker`.

This is problematic for cross-built tests, where the effective compilation
target can differ from compiletest's configured target. For example, when
compiletest is running with `x86_64-unknown-linux-musl` as its configured
target, a test that explicitly compiles for `nvptx64-nvidia-cuda` can
incorrectly inherit the musl linker.

Avoid passing the configured target linker when the test provides a custom
`--target`, so cross-built tests can use their target's linker defaults or
test-provided linker flags.
@rustbot

rustbot commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred in src/tools/compiletest

cc @jieyouxu

@rustbot rustbot added A-compiletest Area: The compiletest test runner A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Jul 10, 2026
@rustbot

rustbot commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator

r? @wesleywiser

rustbot has assigned @wesleywiser.
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

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @jieyouxu, @oli-obk, @wesleywiser, bootstrap
  • @jieyouxu, @oli-obk, @wesleywiser, bootstrap expanded to 8 candidates
  • Random selection from Mark-Simulacrum, clubby789, jieyouxu, oli-obk, wesleywiser

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

Labels

A-compiletest Area: The compiletest test runner A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants