Skip to content

bootstrap: fix panic when repo path contains spaces by switching to CARGO_ENCODED_RUSTFLAGS#158073

Merged
rust-bors[bot] merged 5 commits into
rust-lang:mainfrom
Rohan-Singla:fix/#158052
Jun 30, 2026
Merged

bootstrap: fix panic when repo path contains spaces by switching to CARGO_ENCODED_RUSTFLAGS#158073
rust-bors[bot] merged 5 commits into
rust-lang:mainfrom
Rohan-Singla:fix/#158052

Conversation

@Rohan-Singla

@Rohan-Singla Rohan-Singla commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

View all comments

Fixes #158052
Closes: #156096

Problem

./x build panics with a cryptic assertion error when the repository is
checked out under a directory path containing spaces (e.g.
/Users/foo/Open Source/rust):

thread 'main' panicked at src/bootstrap/src/core/builder/cargo.rs:54:9:
assertion left == right failed
left: 2
right: 1

The root cause: when building tools in ToolRustcPrivate or Codegen
mode, bootstrap calls llvm-config --libdir and passes the result as a
-Clink-arg=-L<path> rustflag. The Rustflags::arg() method asserted
that arguments contain no spaces, but if the repo path has a space the
libdir path inherits it and the assertion fires. The error gives no hint
that the path is the problem.

A secondary bug: llvm-config --libdir output has a trailing newline
that was previously stripped accidentally by RUSTFLAGS whitespace
splitting. Nothing was trimming it explicitly.

Fix

Two changes in src/bootstrap/src/core/builder/cargo.rs:

  1. Switch RUSTFLAGSCARGO_ENCODED_RUSTFLAGS: Change
    Rustflags to store args as Vec<String> and join with \x1f
    (ASCII unit separator) when setting the env var. Cargo's
    CARGO_ENCODED_RUSTFLAGS (stable since Cargo 1.55) uses \x1f as
    delimiter, which never appears in filesystem paths, so paths with
    spaces are handled correctly. The space-based assertion in arg() is
    removed.

  2. Trim llvm-config --libdir output: Explicitly .trim() the
    captured stdout so the trailing newline is not included in the linker
    search path.

RUSTDOCFLAGS is left as-is (space-joined) since no llvm paths are
added to rustdocflags.

cc: @Kobzol

@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 Jun 18, 2026
@rustbot

rustbot commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome! The Rust Project is excited to review your changes, and you should hear from @Mark-Simulacrum (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue
Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: bootstrap
  • bootstrap expanded to 6 candidates
  • Random selection from Mark-Simulacrum, clubby789

Comment thread src/bootstrap/src/core/builder/cargo.rs Outdated
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rustbot

rustbot commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

miri is developed in its own repository. If possible, consider making this change to rust-lang/miri instead.

cc @rust-lang/miri

@Mark-Simulacrum

Copy link
Copy Markdown
Member

Can you compare with a previous PR in this area (#156096) and evaluate whether there's anything from there that should also be done here? I'm also curious if we can get some kind of testing in place for this. Maybe one of the CI runners can adjust its build directory to have a space in it?

@Rohan-Singla

Copy link
Copy Markdown
Contributor Author

Can you compare with a previous PR in this area (#156096) and evaluate whether there's anything from there that should also be done here? I'm also curious if we can get some kind of testing in place for this. Maybe one of the CI runners can adjust its build directory to have a space in it?

Sure i will look into it !

@Rohan-Singla

Rohan-Singla commented Jun 18, 2026

Copy link
Copy Markdown
Contributor Author

Updated to use String with \x1f as the internal delimiter (matching #156096's approach) and added the \x1f assertion in arg(). For the CI test, I can add --set build.build-dir with a space in the path to one existing Linux job in jobs.yml would that be the right approach?

cc : @Mark-Simulacrum

@Kobzol

Kobzol commented Jun 19, 2026

Copy link
Copy Markdown
Member

This looks reasonable to me; at this point it is essentially the same as #156096.

I don't think that we have to test this in CI, it will just create another testing hack in a bash script that we can't run locally through bootstrap. We don't test much more important things in bootstrap on our CI.. 😆

@Rohan-Singla

Copy link
Copy Markdown
Contributor Author

This looks reasonable to me; at this point it is essentially the same as #156096.

I don't think that we have to test this in CI, it will just create another testing hack in a bash script that we can't run locally through bootstrap. We don't test much more important things in bootstrap on our CI.. 😆

Thanks! Happy to skip the CI test then. Let me know if there's anything else needed before this can be merged.

let rustdocflags = &cargo.rustdocflags.0;
if !rustdocflags.is_empty() {
cargo.command.env("RUSTDOCFLAGS", rustdocflags);
cargo.command.env("CARGO_ENCODED_RUSTDOCFLAGS", rustdocflags);

@Mark-Simulacrum Mark-Simulacrum Jun 21, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could we explicitly unset RUSTFLAGS/RUSTDOCFLAGS as well, just to avoid any confusion over those having different values? I assume Cargo will prioritize the encoded form but not sure if downstream things (e.g., build.rs scripts) will do so.

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done, I now explicitly unset RUSTFLAGS and RUSTDOCFLAGS before setting the encoded forms, so cargo and any build.rs scripts only see CARGO_ENCODED_RUSTFLAGS/CARGO_ENCODED_RUSTDOCFLAGS.

Any flags from the caller's environment have already been folded into the Rustflags struct via propagate_cargo_env, so nothing is lost.

@Mark-Simulacrum

Copy link
Copy Markdown
Member

r? Kobzol

@rustbot rustbot assigned Kobzol and unassigned Mark-Simulacrum Jun 21, 2026
@rustbot

rustbot commented Jun 21, 2026

Copy link
Copy Markdown
Collaborator

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

@Rohan-Singla

Copy link
Copy Markdown
Contributor Author

cc : @Kobzol

@Kobzol

Kobzol commented Jun 29, 2026

Copy link
Copy Markdown
Member

Thanks, let's try.

@bors r=kobzol,mark-simulacrum,bjorn3

@rust-bors

rust-bors Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

📌 Commit b4a7c3e has been approved by kobzol,mark-simulacrum,bjorn3

It is now in the queue for this repository.

@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 Jun 29, 2026
jhpratt added a commit to jhpratt/rust that referenced this pull request Jun 29, 2026
… r=kobzol,mark-simulacrum,bjorn3

bootstrap: fix panic when repo path contains spaces by switching to CARGO_ENCODED_RUSTFLAGS

Fixes rust-lang#158052
Closes: rust-lang#156096

  ## Problem

  `./x build` panics with a cryptic assertion error when the repository is
  checked out under a directory path containing spaces (e.g.
  `/Users/foo/Open Source/rust`):

  thread 'main' panicked at src/bootstrap/src/core/builder/cargo.rs:54:9:
  assertion left == right failed
    left: 2
   right: 1

  The root cause: when building tools in `ToolRustcPrivate` or `Codegen`
  mode, bootstrap calls `llvm-config --libdir` and passes the result as a
  `-Clink-arg=-L<path>` rustflag. The `Rustflags::arg()` method asserted
  that arguments contain no spaces, but if the repo path has a space the
  libdir path inherits it and the assertion fires. The error gives no hint
  that the path is the problem.

  A secondary bug: `llvm-config --libdir` output has a trailing newline
  that was previously stripped accidentally by `RUSTFLAGS` whitespace
  splitting. Nothing was trimming it explicitly.

  ## Fix

  Two changes in `src/bootstrap/src/core/builder/cargo.rs`:

  1. **Switch `RUSTFLAGS` → `CARGO_ENCODED_RUSTFLAGS`**: Change
     `Rustflags` to store args as `Vec<String>` and join with `\x1f`
     (ASCII unit separator) when setting the env var. Cargo's
     `CARGO_ENCODED_RUSTFLAGS` (stable since Cargo 1.55) uses `\x1f` as
     delimiter, which never appears in filesystem paths, so paths with
     spaces are handled correctly. The space-based assertion in `arg()` is
     removed.

  2. **Trim `llvm-config --libdir` output**: Explicitly `.trim()` the
     captured stdout so the trailing newline is not included in the linker
     search path.

  `RUSTDOCFLAGS` is left as-is (space-joined) since no llvm paths are
  added to rustdocflags.

cc: @Kobzol
jhpratt added a commit to jhpratt/rust that referenced this pull request Jun 29, 2026
… r=kobzol,mark-simulacrum,bjorn3

bootstrap: fix panic when repo path contains spaces by switching to CARGO_ENCODED_RUSTFLAGS

Fixes rust-lang#158052
Closes: rust-lang#156096

  ## Problem

  `./x build` panics with a cryptic assertion error when the repository is
  checked out under a directory path containing spaces (e.g.
  `/Users/foo/Open Source/rust`):

  thread 'main' panicked at src/bootstrap/src/core/builder/cargo.rs:54:9:
  assertion left == right failed
    left: 2
   right: 1

  The root cause: when building tools in `ToolRustcPrivate` or `Codegen`
  mode, bootstrap calls `llvm-config --libdir` and passes the result as a
  `-Clink-arg=-L<path>` rustflag. The `Rustflags::arg()` method asserted
  that arguments contain no spaces, but if the repo path has a space the
  libdir path inherits it and the assertion fires. The error gives no hint
  that the path is the problem.

  A secondary bug: `llvm-config --libdir` output has a trailing newline
  that was previously stripped accidentally by `RUSTFLAGS` whitespace
  splitting. Nothing was trimming it explicitly.

  ## Fix

  Two changes in `src/bootstrap/src/core/builder/cargo.rs`:

  1. **Switch `RUSTFLAGS` → `CARGO_ENCODED_RUSTFLAGS`**: Change
     `Rustflags` to store args as `Vec<String>` and join with `\x1f`
     (ASCII unit separator) when setting the env var. Cargo's
     `CARGO_ENCODED_RUSTFLAGS` (stable since Cargo 1.55) uses `\x1f` as
     delimiter, which never appears in filesystem paths, so paths with
     spaces are handled correctly. The space-based assertion in `arg()` is
     removed.

  2. **Trim `llvm-config --libdir` output**: Explicitly `.trim()` the
     captured stdout so the trailing newline is not included in the linker
     search path.

  `RUSTDOCFLAGS` is left as-is (space-joined) since no llvm paths are
  added to rustdocflags.

cc: @Kobzol
rust-bors Bot pushed a commit that referenced this pull request Jun 29, 2026
Rollup of 6 pull requests

Successful merges:

 - #158073 (bootstrap: fix panic when repo path contains spaces by switching to CARGO_ENCODED_RUSTFLAGS)
 - #158256 (Avoid parser panics bubbling out to proc macros)
 - #158081 (trait-system: Recover deferred closure calls after errors)
 - #158323 (rustc: improve diagnostics for file-open failures)
 - #158327 (Move attribute and keyword docs from `std` to `core`)
 - #158468 (Include default-stability info in rustdoc JSON.)
jhpratt added a commit to jhpratt/rust that referenced this pull request Jun 29, 2026
… r=kobzol,mark-simulacrum,bjorn3

bootstrap: fix panic when repo path contains spaces by switching to CARGO_ENCODED_RUSTFLAGS

Fixes rust-lang#158052
Closes: rust-lang#156096

  ## Problem

  `./x build` panics with a cryptic assertion error when the repository is
  checked out under a directory path containing spaces (e.g.
  `/Users/foo/Open Source/rust`):

  thread 'main' panicked at src/bootstrap/src/core/builder/cargo.rs:54:9:
  assertion left == right failed
    left: 2
   right: 1

  The root cause: when building tools in `ToolRustcPrivate` or `Codegen`
  mode, bootstrap calls `llvm-config --libdir` and passes the result as a
  `-Clink-arg=-L<path>` rustflag. The `Rustflags::arg()` method asserted
  that arguments contain no spaces, but if the repo path has a space the
  libdir path inherits it and the assertion fires. The error gives no hint
  that the path is the problem.

  A secondary bug: `llvm-config --libdir` output has a trailing newline
  that was previously stripped accidentally by `RUSTFLAGS` whitespace
  splitting. Nothing was trimming it explicitly.

  ## Fix

  Two changes in `src/bootstrap/src/core/builder/cargo.rs`:

  1. **Switch `RUSTFLAGS` → `CARGO_ENCODED_RUSTFLAGS`**: Change
     `Rustflags` to store args as `Vec<String>` and join with `\x1f`
     (ASCII unit separator) when setting the env var. Cargo's
     `CARGO_ENCODED_RUSTFLAGS` (stable since Cargo 1.55) uses `\x1f` as
     delimiter, which never appears in filesystem paths, so paths with
     spaces are handled correctly. The space-based assertion in `arg()` is
     removed.

  2. **Trim `llvm-config --libdir` output**: Explicitly `.trim()` the
     captured stdout so the trailing newline is not included in the linker
     search path.

  `RUSTDOCFLAGS` is left as-is (space-joined) since no llvm paths are
  added to rustdocflags.

cc: @Kobzol
rust-bors Bot pushed a commit that referenced this pull request Jun 29, 2026
Rollup of 12 pull requests

Successful merges:

 - #158073 (bootstrap: fix panic when repo path contains spaces by switching to CARGO_ENCODED_RUSTFLAGS)
 - #158169 (Fix debuginfo compression in bootstrap)
 - #158256 (Avoid parser panics bubbling out to proc macros)
 - #158375 (Support `DefKind::InlineConst` in `ConstKind::Unevaluated`)
 - #158417 (Avoid ICE when cfg_eval recovers no item from derive input)
 - #158556 (delegation: store child segment flag in `PathSegment`)
 - #158561 (Avoid building rustdoc for tests without doctests)
 - #158562 (Improve tracing of steps in bootstrap)
 - #157445 (Allow section override when using patchable-function-entries)
 - #158081 (trait-system: Recover deferred closure calls after errors)
 - #158327 (Move attribute and keyword docs from `std` to `core`)
 - #158468 (Include default-stability info in rustdoc JSON.)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jun 29, 2026
… r=kobzol,mark-simulacrum,bjorn3

bootstrap: fix panic when repo path contains spaces by switching to CARGO_ENCODED_RUSTFLAGS

Fixes rust-lang#158052
Closes: rust-lang#156096

  ## Problem

  `./x build` panics with a cryptic assertion error when the repository is
  checked out under a directory path containing spaces (e.g.
  `/Users/foo/Open Source/rust`):

  thread 'main' panicked at src/bootstrap/src/core/builder/cargo.rs:54:9:
  assertion left == right failed
    left: 2
   right: 1

  The root cause: when building tools in `ToolRustcPrivate` or `Codegen`
  mode, bootstrap calls `llvm-config --libdir` and passes the result as a
  `-Clink-arg=-L<path>` rustflag. The `Rustflags::arg()` method asserted
  that arguments contain no spaces, but if the repo path has a space the
  libdir path inherits it and the assertion fires. The error gives no hint
  that the path is the problem.

  A secondary bug: `llvm-config --libdir` output has a trailing newline
  that was previously stripped accidentally by `RUSTFLAGS` whitespace
  splitting. Nothing was trimming it explicitly.

  ## Fix

  Two changes in `src/bootstrap/src/core/builder/cargo.rs`:

  1. **Switch `RUSTFLAGS` → `CARGO_ENCODED_RUSTFLAGS`**: Change
     `Rustflags` to store args as `Vec<String>` and join with `\x1f`
     (ASCII unit separator) when setting the env var. Cargo's
     `CARGO_ENCODED_RUSTFLAGS` (stable since Cargo 1.55) uses `\x1f` as
     delimiter, which never appears in filesystem paths, so paths with
     spaces are handled correctly. The space-based assertion in `arg()` is
     removed.

  2. **Trim `llvm-config --libdir` output**: Explicitly `.trim()` the
     captured stdout so the trailing newline is not included in the linker
     search path.

  `RUSTDOCFLAGS` is left as-is (space-joined) since no llvm paths are
  added to rustdocflags.

cc: @Kobzol
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jun 29, 2026
… r=kobzol,mark-simulacrum,bjorn3

bootstrap: fix panic when repo path contains spaces by switching to CARGO_ENCODED_RUSTFLAGS

Fixes rust-lang#158052
Closes: rust-lang#156096

  ## Problem

  `./x build` panics with a cryptic assertion error when the repository is
  checked out under a directory path containing spaces (e.g.
  `/Users/foo/Open Source/rust`):

  thread 'main' panicked at src/bootstrap/src/core/builder/cargo.rs:54:9:
  assertion left == right failed
    left: 2
   right: 1

  The root cause: when building tools in `ToolRustcPrivate` or `Codegen`
  mode, bootstrap calls `llvm-config --libdir` and passes the result as a
  `-Clink-arg=-L<path>` rustflag. The `Rustflags::arg()` method asserted
  that arguments contain no spaces, but if the repo path has a space the
  libdir path inherits it and the assertion fires. The error gives no hint
  that the path is the problem.

  A secondary bug: `llvm-config --libdir` output has a trailing newline
  that was previously stripped accidentally by `RUSTFLAGS` whitespace
  splitting. Nothing was trimming it explicitly.

  ## Fix

  Two changes in `src/bootstrap/src/core/builder/cargo.rs`:

  1. **Switch `RUSTFLAGS` → `CARGO_ENCODED_RUSTFLAGS`**: Change
     `Rustflags` to store args as `Vec<String>` and join with `\x1f`
     (ASCII unit separator) when setting the env var. Cargo's
     `CARGO_ENCODED_RUSTFLAGS` (stable since Cargo 1.55) uses `\x1f` as
     delimiter, which never appears in filesystem paths, so paths with
     spaces are handled correctly. The space-based assertion in `arg()` is
     removed.

  2. **Trim `llvm-config --libdir` output**: Explicitly `.trim()` the
     captured stdout so the trailing newline is not included in the linker
     search path.

  `RUSTDOCFLAGS` is left as-is (space-joined) since no llvm paths are
  added to rustdocflags.

cc: @Kobzol
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jun 29, 2026
… r=kobzol,mark-simulacrum,bjorn3

bootstrap: fix panic when repo path contains spaces by switching to CARGO_ENCODED_RUSTFLAGS

Fixes rust-lang#158052
Closes: rust-lang#156096

  ## Problem

  `./x build` panics with a cryptic assertion error when the repository is
  checked out under a directory path containing spaces (e.g.
  `/Users/foo/Open Source/rust`):

  thread 'main' panicked at src/bootstrap/src/core/builder/cargo.rs:54:9:
  assertion left == right failed
    left: 2
   right: 1

  The root cause: when building tools in `ToolRustcPrivate` or `Codegen`
  mode, bootstrap calls `llvm-config --libdir` and passes the result as a
  `-Clink-arg=-L<path>` rustflag. The `Rustflags::arg()` method asserted
  that arguments contain no spaces, but if the repo path has a space the
  libdir path inherits it and the assertion fires. The error gives no hint
  that the path is the problem.

  A secondary bug: `llvm-config --libdir` output has a trailing newline
  that was previously stripped accidentally by `RUSTFLAGS` whitespace
  splitting. Nothing was trimming it explicitly.

  ## Fix

  Two changes in `src/bootstrap/src/core/builder/cargo.rs`:

  1. **Switch `RUSTFLAGS` → `CARGO_ENCODED_RUSTFLAGS`**: Change
     `Rustflags` to store args as `Vec<String>` and join with `\x1f`
     (ASCII unit separator) when setting the env var. Cargo's
     `CARGO_ENCODED_RUSTFLAGS` (stable since Cargo 1.55) uses `\x1f` as
     delimiter, which never appears in filesystem paths, so paths with
     spaces are handled correctly. The space-based assertion in `arg()` is
     removed.

  2. **Trim `llvm-config --libdir` output**: Explicitly `.trim()` the
     captured stdout so the trailing newline is not included in the linker
     search path.

  `RUSTDOCFLAGS` is left as-is (space-joined) since no llvm paths are
  added to rustdocflags.

cc: @Kobzol
rust-bors Bot pushed a commit that referenced this pull request Jun 29, 2026
…uwer

Rollup of 16 pull requests

Successful merges:

 - #155722 (Introduce aarch64-unknown-linux-pauthtest target)
 - #156230 (tests: check wasm compiler_builtins object architecture)
 - #158073 (bootstrap: fix panic when repo path contains spaces by switching to CARGO_ENCODED_RUSTFLAGS)
 - #158169 (Fix debuginfo compression in bootstrap)
 - #158256 (Avoid parser panics bubbling out to proc macros)
 - #158375 (Support `DefKind::InlineConst` in `ConstKind::Unevaluated`)
 - #158556 (delegation: store child segment flag in `PathSegment`)
 - #158561 (Avoid building rustdoc for tests without doctests)
 - #158562 (Improve tracing of steps in bootstrap)
 - #157445 (Allow section override when using patchable-function-entries)
 - #158081 (trait-system: Recover deferred closure calls after errors)
 - #158327 (Move attribute and keyword docs from `std` to `core`)
 - #158468 (Include default-stability info in rustdoc JSON.)
 - #158564 (fix `-Z min-recursion-limit` unstable chapter name)
 - #158568 (llvm-wrapper: use accessors for private fields in LLVM 23+)
 - #158582 (Comment on needed RAM in huge-stacks.rs)
rust-bors Bot pushed a commit that referenced this pull request Jun 30, 2026
…uwer

Rollup of 16 pull requests

Successful merges:

 - #155722 (Introduce aarch64-unknown-linux-pauthtest target)
 - #156230 (tests: check wasm compiler_builtins object architecture)
 - #158073 (bootstrap: fix panic when repo path contains spaces by switching to CARGO_ENCODED_RUSTFLAGS)
 - #158169 (Fix debuginfo compression in bootstrap)
 - #158256 (Avoid parser panics bubbling out to proc macros)
 - #158375 (Support `DefKind::InlineConst` in `ConstKind::Unevaluated`)
 - #158556 (delegation: store child segment flag in `PathSegment`)
 - #158561 (Avoid building rustdoc for tests without doctests)
 - #158562 (Improve tracing of steps in bootstrap)
 - #157445 (Allow section override when using patchable-function-entries)
 - #158081 (trait-system: Recover deferred closure calls after errors)
 - #158327 (Move attribute and keyword docs from `std` to `core`)
 - #158468 (Include default-stability info in rustdoc JSON.)
 - #158564 (fix `-Z min-recursion-limit` unstable chapter name)
 - #158568 (llvm-wrapper: use accessors for private fields in LLVM 23+)
 - #158582 (Comment on needed RAM in huge-stacks.rs)
@JonathanBrouwer

Copy link
Copy Markdown
Contributor

@bors try jobs=dist-x86_64-msvc

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Jun 30, 2026
bootstrap: fix panic when repo path contains spaces by switching to CARGO_ENCODED_RUSTFLAGS


try-job: dist-x86_64-msvc
rust-bors Bot pushed a commit that referenced this pull request Jun 30, 2026
…uwer

Rollup of 7 pull requests

Successful merges:

 - #158073 (bootstrap: fix panic when repo path contains spaces by switching to CARGO_ENCODED_RUSTFLAGS)
 - #158256 (Avoid parser panics bubbling out to proc macros)
 - #158561 (Avoid building rustdoc for tests without doctests)
 - #158562 (Improve tracing of steps in bootstrap)
 - #157445 (Allow section override when using patchable-function-entries)
 - #158327 (Move attribute and keyword docs from `std` to `core`)
 - #158591 (Fix spacing issue for unused parentheses lint)
rust-bors Bot pushed a commit that referenced this pull request Jun 30, 2026
…uwer

Rollup of 7 pull requests

Successful merges:

 - #158073 (bootstrap: fix panic when repo path contains spaces by switching to CARGO_ENCODED_RUSTFLAGS)
 - #158256 (Avoid parser panics bubbling out to proc macros)
 - #158561 (Avoid building rustdoc for tests without doctests)
 - #158562 (Improve tracing of steps in bootstrap)
 - #157445 (Allow section override when using patchable-function-entries)
 - #158327 (Move attribute and keyword docs from `std` to `core`)
 - #158591 (Fix spacing issue for unused parentheses lint)
@rust-bors

rust-bors Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 18535c5 (18535c55b74045798402e5f4d8e6b192ba95d0dd)
Base parent: 0966944 (096694416a41840709140eb0fd0ca193d1a3e6ba)

rust-bors Bot pushed a commit that referenced this pull request Jun 30, 2026
…uwer

Rollup of 7 pull requests

Successful merges:

 - #158073 (bootstrap: fix panic when repo path contains spaces by switching to CARGO_ENCODED_RUSTFLAGS)
 - #158256 (Avoid parser panics bubbling out to proc macros)
 - #158561 (Avoid building rustdoc for tests without doctests)
 - #158562 (Improve tracing of steps in bootstrap)
 - #157445 (Allow section override when using patchable-function-entries)
 - #158327 (Move attribute and keyword docs from `std` to `core`)
 - #158591 (Fix spacing issue for unused parentheses lint)
@manyifire

Copy link
Copy Markdown

Hi, just a quick question — I noticed this PR also fixes the bug where llvm-config --libdir output has a trailing newline. Is that also the root cause of issues #15802 and #156096, or was it simply found by accident while fixing those two?Thanks!

@Kobzol

Kobzol commented Jun 30, 2026

Copy link
Copy Markdown
Member

Not sure what the first issue was supposed to be, maybe a wrong link? But yeah, this will close #156096, as it arrived at essentially the same implementation.

@manyifire

Copy link
Copy Markdown

Not sure what the first issue was supposed to be, maybe a wrong link? But yeah, this will close #156096, as it arrived at essentially the same implementation.

Sorry for the wrong link, it's issue #158052 .

rust-bors Bot pushed a commit that referenced this pull request Jun 30, 2026
…uwer

Rollup of 7 pull requests

Successful merges:

 - #158073 (bootstrap: fix panic when repo path contains spaces by switching to CARGO_ENCODED_RUSTFLAGS)
 - #158256 (Avoid parser panics bubbling out to proc macros)
 - #158561 (Avoid building rustdoc for tests without doctests)
 - #158562 (Improve tracing of steps in bootstrap)
 - #157445 (Allow section override when using patchable-function-entries)
 - #158327 (Move attribute and keyword docs from `std` to `core`)
 - #158591 (Fix spacing issue for unused parentheses lint)
@rust-bors rust-bors Bot merged commit b674511 into rust-lang:main Jun 30, 2026
14 checks passed
rust-timer added a commit that referenced this pull request Jun 30, 2026
Rollup merge of #158073 - Rohan-Singla:fix/#158052, r=kobzol,mark-simulacrum,bjorn3

bootstrap: fix panic when repo path contains spaces by switching to CARGO_ENCODED_RUSTFLAGS

Fixes #158052
Closes: #156096

  ## Problem

  `./x build` panics with a cryptic assertion error when the repository is
  checked out under a directory path containing spaces (e.g.
  `/Users/foo/Open Source/rust`):

  thread 'main' panicked at src/bootstrap/src/core/builder/cargo.rs:54:9:
  assertion left == right failed
    left: 2
   right: 1

  The root cause: when building tools in `ToolRustcPrivate` or `Codegen`
  mode, bootstrap calls `llvm-config --libdir` and passes the result as a
  `-Clink-arg=-L<path>` rustflag. The `Rustflags::arg()` method asserted
  that arguments contain no spaces, but if the repo path has a space the
  libdir path inherits it and the assertion fires. The error gives no hint
  that the path is the problem.

  A secondary bug: `llvm-config --libdir` output has a trailing newline
  that was previously stripped accidentally by `RUSTFLAGS` whitespace
  splitting. Nothing was trimming it explicitly.

  ## Fix

  Two changes in `src/bootstrap/src/core/builder/cargo.rs`:

  1. **Switch `RUSTFLAGS` → `CARGO_ENCODED_RUSTFLAGS`**: Change
     `Rustflags` to store args as `Vec<String>` and join with `\x1f`
     (ASCII unit separator) when setting the env var. Cargo's
     `CARGO_ENCODED_RUSTFLAGS` (stable since Cargo 1.55) uses `\x1f` as
     delimiter, which never appears in filesystem paths, so paths with
     spaces are handled correctly. The space-based assertion in `arg()` is
     removed.

  2. **Trim `llvm-config --libdir` output**: Explicitly `.trim()` the
     captured stdout so the trailing newline is not included in the linker
     search path.

  `RUSTDOCFLAGS` is left as-is (space-joined) since no llvm paths are
  added to rustdocflags.

cc: @Kobzol
@rustbot rustbot added this to the 1.98.0 milestone Jun 30, 2026
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.

./x build panics with assertion error when repo path contains spaces

8 participants