Skip to content

Use cc-rs to detect the default linker, instead of assuming cc#4807

Merged
djc merged 1 commit intorust-lang:mainfrom
jamesmunns:james/use-cc-for-link-detect
Apr 10, 2026
Merged

Use cc-rs to detect the default linker, instead of assuming cc#4807
djc merged 1 commit intorust-lang:mainfrom
jamesmunns:james/use-cc-for-link-detect

Conversation

@jamesmunns
Copy link
Copy Markdown
Contributor

On hosts like illumos, cc is not present in the path, leading to misleading warnings like:

warn: no default linker (`cc`) was found in your PATH
warn: many Rust crates require a system C toolchain to build

However, there is a linker present: gcc. Since this warning at install time is to help ensure the system is prepared to do build.rs work, which typically uses cc-rs, and has this additional metadata for targets, this PR uses the cc-rs infra directly to determine the correct binary to search for. If cc-rs has nothing to say about our particular host, we fall back to the existing "just look for cc in PATH" logic.

There's a little unfortunate song and dance required, as cc-rs doesn't make this information directly available (requiring you to create a Build, which then requires some information like opt-level and host/target triples to get the correct tool path), if this isn't palatable, I can follow up with cc-rs to see if they want to make this metadata a bit more directly obtainable.

I'm not sure the best way to directly test the rustup install process using this branch, if there are docs somewhere I'm happy to run and verify the warning is skipped now on illumos targets.

Copy link
Copy Markdown
Contributor

@djc djc left a comment

Choose a reason for hiding this comment

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

Looks okay to me modulo a few nits, thanks!

(Please squash your changes into a single commit, we prefer to rebase clean history.)

View changes since this review

@jamesmunns jamesmunns force-pushed the james/use-cc-for-link-detect branch from b70c77a to aad36ed Compare April 10, 2026 14:21
@jamesmunns
Copy link
Copy Markdown
Contributor Author

@djc thanks for the review! Fixed nits, looking at how to re-bless the snapshot tests now, feel free to handle it, or I can look at the devguide.

@djc
Copy link
Copy Markdown
Contributor

djc commented Apr 10, 2026

I think the test failures give a hint of how to update the snapshots?

@jamesmunns
Copy link
Copy Markdown
Contributor Author

jamesmunns commented Apr 10, 2026

It's not immediately clear to me how to run the test suite directly. cargo test --all does not run without errors on MacOS, at least. The error says:

[4](https://github.com/rust-lang/rustup/actions/runs/24247005720/job/70795886044#step:14:1145)
thread 'suite::cli_inst_interactive::install_warns_if_default_linker_missing' (122418) panicked at src/test/clitools.rs:230:9:

---- expected: tests/suite/cli_inst_interactive.rs:685:22
++++ actual:   In-memory
   1    1 | ...
   2    2 | warn: no default linker (`cc`) was found in your PATH
   3      - warn: many Rust crates require a system C toolchain to build
        3 + warn: unable to search PATH for a default linker
   4    4 | ...∅

Update with SNAPSHOTS=overwrite

So, once I get tests running, I will try setting that env var. Currently trying to run via bash ci/run.bash.

edit: the error above is from CI, I get different errors when building tests on macos, unrelated to the failing snapshot tests.

@djc
Copy link
Copy Markdown
Contributor

djc commented Apr 10, 2026

You need --features test I think.

@jamesmunns jamesmunns force-pushed the james/use-cc-for-link-detect branch 2 times, most recently from cdabe14 to efa509f Compare April 10, 2026 15:14
@jamesmunns
Copy link
Copy Markdown
Contributor Author

jamesmunns commented Apr 10, 2026

@djc CI is now green! Took a bit more time to use redaction to paper over the now More Helpful error that tells you what toolchain we look for.

minor note: in terms of CI optimization, it might be worth cancelling jobs on first failure, or sequencing the more expensive macos/windows ci runners after the cheaper linux ones pass, or at least cancelling the old run after a new commit is pushed. Not sure if rustup gets enough PRs to make the utilization worth caring about, but there are a couple of ~30m jobs run on mac/win on every commit, and they don't stop if some other error is hit.

@jamesmunns jamesmunns force-pushed the james/use-cc-for-link-detect branch 2 times, most recently from 432a300 to faa757d Compare April 10, 2026 22:30
@jamesmunns jamesmunns force-pushed the james/use-cc-for-link-detect branch from faa757d to 7599df8 Compare April 10, 2026 22:33
@djc djc enabled auto-merge April 10, 2026 22:36
@djc
Copy link
Copy Markdown
Contributor

djc commented Apr 10, 2026

Thanks, looks good!

@djc djc added this pull request to the merge queue Apr 10, 2026
Merged via the queue into rust-lang:main with commit 9b6b629 Apr 10, 2026
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants