Skip to content

Can't bootstrap 1.89 on Windows with custom dlltool #147229

@jfgoog

Description

@jfgoog

Summary

Bootstrapping rust 1.89.0 on Windows fails at "Building tool cargo (stage1 -> stage2, x86_64-pc-windows-gnu)" when using a custom dlltool.

Command used

Somewhat complicated to describe. We build a Rust toolchain for Android with a script that is a wrapper around x.py that creates a custom bootstrap.toml and sets some environment variables. Slightly out-of-date version of build scripts is at https://android.googlesource.com/toolchain/android_rust/+/refs/heads/main

Expected behaviour

  • We are able to specify a custom dlltool that is used to bootstrap the toolchain.

Actual behaviour

  • The build fails at "Building tool cargo (stage1 -> stage2, x86_64-pc-windows-gnu)"
  • The failing command is C:/src/main-rust-toolchain/prebuilts/rust/windows-x86/1.88.0/bin/cargo.exe build --target x86_64-pc-windows-gnu -Zbinary-dep-depinfo -j 64 -Zroot-dir=C:\src\main-rust-toolchain\out\rustc -v --frozen --release --manifest-path C:\src\main-rust-toolchain\out\rustc\src/tools/cargo\Cargo.toml --features all-static
  • The failing crate is getrandom 0.3.3, with the error "error: Error calling dlltool 'dlltool.exe': program not found"

We are specifying a custom dlltool in RUSTFLAGS with "-Cdlltool=XXXX". In practice, this doesn't actually work. There seem to be a number of things going on:

  • Cargo ignores RUSTFLAGS when --target is set. This means that ALL of the rust flags, set by our build script and by the bootstrap process, are ignored, not just -Cdlltool=XXX
  • When bootstrapping the new version of cargo, the bootstrap process uses the old (stage0) version of cargo, with the new version of rustc.
  • But the bootstrap process needs to be able to pass some flags to rustc, such as telling rustc about the linker. It can't use RUSTFLAGS, so there is a special rustc wrapper (src/bootstrap/src/bin/rustc.rs) that, among other things, allows additional flags to be passed via RUSTC_HOST_FLAGS, which the bootstrap process sets before invoking cargo.
  • In our case, RUSTC_HOST_FLAGS = "--check-cfg=cfg(bootstrap) -Ctarget-feature=-crt-static -Clinker=C:/src/main-rust-toolchain/out/wrappers/linker-x86_64-pc-windows-gnu.cmd"

This does not appear to be a new issue; it's probably been latent for awhile. It looks like what changed between rust 1.88 and 1.89 is the Cargo.lock file for cargo (src/tools/cargo/Cargo.lock) bumped the version of getrandom from 0.3.1 to 0.3.3, which changes the dependencies and compilation behavior on windows (see rust-random/getrandom#627 and rust-random/getrandom#723).

Bootstrap configuration (bootstrap.toml)

change-id = 131075

[llvm]
download-ci-llvm = false
ninja = true
targets = "AArch64;ARM;X86;RISCV"
link-shared = false
cflags = ""
cxxflags = ""
ldflags = "-Wl,-mllvm,--relocation-model=pic"
use-libcxx = true
static-libstdcpp = false
thin-lto = false
version-suffix = ""
libzstd = false


[llvm.build-config]
CMAKE_BUILD_RPATH = "C:/src/main-rust-toolchain/prebuilts/clang/host/windows-x86/clang-r574158/lib"


[build]
build = "x86_64-pc-windows-gnu"
host = ["x86_64-pc-windows-gnu"]
target = ["x86_64-pc-windows-gnu"]
cargo = "C:/src/main-rust-toolchain/prebuilts/rust/windows-x86/1.88.0/bin/cargo.exe"
rustc = "C:/src/main-rust-toolchain/prebuilts/rust/windows-x86/1.88.0/bin/rustc.exe"
python = "C:/src/main-rust-toolchain/prebuilts/python/windows-x86/python.exe"
verbose = 1
docs = false
submodules = false
vendor = true
full-bootstrap = true
extended = true
tools = ["cargo", "clippy", "rustdoc", "rustfmt", "rust-analyzer"]
cargo-native-static = true

[dist]
compression-formats = ["gz"]
include-mingw-linker = false

[install]
prefix = "/"
sysconfdir = "etc"

[rust]
channel = "dev"
description = "Android Rust Toolchain version windows"
download-rustc = false
remap-debuginfo = true
deny-warnings = false
new-symbol-mangling = true
lld = false
lto = "thin-local"


[target.x86_64-pc-windows-gnu]
cc = "C:/src/main-rust-toolchain/out/wrappers/clang-x86_64-pc-windows-gnu.cmd"
cxx = "C:/src/main-rust-toolchain/out/wrappers/clang++-x86_64-pc-windows-gnu.cmd"
linker = "C:/src/main-rust-toolchain/out/wrappers/linker-x86_64-pc-windows-gnu.cmd"
ar = "C:/src/main-rust-toolchain/prebuilts/clang/host/windows-x86/clang-r574158/bin/llvm-ar.exe"
ranlib = "C:/src/main-rust-toolchain/prebuilts/clang/host/windows-x86/clang-r574158/bin/llvm-ranlib.exe"
crt-static = false
llvm-libunwind = "in-tree"
profiler = false

Operating system

Windows 11

HEAD

2948388

With some patches: https://android.googlesource.com/toolchain/android_rust/+/refs/heads/main/patches/ (somewhat out-of-date due to AOSP turndown)

Additional context

Full set of environment variables used when invoking std::process::Command:

"AR_x86_64_pc_windows_gnu", Some("C:/src/main-rust-toolchain/prebuilts/clang/host/windows-x86/clang-r574158/bin/llvm-ar.exe")
"CARGO_INCREMENTAL", Some("0")
"CARGO_PROFILE_RELEASE_DEBUG", Some("0")
"CARGO_PROFILE_RELEASE_DEBUG_ASSERTIONS", Some("false")
"CARGO_PROFILE_RELEASE_OVERFLOW_CHECKS", Some("false")
"CARGO_PROFILE_RELEASE_STRIP", Some("false")
"CARGO_TARGET_DIR", Some("C:\\src\\main-rust-toolchain\\out\\rustc\\build\\x86_64-pc-windows-gnu\\stage1-tools")
"CARGO_TARGET_X86_64_PC_WINDOWS_GNU_LINKER", Some("C:/src/main-rust-toolchain/out/wrappers/linker-x86_64-pc-windows-gnu.cmd")
"CC_x86_64_pc_windows_gnu", Some("C:/src/main-rust-toolchain/out/wrappers/clang-x86_64-pc-windows-gnu.cmd")
"CFG_COMMIT_DATE", Some("2025-06-23")
"CFG_COMMIT_HASH", Some("c24e1064277fe51ab72011e2612e556ac56addf7")
"CFG_COMPILER_BUILD_TRIPLE", Some("x86_64-pc-windows-gnu")
"CFG_COMPILER_HOST_TRIPLE", Some("x86_64-pc-windows-gnu")
"CFG_RELEASE", Some("1.89.0-dev")
"CFG_RELEASE_CHANNEL", Some("dev")
"CFG_RELEASE_NUM", Some("1.89.0")
"CFG_SHORT_COMMIT_HASH", Some("c24e10642")
"CFG_VERSION", Some("1.89.0-dev (29483883e 2025-08-04) (Android Rust Toolchain version windows)")
"CFG_VER_DATE", Some("2025-08-04")
"CFG_VER_DESCRIPTION", Some("Android Rust Toolchain version windows")
"CFG_VER_HASH", Some("29483883eed69d5fb4db01964cdf2af4d86e9cb2")
"CFLAGS_x86_64_pc_windows_gnu", Some("")
"CXXFLAGS_x86_64_pc_windows_gnu", Some("")
"CXX_x86_64_pc_windows_gnu", Some("C:/src/main-rust-toolchain/out/wrappers/clang++-x86_64-pc-windows-gnu.cmd")
"DOC_RUST_LANG_ORG_CHANNEL", Some("https://doc.rust-lang.org/nightly")
"LIBC_CHECK_CFG", Some("1")
"LIBZ_SYS_STATIC", Some("1")
"LZMA_API_STATIC", Some("1")
"MAKEFLAGS", None
"MFLAGS", None
"RANLIB_x86_64_pc_windows_gnu", Some("C:/src/main-rust-toolchain/prebuilts/clang/host/windows-x86/clang-r574158/bin/llvm-ar.exe s")
"REAL_LIBRARY_PATH", Some("C:\\src\\main-rust-toolchain\\prebuilts\\python\\windows-x86;C:\\src\\main-rust-toolchain\\prebuilts\\rust\\windows-x86\\1.88.0\\bin;C:\\src\\main-rust-toolchain\\prebuilts\\cmake\\windows-x86\\bin;C:\\src\\main-rust-toolchain\\prebuilts\\ninja\\windows-x86;C:\\src\\main-rust-toolchain\\prebuilts\\build-tools\\path\\windows-x86;C:\\src\\main-rust-toolchain\\prebuilts\\build-tools\\windows-x86\\bin;C:\\src\\main-rust-toolchain\\out\\rust-toolchain\\bin;C:\\program files\\git\\usr\\bin;C:\\src\\main-rust-toolchain\\prebuilts\\gcc\\linux-x86\\host\\x86_64-w64-mingw32-4.8\\x86_64-w64-mingw32\\bin;C:\\src\\main-rust-toolchain\\prebuilts\\gcc\\linux-x86\\host\\x86_64-w64-mingw32-4.8\\x86_64-w64-mingw32\\lib")
"REAL_LIBRARY_PATH_VAR", Some("PATH")
"RUSTBUILD_NATIVE_DIR", Some("C:\\src\\main-rust-toolchain\\out\\rustc\\build\\x86_64-pc-windows-gnu\\native")
"RUSTC", Some("C:\\src\\main-rust-toolchain\\out\\rustc\\build\\bootstrap\\debug\\rustc")
"RUSTC_BOOTSTRAP", Some("1")
"RUSTC_BREAK_ON_ICE", Some("1")
"RUSTC_CARGO_REGISTRY_SRC_TO_REMAP", Some("C:\\src\\main-rust-toolchain\\out\\rustc\\vendor=/rust/deps")
"RUSTC_DEBUGINFO_MAP", Some("C:\\src\\main-rust-toolchain\\out\\rustc=/rustc/29483883eed69d5fb4db01964cdf2af4d86e9cb2")
"RUSTC_ERROR_METADATA_DST", Some("C:\\src\\main-rust-toolchain\\out\\rustc\\build\\tmp/extended-error-metadata")
"RUSTC_HOST_FLAGS", Some("--check-cfg=cfg(bootstrap) -Ctarget-feature=-crt-static -Clinker=C:/src/main-rust-toolchain/out/wrappers/linker-x86_64-pc-windows-gnu.cmd")
"RUSTC_INSTALL_BINDIR", Some("bin")
"RUSTC_LIBDIR", Some("C:\\src\\main-rust-toolchain\\out\\rustc\\build\\x86_64-pc-windows-gnu\\stage1\\bin")
"RUSTC_LINK_STD_INTO_RUSTC_DRIVER", Some("0")
"RUSTC_LINT_FLAGS", Some("")
"RUSTC_REAL", Some("C:\\src\\main-rust-toolchain\\out\\rustc\\build\\x86_64-pc-windows-gnu\\stage1\\bin\\rustc.exe")
"RUSTC_SNAPSHOT", Some("C:\\src\\main-rust-toolchain\\out\\rustc\\build\\x86_64-pc-windows-gnu\\stage1\\bin\\rustc.exe")
"RUSTC_SNAPSHOT_LIBDIR", Some("C:\\src\\main-rust-toolchain\\out\\rustc\\build\\x86_64-pc-windows-gnu\\stage1\\bin")
"RUSTC_STAGE", Some("1")
"RUSTC_SYSROOT", Some("C:\\src\\main-rust-toolchain\\out\\rustc\\build\\x86_64-pc-windows-gnu\\stage1")
"RUSTC_TLS_MODEL_INITIAL_EXEC", Some("1")
"RUSTC_VERBOSE", Some("1")
"RUSTC_WRAPPER", Some("C:\\src\\main-rust-toolchain\\out\\rustc\\build\\bootstrap\\debug\\rustc")
"RUSTDOC", Some("C:\\src\\main-rust-toolchain\\out\\rustc\\build\\bootstrap\\debug\\rustdoc")
"RUSTDOCFLAGS", Some("-Crelocation-model=pic -Csave-temps -Cdlltool=C:\\src\\main-rust-toolchain\\prebuilts\\clang\\host\\windows-x86\\clang-r574158\\bin\\llvm-dlltool.exe --cfg=windows_raw_dylib -Csymbol-mangling-version=v0 -Zunstable-options --check-cfg=cfg(bootstrap) --check-cfg=cfg(llvm_enzyme) --check-cfg=cfg(rust_analyzer) -Clinker=C:\\src\\main-rust-toolchain\\out\\wrappers\\linker-x86_64-pc-windows-gnu.cmd --crate-version 1.89.0-dev\t(29483883e\t2025-08-04)\t(Android\tRust\tToolchain\tversion\twindows) -Clinker=C:/src/main-rust-toolchain/out/wrappers/linker-x86_64-pc-windows-gnu.cmd")
"RUSTDOC_REAL", Some("/path/to/nowhere/rustdoc/not/required")
"RUSTFLAGS", Some("-Crelocation-model=pic -Csave-temps -Cdlltool=C:\\src\\main-rust-toolchain\\prebuilts\\clang\\host\\windows-x86\\clang-r574158\\bin\\llvm-dlltool.exe --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=packed -Ctarget-feature=-crt-static -Clink-arg=-LC:/src/main-rust-toolchain/out/rustc/build/x86_64-pc-windows-gnu/llvm/lib -Alinker-messages -Zunstable-options")
"RUST_TEST_THREADS", Some("64")
"SYSROOT", Some("C:\\src\\main-rust-toolchain\\out\\rustc\\build\\x86_64-pc-windows-gnu\\stage1")
"__CARGO_DEFAULT_LIB_METADATA", Some("devtool-rustc1.89.0")

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.O-androidOperating system: AndroidT-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