Skip to content

bootstrap: only encode RUSTFLAGS when a flag contains a space#158775

Open
valentynkit wants to merge 1 commit into
rust-lang:mainfrom
valentynkit:bootstrap-readable-rustflags
Open

bootstrap: only encode RUSTFLAGS when a flag contains a space#158775
valentynkit wants to merge 1 commit into
rust-lang:mainfrom
valentynkit:bootstrap-readable-rustflags

Conversation

@valentynkit

@valentynkit valentynkit commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Fixes #158749

Since #158073, bootstrap passes rustc and rustdoc flags to cargo through CARGO_ENCODED_RUSTFLAGS / CARGO_ENCODED_RUSTDOCFLAGS, whose values are \x1f-separated. When a command fails and gets debug-printed, that separator shows up as \u{1f}, e.g.:

CARGO_ENCODED_RUSTDOCFLAGS="--cfg=windows_raw_dylib\u{1f}-Csymbol-mangling-version=v0\u{1f}..."

which isn't a valid escape in bash/zsh, so the printed command can't be copy-pasted.

The encoded form is only needed when a flag value contains a space (the case #158073 fixed, e.g. an -L path from llvm-config --libdir under a directory whose name has a space). Cargo splits RUSTFLAGS on spaces, so when no flag contains one the plain, space-separated RUSTFLAGS/RUSTDOCFLAGS form is equivalent and stays readable. This uses the plain form in that case and only falls back to the encoded form when a flag actually contains a space.

It also clears any inherited CARGO_ENCODED_RUSTFLAGS/CARGO_ENCODED_RUSTDOCFLAGS, since cargo prefers the encoded variable over the plain one and the plain form would otherwise be ignored.

r? @Mark-Simulacrum

Bootstrap now passes rustc and rustdoc flags via CARGO_ENCODED_RUSTFLAGS
and CARGO_ENCODED_RUSTDOCFLAGS, whose values use \x1f to separate flags.
That control character renders as \u{1f} when a failing command is
debug-printed, so the printed command can't be copy-pasted.

Prefer the plain, space-separated RUSTFLAGS/RUSTDOCFLAGS form, which is
equivalent whenever no flag value contains a space, and only fall back to
the encoded form when a flag value does contain a space.
@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 4, 2026
@Mark-Simulacrum

Copy link
Copy Markdown
Member

@bors r+

Thanks!

@rust-bors

rust-bors Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

📌 Commit d0c3225 has been approved by Mark-Simulacrum

It is now in the queue for this repository.

🌲 The tree is currently closed for pull requests below priority 1000. This pull request will be tested once the tree is reopened.

@rust-bors rust-bors Bot 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 4, 2026
jhpratt added a commit to jhpratt/rust that referenced this pull request Jul 5, 2026
…tflags, r=Mark-Simulacrum

bootstrap: only encode RUSTFLAGS when a flag contains a space

Fixes rust-lang#158749

Since rust-lang#158073, bootstrap passes rustc and rustdoc flags to cargo through `CARGO_ENCODED_RUSTFLAGS` / `CARGO_ENCODED_RUSTDOCFLAGS`, whose values are `\x1f`-separated. When a command fails and gets debug-printed, that separator shows up as `\u{1f}`, e.g.:

```
CARGO_ENCODED_RUSTDOCFLAGS="--cfg=windows_raw_dylib\u{1f}-Csymbol-mangling-version=v0\u{1f}..."
```

which isn't a valid escape in bash/zsh, so the printed command can't be copy-pasted.

The encoded form is only needed when a flag value contains a space (the case rust-lang#158073 fixed, e.g. an `-L` path from `llvm-config --libdir` under a directory whose name has a space). Cargo splits `RUSTFLAGS` on spaces, so when no flag contains one the plain, space-separated `RUSTFLAGS`/`RUSTDOCFLAGS` form is equivalent and stays readable. This uses the plain form in that case and only falls back to the encoded form when a flag actually contains a space.

It also clears any inherited `CARGO_ENCODED_RUSTFLAGS`/`CARGO_ENCODED_RUSTDOCFLAGS`, since cargo prefers the encoded variable over the plain one and the plain form would otherwise be ignored.

r? @Mark-Simulacrum
jhpratt added a commit to jhpratt/rust that referenced this pull request Jul 5, 2026
…tflags, r=Mark-Simulacrum

bootstrap: only encode RUSTFLAGS when a flag contains a space

Fixes rust-lang#158749

Since rust-lang#158073, bootstrap passes rustc and rustdoc flags to cargo through `CARGO_ENCODED_RUSTFLAGS` / `CARGO_ENCODED_RUSTDOCFLAGS`, whose values are `\x1f`-separated. When a command fails and gets debug-printed, that separator shows up as `\u{1f}`, e.g.:

```
CARGO_ENCODED_RUSTDOCFLAGS="--cfg=windows_raw_dylib\u{1f}-Csymbol-mangling-version=v0\u{1f}..."
```

which isn't a valid escape in bash/zsh, so the printed command can't be copy-pasted.

The encoded form is only needed when a flag value contains a space (the case rust-lang#158073 fixed, e.g. an `-L` path from `llvm-config --libdir` under a directory whose name has a space). Cargo splits `RUSTFLAGS` on spaces, so when no flag contains one the plain, space-separated `RUSTFLAGS`/`RUSTDOCFLAGS` form is equivalent and stays readable. This uses the plain form in that case and only falls back to the encoded form when a flag actually contains a space.

It also clears any inherited `CARGO_ENCODED_RUSTFLAGS`/`CARGO_ENCODED_RUSTDOCFLAGS`, since cargo prefers the encoded variable over the plain one and the plain form would otherwise be ignored.

r? @Mark-Simulacrum
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.

bootstrap printing failing command contains non-shell escape sequences

3 participants