Skip to content

build and target aren't distinguished during llvm building #132926

Closed
@ziyao233

Description

@ziyao233

Cross-compiling rust 1.82.0 itself fails with custom LLVM used on the build and vendored llvm on the host.

$ ./x.py build -j30 -v
...
-- Installing: /root/la64_rust/rustc-1.82.0-src/build/loongarch64-unknown-linux-musl/llvm/lib/cmake/llvm/LLVMConfigExtensions.cmake
cargo:root=/root/la64_rust/rustc-1.82.0-src/build/loongarch64-unknown-linux-musl/llvm
running: "/root/la64_rust/rustc-1.82.0-src/build/x86_64-unknown-linux-musl/llvm/bin/llvm-config" "--version" (failure_mode=Exit) (created at src/core/build_steps/llvm.rs:508:17, executed at src/core/build_steps/llvm.rs:508:60)


Command "/root/la64_rust/rustc-1.82.0-src/build/x86_64-unknown-linux-musl/llvm/bin/llvm-config" "--version" (failure_mode=Exit) did not execute successfully.
It was not possible to execute the command: Os { code: 2, kind: NotFound, message: "No such file or directory" }

Traceback (most recent call last):
  File "/root/la64_rust/rustc-1.82.0-src/./x.py", line 50, in <module>
    bootstrap.main()
  File "/root/la64_rust/rustc-1.82.0-src/src/bootstrap/bootstrap.py", line 1208, in main
    bootstrap(args)
  File "/root/la64_rust/rustc-1.82.0-src/src/bootstrap/bootstrap.py", line 1184, in bootstrap
    run(args, env=env, verbose=build.verbose, is_bootstrap=True)
  File "/root/la64_rust/rustc-1.82.0-src/src/bootstrap/bootstrap.py", line 195, in run
    raise RuntimeError(err)
RuntimeError: failed to run: /root/la64_rust/rustc-1.82.0-src/build/bootstrap/debug/bootstrap build -j30 -v

config.toml is configured as

change-id = 129295
profile = "user"

[llvm]
link-shared = true
static-libstdcpp = false
use-libcxx = true
targets = "X86;LoongArch;WebAssembly"

[build]
build = "x86_64-unknown-linux-musl"
host = ["loongarch64-unknown-linux-musl"]
target = ["loongarch64-unknown-linux-musl"]
cargo = "/usr/bin/cargo"
rustc = "/usr/bin/rustc"
rustfmt = "/usr/bin/rustfmt"
locked-deps = true
vendor = true
tools = ["cargo"]
sanitizers = false
profiler = true
# Generating docs fails with the wasm32-* targets
docs = false

[install]
prefix = "/usr"

[rust]
debuginfo-level-std = 2
channel = "stable"
description = "eweOS rust %RUSTVER%"
rpath = false
backtrace-on-ice = true
remap-debuginfo = true
jemalloc = false
llvm-libunwind = "system"
codegen-units-std = 1
deny-warnings = false
lld = false
musl-root = "/usr"

[target.x86_64-unknown-linux-musl]
crt-static = false
llvm-config = "/usr/bin/llvm-config"

[target.loongarch64-unknown-linux-musl]
crt-static = false
cc="clang"
cxx="clang++"
linker="/usr/bin/loongarch64-unknown-linux-musl-clang"
musl-root="/opt/sysroot-loongarch64"
musl-libdir="/opt/sysroot-loongarch64/usr/lib"

The error occurs in src/bootstrap/src/core/build_steps/llvm.rs: find_llvm_lib_name()1,

        let find_llvm_lib_name = |extension| {
            let version =
                command(&res.llvm_config).arg("--version").run_capture_stdout(builder).stdout();
            let major = version.split('.').next().unwrap();


            match &llvm_version_suffix {
                Some(version_suffix) => format!("libLLVM-{major}{version_suffix}.{extension}"),
                None => format!("libLLVM-{major}.{extension}"),
            }
        };

which tries to exec llvm-config of LLVM built for the build, but we don't acutally build it according to the configuration.

This problematic path is generated in prebuilt_llvm_config()2

    let mut llvm_config_ret_dir = builder.llvm_out(builder.config.build);
    llvm_config_ret_dir.push("bin");
    let build_llvm_config = llvm_config_ret_dir.join(exe("llvm-config", builder.config.build));

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-crossArea: Cross compilationC-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