Skip to content

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

Open
Rohan-Singla wants to merge 5 commits into
rust-lang:mainfrom
Rohan-Singla:fix/#158052
Open

bootstrap: fix panic when repo path contains spaces by switching to CARGO_ENCODED_RUSTFLAGS#158073
Rohan-Singla wants to merge 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

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
let rustdocflags = &cargo.rustdocflags.0;
if !rustdocflags.is_empty() {
cargo.command.env("RUSTDOCFLAGS", rustdocflags);
cargo.command.env("RUSTDOCFLAGS", rustdocflags.join(" "));

@bjorn3 bjorn3 Jun 18, 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.

This can use CARGO_ENCODED_RUSTDOCFLAGS.

View changes since the review

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Ah , let me see..

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done! Updated to use CARGO_ENCODED_RUSTDOCFLAGS with the \x1f separator for RUSTDOCFLAGS as well, consistent with how RUSTFLAGS is now handeled.

@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
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
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
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
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

6 participants