Repository navigation
Conversation
…anitizer 237a56c added `-Cunsafe-allow-abi-mismatch=sanitizer` to the CARGO_ENCODED_RUSTFLAGS of every build script, so that their probe compiles do not fail against a std built with a sanitizer. Build scripts pass these flags to rustc for feature probes (autocfg, rustix, ...). A rustc that does not know the option, such as 1.85, rejects every probe, and the crate is built with its fallback cfgs without any error: num-traits loses `has_total_cmp`. Add the option only when the toolchain has a sanitizer, the case it was added for.
Contributor
|
This pull request has been imported. If you are a Meta employee, you can view this in D134832345. (Because this pull request was imported automatically, there will not be any future comments.) |
dtolnay
approved these changes
Nov 27, 2026
dtolnay
left a comment
There was a problem hiding this comment.
In general we have limited interest in supporting rust toolchains older than the most recent stable, but this seems fine.
Contributor
|
This pull request has been merged in 34b264c. |
meta-codesync Bot
pushed a commit
to meta/buck2-prelude
that referenced
this pull request
Nov 27, 2026
…anitizer Summary: Since 237a56ce94, `buildscript_run` adds `-Cunsafe-allow-abi-mismatch=sanitizer` to the `CARGO_ENCODED_RUSTFLAGS` of every build script. That keeps probe compiles from failing against a std built with a sanitizer. Build scripts pass `CARGO_ENCODED_RUSTFLAGS` to rustc when they probe for features: autocfg-based crates such as `num-traits`, plus `rustix`, `proc-macro2` and others. A rustc that does not know the option rejects every probe: ``` error: unknown codegen option: `unsafe-allow-abi-mismatch` ``` The build script reads that as "feature not available" and picks its fallback configuration. The build succeeds, so nothing reports that the crate was configured differently. Rust 1.85 rejects the option; 1.93, 1.98 and current nightly accept it. That leaves toolchains pinned to an older Rust silently misconfigured. This PR adds the option only when the toolchain has a `sanitizer`, the case it was added for. That is the same field that puts `-Zsanitizer=` on the Rust compiles (`build.bzl`). ## Affected version origin/main 00c2ee4f74. ## Reproduction `num-traits` 0.2.19 with `autocfg` 1.5.1, through `buildscript_run` with the demo toolchains. Its probe checks for `f64::total_cmp` (Rust 1.62). The `[rustc_flags]` output: | rustc | origin/main | this PR | | --- | --- | --- | | 1.85.0 | (empty) | `--cfg=has_total_cmp` | | 1.93.0 | `--cfg=has_total_cmp` | `--cfg=has_total_cmp` | On origin/main with rustc 1.85, removing only `-Cunsafe-allow-abi-mismatch=sanitizer` brings `--cfg=has_total_cmp` back. X-link: meta/buck2#1670 Reviewed By: dtolnay Differential Revision: D134832345 fbshipit-source-id: d5cb6884d49343ad5337823f98a9e110014eeb4b
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Since 237a56c,
buildscript_runadds-Cunsafe-allow-abi-mismatch=sanitizerto theCARGO_ENCODED_RUSTFLAGSof every build script. That keeps probe compiles from failing against a std built with a sanitizer.Build scripts pass
CARGO_ENCODED_RUSTFLAGSto rustc when they probe for features: autocfg-based crates such asnum-traits, plusrustix,proc-macro2and others. A rustc that does not know the option rejects every probe:The build script reads that as "feature not available" and picks its fallback configuration. The build succeeds, so nothing reports that the crate was configured differently. Rust 1.85 rejects the option; 1.93, 1.98 and current nightly accept it. That leaves toolchains pinned to an older Rust silently misconfigured.
This PR adds the option only when the toolchain has a
sanitizer, the case it was added for. That is the same field that puts-Zsanitizer=on the Rust compiles (build.bzl).Affected version
origin/main 00c2ee4.
Reproduction
num-traits0.2.19 withautocfg1.5.1, throughbuildscript_runwith the demo toolchains. Its probe checks forf64::total_cmp(Rust 1.62). The[rustc_flags]output:--cfg=has_total_cmp--cfg=has_total_cmp--cfg=has_total_cmpOn origin/main with rustc 1.85, removing only
-Cunsafe-allow-abi-mismatch=sanitizerbrings--cfg=has_total_cmpback.Test plan
tests/prelude/rust/buildscript_rustflags_probe: a build script compiles an empty crate with$RUSTCandCARGO_ENCODED_RUSTFLAGS, as autocfg does, and the assertion expects its--cfg=probe_compiles.sanitizer, where the option is still added as before.