Skip to content

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

Closed

Description

@Rohan-Singla

Summary

./x build fails with an assertion panic in bootstrap when the repository is checked out under a directory path that contains spaces. The
error message gives no indication that the path is the problem, making it very hard to debug.

The root cause is in src/bootstrap/src/core/builder/cargo.rs when building tools like rustdoc (mode ToolRustcPrivate), bootstrap runs
llvm-config --libdir and passes the result as a -Clink-arg=-L<path> rustflag. Rustflags::arg() asserts that arguments contain no
spaces, but if the repo path has a space in it (e.g. /Users/foo/Open Source/rust), the libdir path inherits that space and the assertion
fires.

Command used

```sh
RUST_BACKTRACE=1 ./x build
```

Expected behaviour

Build completes successfully, or fails with a clear error explaining that paths with spaces aren't supported.

Actual behaviour

Bootstrap panics with a cryptic assertion error:

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

Nothing in the output points to the repo path being the issue.

Bootstrap configuration (bootstrap.toml)

```toml

none default configuration

```

Operating system

macOS 15 (aarch64, Apple Silicon)

HEAD

09a3713

Additional context

The repo was cloned to /Users/<user>/Open Source/rust. Renaming the parent directory to remove the space (OpenSource) fixes the build
immediately.

The problematic line is cargo.rs:1189:
```rust
rustflags.arg(&format!("-Clink-arg=-L{llvm_libdir}"));
```
llvm_libdir contains the full repo path (via the ci-llvm build dir), which includes the space. `Rustflags` uses a space-delimited internal
format so any path with spaces breaks the assertion.

This is reproducible by cloning the repo to any path containing a space and running ./x build.

Build Log

Building bootstrap
Finished dev profile [unoptimized] target(s) in 0.09s
/Users/rohansingla/Open Source/rust/build/aarch64-apple-darwin/ci-llvm/bin/llvm-strip does not exist; skipping copy
Building stage1 compiler artifacts (stage0 -> stage1, aarch64-apple-darwin)
Finished release profile [optimized + debuginfo] target(s) in 0.28s
Creating a sysroot for stage1 compiler (use rustup toolchain link 'name' build/host/stage1)
Building stage1 library artifacts{...} (stage1 -> stage1, aarch64-apple-darwin)
Finished dist profile [optimized + debuginfo] target(s) in 0.03s

thread 'main' panicked at src/bootstrap/src/core/builder/cargo.rs:54:9:
assertion left == right failed
left: 2
right: 1
stack backtrace:
4: bootstrap::core::builder::cargo::Rustflags::arg
5: bootstrap::core::builder::Builder::cargo (cargo.rs:1189)
6: bootstrap::core::builder::cargo::Cargo::new
7: bootstrap::core::build_steps::tool::prepare_tool_cargo (tool.rs:191)
8: <bootstrap::core::build_steps::tool::ToolBuild as bootstrap::core::builder::Step>::run
10: <bootstrap::core::build_steps::tool::Rustdoc as bootstrap::core::builder::Step>::run
Build completed unsuccessfully in 0:00:09

Activity

  1. added
    T-bootstrapRelevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)
    C-bugCategory: This is a bug.
    on Jun 17, 2026
  2. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Jun 17, 2026
  3. Rohan-Singla commented on Jun 17, 2026

    @Rohan-Singla
    ContributorAuthor

    Also if this makes sense can i work on this issue ?

  4. Unique-Usman commented on Jun 17, 2026

    @Unique-Usman
    Contributor

    cc: @Kobzol, this issues looks valid, thought ?

  5. ChrisDenton commented on Jun 17, 2026

    @ChrisDenton
    Member

    bootstrap runs llvm-config --libdir and passes the result as a -Clink-arg=-L<path> rustflag.

    llvm-config, prior to LLVM 22, didn't support outputting quoted paths. So this will either need to check for --quote-paths support or else wait for our minimum LLVM version to be 22.

  6. Kobzol commented on Jun 17, 2026

    @Kobzol
    Member

    I guess that we could just quote the path ourselves.

  7. Rohan-Singla commented on Jun 17, 2026

    @Rohan-Singla
    ContributorAuthor

    I guess that we could just quote the path ourselves.

    Makes sense , Thanks! I'll fix it in src/bootstrap/src/core/builder/cargo.rs at line 1189 by quoting the path returned by llvm-config --libdir before

    passing it as a -Clink-arg rustflag, so paths with spaces are handled correctly.

    @rustbot claim

  8. bjorn3 commented on Jun 17, 2026

    @bjorn3
    Member

    RUSTFLAGS does not support spaces in arguments. It would need to be CARGO_ENCODED_RUSTFLAGS. Not sure if we already use that.

  9. added a commit that references this issue on Jun 30, 2026
  10. added a commit that references this issue on Jun 30, 2026
  11. removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Jun 30, 2026
  12. added a commit that references this issue on Jun 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.T-bootstrapRelevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions