Skip to content

./x.py dist cargo rustc rust-std doesn't build std before cargo #139993

Closed as duplicate of#138778
@lambdageek

Description

@lambdageek

Summary

When using x.py dist with a list of paths, the order of the paths matters. In particular, if cargo is listed before rust-std, the build fails

Command used

x.py dist cargo rustc rust-std

Expected behaviour

The tarballs for cargo, rustc and rust-std are created

Actual behaviour

The build fails. See build-log.txt below

Bootstrap configuration (bootstrap.toml)

# See bootstrap.example.toml for documentation of available options
#
profile = "dist"  # Includes one of the default files in src/bootstrap/defaults
change-id = 138986

[llvm]

download-ci-llvm=true

Operating system

macOS 15.4 arm64

HEAD

a594829

Additional context

Starting from a clean clone, but using ./x.py dist rustc rust-std cargo results in a successful build.

Here's the full log of a failed run:

Output of RUST_BACKTRACE=1 ./x dist -v cargo rustc rust-std > build-log.txt 2>&1, attached:

build-log.txt

Here's a summary of what's in the build-log

% grep -e '^Building' build-log.txt
Building bootstrap
Building stage0 library artifacts (aarch64-apple-darwin)
Building compiler artifacts (stage0 -> stage1, aarch64-apple-darwin)
Building stage0 tool lld-wrapper (aarch64-apple-darwin)
Building stage0 tool wasm-component-ld (aarch64-apple-darwin)
Building tool llvm-bitcode-linker (stage0 -> stage1, aarch64-apple-darwin)
Building tool cargo (stage1 -> stage2, aarch64-apple-darwin)

and here's just the part where things go wrong

Build log excerpts

Building tool cargo (stage1 -> stage2, aarch64-apple-darwin)
...
   1.435554875s  INFO prepare_target{force=false package_id=cargo v0.88.0 (/Users/alklig/work/bootstrap-order-issue/src/tools/cargo) target="cargo"}: cargo::core::compiler::fingerprint: fingerprint error for cargo v0.88.0 (/Users/alklig/work/bootstrap-order-issue/src/tools/cargo)/Build/TargetInner { ..: lib_target("cargo", ["lib"], "/Users/alklig/work/bootstrap-order-issue/src/tools/cargo/src/cargo/lib.rs", Edition2021) }
   1.435601584s  INFO prepare_target{force=false package_id=cargo v0.88.0 (/Users/alklig/work/bootstrap-order-issue/src/tools/cargo) target="cargo"}: cargo::core::compiler::fingerprint:     err: failed to read `/Users/alklig/work/bootstrap-order-issue/build/aarch64-apple-darwin/stage1-tools/aarch64-apple-darwin/release/.fingerprint/cargo-7cb5bb608f39f749/lib-cargo`

Caused by:
    No such file or directory (os error 2)
...
     Running `/Users/alklig/work/bootstrap-order-issue/build/bootstrap/debug/rustc /Users/alklig/work/bootstrap-order-issue/build/bootstrap/debug/rustc --crate-name cfg_if --edition=2018 /Users/alklig/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/cfg-if-1.0.0/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C embed-bitcode=no --check-cfg 'cfg(docsrs,test)' --check-cfg 'cfg(feature, values("compiler_builtins", "core", "rustc-dep-of-std"))' -C metadata=2f38658e0927f1af -C extra-filename=-d52429c6ba8871bb --out-dir /Users/alklig/work/bootstrap-order-issue/build/aarch64-apple-darwin/stage1-tools/aarch64-apple-darwin/release/deps --target aarch64-apple-darwin -L dependency=/Users/alklig/work/bootstrap-order-issue/build/aarch64-apple-darwin/stage1-tools/aarch64-apple-darwin/release/deps -L dependency=/Users/alklig/work/bootstrap-order-issue/build/aarch64-apple-darwin/stage1-tools/release/deps --cap-lints allow --cfg=windows_raw_dylib -Csymbol-mangling-version=v0 -Zunstable-options '--check-cfg=cfg(bootstrap)' '--check-cfg=cfg(llvm_enzyme)' '--check-cfg=cfg(rust_analyzer)' -Zmacro-backtrace -Csplit-debuginfo=unpacked -Clink-arg=-L/Users/alklig/work/bootstrap-order-issue/build/aarch64-apple-darwin/ci-llvm/lib -Zosx-rpath-install-name '-Clink-args=-Wl,-rpath,@loader_path/../lib' -Alinker-messages -Zunstable-options -Z binary-dep-depinfo`
...
error[E0463]: can't find crate for `core`
  |
  = note: the `aarch64-apple-darwin` target may not be installed
  = help: consider downloading the target with `rustup target add aarch64-apple-darwin`
  = help: consider building the standard library from source with `cargo build -Zbuild-std`

error[E0463]: can't find crate for `std`
  |
  = note: the `aarch64-apple-darwin` target may not be installed
  = help: consider downloading the target with `rustup target add aarch64-apple-darwin`
  = help: consider building the standard library from source with `cargo build -Zbuild-std`

For more information about this error, try `rustc --explain E0463`.

Did not run successfully: exit status: 1
DYLD_LIBRARY_PATH="/Users/alklig/work/bootstrap-order-issue/build/aarch64-apple-darwin/stage1/lib" "/Users/alklig/work/bootstrap-order-issue/build/aarch64-apple-darwin/stage1/bin/rustc" "--crate-name" "cfg_if" "--edition=2018" "/Users/alklig/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/cfg-if-1.0.0/src/lib.rs" "--error-format=json" "--json=diagnostic-rendered-ansi,artifacts,future-incompat" "--crate-type" "lib" "--emit=dep-info,metadata,link" "-C" "opt-level=3" "-C" "embed-bitcode=no" "--check-cfg" "cfg(docsrs,test)" "--check-cfg" "cfg(feature, values(\"compiler_builtins\", \"core\", \"rustc-dep-of-std\"))" "-C" "metadata=2f38658e0927f1af" "-C" "extra-filename=-d52429c6ba8871bb" "--out-dir" "/Users/alklig/work/bootstrap-order-issue/build/aarch64-apple-darwin/stage1-tools/aarch64-apple-darwin/release/deps" "--target" "aarch64-apple-darwin" "-L" "dependency=/Users/alklig/work/bootstrap-order-issue/build/aarch64-apple-darwin/stage1-tools/aarch64-apple-darwin/release/deps" "-L" "dependency=/Users/alklig/work/bootstrap-order-issue/build/aarch64-apple-darwin/stage1-tools/release/deps" "--cap-lints" "allow" "--cfg=windows_raw_dylib" "-Csymbol-mangling-version=v0" "-Zunstable-options" "--check-cfg=cfg(bootstrap)" "--check-cfg=cfg(llvm_enzyme)" "--check-cfg=cfg(rust_analyzer)" "-Zmacro-backtrace" "-Csplit-debuginfo=unpacked" "-Clink-arg=-L/Users/alklig/work/bootstrap-order-issue/build/aarch64-apple-darwin/ci-llvm/lib" "-Zosx-rpath-install-name" "-Clink-args=-Wl,-rpath,@loader_path/../lib" "-Alinker-messages" "-Zunstable-options" "-Z" "binary-dep-depinfo" "--sysroot" "/Users/alklig/work/bootstrap-order-issue/build/aarch64-apple-darwin/stage1" "-Ztls-model=initial-exec"
-------------

Additionally, I tried instrumenting this line:

run.builder.ensure(Cargo {
compiler: run.builder.compiler_for(
run.builder.top_stage,
run.builder.config.build,
run.target,
),
target: run.target,
});

Like this:

        run.builder.ensure(Cargo {
            compiler: {
                let compiler = run.builder.compiler_for(
                    run.builder.top_stage,
                    run.builder.config.build,
                    run.target,
                );
                if compiler.is_forced_compiler() {
                    eprintln!("top stage is {}, cargo has a forced compiler: {:?}", run.builder.top_stage, compiler);
                }
                compiler
            },
            target: run.target,
        });

And I see this output

top stage is 2, cargo has a forced compiler: Compiler { stage: 1, host: aarch64-apple-darwin, forced_compiler: true }

Which I think interacts poorly with this code:

Mode::ToolRustc => {
// If compiler was forced, its artifacts should be prepared earlier.
if !self.compiler.is_forced_compiler() {
builder.ensure(compile::Std::new(self.compiler, self.compiler.host));
builder.ensure(compile::Rustc::new(self.compiler, target));
}
}

I don't think this is macOS specific - at work we're building across a number of platforms and they all fail at building cargo for stage 2 (Those builds have a more elaborate bootstrap.toml and with more components: ./x.py dist cargo rustfmt rust-src rustc-src rustc rust-std rust-analysis rustc-dev llvm-tools clippy but they all have cargo first in the list). Unfortunately we just started setting up our infrastructure to build the beta branch so I can't pinpoint when things went wrong. stable (1.86.0) builds as expected in our environment.

Metadata

Metadata

Assignees

No one assigned

    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