Skip to content

Don't panic if WASI_SDK_PATH not set when detecting compiler #143752

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 15, 2025

Conversation

pmur
Copy link

@pmur pmur commented Jul 10, 2025

The fedora packaging builds the wasm sysroot outside of the rust build system. Fedora applies a couple of patches related to wasm which I think make this possible. Not panicking seems consistent with the detection logic of other targets when they cannot find cc.

r? @Kobzol

@rustbot
Copy link
Collaborator

rustbot commented Jul 10, 2025

Kobzol is not on the review rotation at the moment.
They may take a while to respond.

@rustbot rustbot added 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, 2025
@Kobzol
Copy link
Member

Kobzol commented Jul 10, 2025

Hi, how does it help you if you return None from this function? Won't that just break the wasi build, if cc isn't properly configured?

In any case, if it does help you, I'd appreciate printing a warning containing the WASI_SDK_PATH environment variable name in it, if the path cannot be found. It is quite useful if you try to build a wasi target, as it tells you what you should configure in order to get it working :)

@cuviper
Copy link
Member

cuviper commented Jul 10, 2025

Won't that just break the wasi build, if cc isn't properly configured?

If not specified, it falls back to the cc crate's default, which is clang for wasm targets -- and that works fine for us.

Also, Fedora uses build.optimized-compiler-builtins = false (pending #143689), and I don't think it needs any cc otherwise.

@Kobzol
Copy link
Member

Kobzol commented Jul 10, 2025

I see. Then use the fallback to the default cc, but if the wask path isn't found, also print a warning, like println!("WARNING: WASI_SDK_PATH environment variable not found, falling back to default cc");. I wonder if we should maybe also keep the panic on CI to make sure we don't fall back by accident 🤔

@pmur pmur force-pushed the murp/no-panic-detect-wasi-cc branch from aca4980 to b859fbd Compare July 11, 2025 19:28
@pmur
Copy link
Author

pmur commented Jul 11, 2025

Would it be ok to restrict panicking to a missing WASI_SDK_PATH envvar and an unset <target>.wasi-root build config?

@Kobzol
Copy link
Member

Kobzol commented Jul 11, 2025

So if I understand it correctly, you are using wasi_root instead of WASI_SDK_PATH? Or you're using neither and you just always depend on the fallback?

There is already a function in bootstrap (

fn wasi_libdir(&self, target: TargetSelection) -> Option<PathBuf> {
) that loads these two things, so it seems that the cc detection logic should also first be accessing the wasi root and only then the WASI_SDK_PATH - assuming that the wasi-root is actually useful for the cc detection (maybe that's not the case).

@Kobzol
Copy link
Member

Kobzol commented Jul 11, 2025

I even see that we already assert this (

let srcdir = builder.wasi_libdir(target).unwrap_or_else(|| {
).

@pmur
Copy link
Author

pmur commented Jul 11, 2025

So if I understand it correctly, you are using wasi_root instead of WASI_SDK_PATH? Or you're using neither and you just always depend on the fallback?

Yes, wasi-root is always set when building a wasm std on fedora.

I don't think wasi-root has meaning for cc detection beyond indicating the default cc/cxx settings might suffice in the absence of WASI_SDK_PATH.

@pmur pmur force-pushed the murp/no-panic-detect-wasi-cc branch from b859fbd to c3980ab Compare July 14, 2025 16:26
@Kobzol
Copy link
Member

Kobzol commented Jul 14, 2025

Thanks.

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Jul 14, 2025

📌 Commit c3980ab has been approved by Kobzol

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 14, 2025
@Kobzol
Copy link
Member

Kobzol commented Jul 14, 2025

@bors r-

Actually, the panic when on CI hasn't been implemented yet. We should make sure to keep the original behavior there.

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jul 14, 2025
They are not always needed when building std, as is the case when
packaging on Fedora. Panic if building from CI, but warn otherwise.
@pmur pmur force-pushed the murp/no-panic-detect-wasi-cc branch from c3980ab to 9bdd3b0 Compare July 14, 2025 20:16
@Kobzol
Copy link
Member

Kobzol commented Jul 14, 2025

Thanks!

@bors r+

@bors
Copy link
Collaborator

bors commented Jul 14, 2025

📌 Commit 9bdd3b0 has been approved by Kobzol

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 14, 2025
Kobzol added a commit to Kobzol/rust that referenced this pull request Jul 14, 2025
… r=Kobzol

Don't panic if WASI_SDK_PATH not set when detecting compiler

The fedora packaging builds the wasm sysroot outside of the rust build system. Fedora applies a couple of patches related to wasm which I think make this possible. Not panicking seems consistent with the detection logic of other targets when they cannot find cc.
jhpratt added a commit to jhpratt/rust that referenced this pull request Jul 15, 2025
… r=Kobzol

Don't panic if WASI_SDK_PATH not set when detecting compiler

The fedora packaging builds the wasm sysroot outside of the rust build system. Fedora applies a couple of patches related to wasm which I think make this possible. Not panicking seems consistent with the detection logic of other targets when they cannot find cc.
bors added a commit that referenced this pull request Jul 15, 2025
Rollup of 16 pull requests

Successful merges:

 - #142301 (tests: Fix duplicated-path-in-error fail with musl)
 - #142936 (rustdoc-json: Structured attributes)
 - #143355 (wrapping shift: remove first bitmask and table)
 - #143630 (Drop `./x suggest`)
 - #143738 (Move several float tests to floats/mod.rs)
 - #143752 (Don't panic if WASI_SDK_PATH not set when detecting compiler)
 - #143820 (Fixed a core crate compilation failure when enabling the `optimize_for_size` feature on some targets)
 - #143837 (Adjust `run_make_support::symbols` helpers)
 - #143878 (Port `#[pointee]` to the new attribute parsing infrastructure)
 - #143907 (core: make `str::split_at_unchecked()` inline)
 - #143910 (Add experimental `backtrace-trace-only` std feature)
 - #143927 (Preserve constness in trait objects up to hir ty lowering)
 - #143935 (rustc_type_ir/walk: move docstring to `TypeWalker` itself)
 - #143938 (Update books)
 - #143941 (update `cfg_select!` documentation)
 - #143948 (Update mdbook to 0.4.52)

Failed merges:

 - #143926 (Remove deprecated fields in bootstrap)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit that referenced this pull request Jul 15, 2025
Rollup of 16 pull requests

Successful merges:

 - #142301 (tests: Fix duplicated-path-in-error fail with musl)
 - #142936 (rustdoc-json: Structured attributes)
 - #143355 (wrapping shift: remove first bitmask and table)
 - #143630 (Drop `./x suggest`)
 - #143738 (Move several float tests to floats/mod.rs)
 - #143752 (Don't panic if WASI_SDK_PATH not set when detecting compiler)
 - #143820 (Fixed a core crate compilation failure when enabling the `optimize_for_size` feature on some targets)
 - #143837 (Adjust `run_make_support::symbols` helpers)
 - #143878 (Port `#[pointee]` to the new attribute parsing infrastructure)
 - #143907 (core: make `str::split_at_unchecked()` inline)
 - #143910 (Add experimental `backtrace-trace-only` std feature)
 - #143927 (Preserve constness in trait objects up to hir ty lowering)
 - #143935 (rustc_type_ir/walk: move docstring to `TypeWalker` itself)
 - #143938 (Update books)
 - #143941 (update `cfg_select!` documentation)
 - #143948 (Update mdbook to 0.4.52)

Failed merges:

 - #143926 (Remove deprecated fields in bootstrap)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit that referenced this pull request Jul 15, 2025
Rollup of 13 pull requests

Successful merges:

 - #142301 (tests: Fix duplicated-path-in-error fail with musl)
 - #143630 (Drop `./x suggest`)
 - #143736 (Give all bytes of TypeId provenance)
 - #143752 (Don't panic if WASI_SDK_PATH not set when detecting compiler)
 - #143837 (Adjust `run_make_support::symbols` helpers)
 - #143878 (Port `#[pointee]` to the new attribute parsing infrastructure)
 - #143905 (Recover and suggest to use `;` to construct array type)
 - #143907 (core: make `str::split_at_unchecked()` inline)
 - #143910 (Add experimental `backtrace-trace-only` std feature)
 - #143927 (Preserve constness in trait objects up to hir ty lowering)
 - #143935 (rustc_type_ir/walk: move docstring to `TypeWalker` itself)
 - #143938 (Update books)
 - #143941 (update `cfg_select!` documentation)

Failed merges:

 - #143926 (Remove deprecated fields in bootstrap)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 6b6c8be into rust-lang:master Jul 15, 2025
11 checks passed
@rustbot rustbot added this to the 1.90.0 milestone Jul 15, 2025
rust-timer added a commit that referenced this pull request Jul 15, 2025
Rollup merge of #143752 - pmur:murp/no-panic-detect-wasi-cc, r=Kobzol

Don't panic if WASI_SDK_PATH not set when detecting compiler

The fedora packaging builds the wasm sysroot outside of the rust build system. Fedora applies a couple of patches related to wasm which I think make this possible. Not panicking seems consistent with the detection logic of other targets when they cannot find cc.
github-actions bot pushed a commit to rust-lang/rustc-dev-guide that referenced this pull request Jul 17, 2025
Rollup of 13 pull requests

Successful merges:

 - rust-lang/rust#142301 (tests: Fix duplicated-path-in-error fail with musl)
 - rust-lang/rust#143630 (Drop `./x suggest`)
 - rust-lang/rust#143736 (Give all bytes of TypeId provenance)
 - rust-lang/rust#143752 (Don't panic if WASI_SDK_PATH not set when detecting compiler)
 - rust-lang/rust#143837 (Adjust `run_make_support::symbols` helpers)
 - rust-lang/rust#143878 (Port `#[pointee]` to the new attribute parsing infrastructure)
 - rust-lang/rust#143905 (Recover and suggest to use `;` to construct array type)
 - rust-lang/rust#143907 (core: make `str::split_at_unchecked()` inline)
 - rust-lang/rust#143910 (Add experimental `backtrace-trace-only` std feature)
 - rust-lang/rust#143927 (Preserve constness in trait objects up to hir ty lowering)
 - rust-lang/rust#143935 (rustc_type_ir/walk: move docstring to `TypeWalker` itself)
 - rust-lang/rust#143938 (Update books)
 - rust-lang/rust#143941 (update `cfg_select!` documentation)

Failed merges:

 - rust-lang/rust#143926 (Remove deprecated fields in bootstrap)

r? `@ghost`
`@rustbot` modify labels: rollup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

5 participants