Skip to content

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

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

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

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions