Skip to content

fix: probe flag support without OUT_DIR via tempfile - #1875

Merged
NobodyXu merged 3 commits into
rust-lang:mainfrom
cestercian:fix/flag-if-supported-without-out-dir
Sep 1, 2026
Merged

NobodyXu merged 3 commits into
rust-lang:mainfrom
cestercian:fix/flag-if-supported-without-out-dir

Conversation

@cestercian

Copy link
Copy Markdown
Contributor

Build::flag_if_supported queues flags that are later applied via is_flag_supported_inner(...).unwrap_or(false). The probe writes flag_check.c under get_out_dir(), which only succeeds when Build::out_dir() was set or OUT_DIR is in the environment. Outside a Cargo build script (rustc bootstrap, rust-lang/rust#158169), that lookup errors, every flag is treated as unsupported, and flags such as -gz are silently dropped.

get_out_dir is unchanged: compile() / archive output still require OUT_DIR. Only the flag-support probe falls back to unique NamedTempfiles under std::env::temp_dir() when the dir is missing.

Changes

  • is_flag_supported_inner: tempfile fallback when OUT_DIR / out_dir is unset; existing flag_check.c reuse when OUT_DIR is present
  • Test helper Test::gcc_without_out_dir plus flag_if_supported_without_out_dir covering unset OUT_DIR

Related

Fixes #1765. Bootstrap symptom: rust-lang/rust#158169.

Testing

cargo test --locked --test test flag_if_supported

Callers outside Cargo build scripts (e.g. rustc bootstrap) have no
OUT_DIR, so flag-support probes errored and unwrap_or(false) silently
dropped flags such as -gz. Fall back to unique tempfiles on the probe
path only; compile() still requires OUT_DIR.

Co-authored-by: Cestercian <yashafaid@gmail.com>

@NobodyXu NobodyXu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you! Some feedback on the code

Comment thread CHANGELOG.md Outdated
Comment thread src/lib.rs Outdated
Comment thread src/lib.rs Outdated
Share check-file extension and contents between ensure_check_file and
the OUT_DIR tempfile fallback, and extract probe-dir setup for reuse.

Co-authored-by: Cestercian <yashafaid@gmail.com>

@NobodyXu NobodyXu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you, just one last comment to be resolved!

Comment thread src/lib.rs Outdated
Share flush and sync_data with ensure_check_file; keep the tempfile
handle drop at the NamedTempfile call site so Windows can open the
probe file.

Co-authored-by: Cestercian <yashafaid@gmail.com>

@NobodyXu NobodyXu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you!

@NobodyXu
NobodyXu merged commit 754c1a0 into rust-lang:main Sep 1, 2026
82 checks passed
This was referenced Sep 4, 2026
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.

Fix flag_if_supported when OUT_DIR not set

3 participants