Trying to build rustc from scratch, missing std lib

Previously, I had always built rustc with the follow command: ./x build library --stage 2

Looking at the build logs everything seems correct, however, when I try to build (tag=v.1.85.0) I get an error saying it doesn't have the stdlib. Also, suspiciously, the rustc bin is half the size of my old builds.

rror[E0463]: can't find crate for `std`
  |
  = note: the `aarch64-apple-darwin` target may not be installed
  = help: consider adding the standard library to the sysroot with `x build library --target 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`.
error[E0463]: can't find crate for `core`
  |
  = note: the `aarch64-apple-darwin` target may not be installed
  = help: consider adding the standard library to the sysroot with `x build library --target aarch64-apple-darwin`
  = help: consider building the standard library from source with `cargo build -Zbuild-std`

error: could not compile `version_check` (lib) due to 1 previous error
warning: build failed, waiting for other jobs to finish...
error: could not compile `serde` (build script) due to 1 previous error
error: could not compile `proc-macro2` (build script) due to 1 previous error
error: could not compile `syn` (build script) due to 1 previous error
error: could not compile `base64` (lib) due to 1 previous error
error: could not compile `unicode-ident` (lib) due to 1 previous error
error: could not compile `typenum` (build script) due to 1 previous error
error: could not compile `autocfg` (lib) due to 1 previous error
error: could not compile `unicode-width` (lib) due to 1 previous error

Any help is appreciated!

Also, my command actually specifies a different target, aarch64-apple-darwin is my host machine.

> rustc +succinct --print target-list | grep succinct
riscv32im-succinct-zkvm-elf

>rustc +succinct --print sysroot
/Users/nhtyy/succinct/rust/build/aarch64-apple-darwin/stage2

>cargo +succinct build --target riscv32im-succinct-zkvm-elf
<elided as in original post>

What is your config.toml?

It looks like this

[build]
target = ["riscv32im-succinct-zkvm-elf"]
extended = true
tools = ["cargo", "cargo-clippy", "clippy", "rustfmt"]
configure-args = []
cargo-native-static = true

[rust]
lld = true
llvm-tools = true

[llvm]
download-ci-llvm = false

This is for a target I maintain (and plan on upstreaming very soon).

I was actually able to resolve this issue by changing the build command to

./x build --stage 2 compiler/rustc library .

In the target key you need to also include the triple of the host platform. Otherwise the resulting compiler can't build proc macros and build scripts for the host.

Oh interesting are you saying in both cases? What is the difference between the two commands?

I think for my use case I actually only care about cross compilation so maybe thats why I haven't noticed the issue you're describing.

When doing ./x.py build --stage 2 compiler/rustc library implicitly causes a standard library to be built for the host as that is necessary for building the stage 2 compiler for the host.

Even when cross-compiling you often have dependencies with build scripts and proc macros that need to be compiled for the host.

When doing ./x.py build --stage 2 compiler/rustc library implicitly causes a standard library to be built for the host as that is necessary for building the stage 2 compiler for the host.

Oh so even without my "host" target listed in the config.toml it still creates some things for my host, but not everything I may need? And this is the reason I was seeing the errors, even though I was compiling to the custom target?

Yes, if one of your dependencies has a build script or proc macro it will get compiled for the host. Most projects have at least one build script or proc macro somewhere in their dependency graph. In your case for example serde, base64, typenum and one or more dependencies that use autocfg.