Skip to content

"cannot produce dylib for rustc_driver v0.0.0 ... as the target riscv64gc-unknown-linux-musl does not support these crate types" #110511

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
catamorphism opened this issue Apr 18, 2023 · 2 comments
Labels
A-linkage Area: linking into static, shared libraries and binaries C-enhancement Category: An issue proposing an enhancement or a PR with one. O-musl Target: The musl libc T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-cargo Relevant to the cargo team, which will review and decide on the PR/issue.

Comments

@catamorphism
Copy link
Contributor

catamorphism commented Apr 18, 2023

I'm cross-compiling Rust for riscv64gc-unknown-linux-musl with the following config.toml:

profile = "codegen"
changelog-seen = 2

[build]
docs = false
compiler-docs = false
extended = true

[target.riscv64gc-unknown-linux-musl]
ar = "/home/scratch/riscv/bin/riscv64-unknown-linux-musl-ar"
linker = "/home/scratch/riscv/bin/riscv64-unknown-linux-musl-gcc"
cc = "/home/scratch/riscv/bin/riscv64-unknown-linux-musl-gcc"
cxx = "/home/scratch/riscv/bin/riscv64-unknown-linux-musl-g++"
musl-root = "/home/scratch/riscv/sysroot"

[llvm]
download-ci-llvm = false
link-shared = false

Executing:
RUSTFLAGS="-Clink-args=-lgcc" ./x.py build --host riscv64gc-unknown-linux-musl --target riscv64gc-unknown-linux-musl --verbose

the output is:

[snip]
Building compiler artifacts (stage1:x86_64-unknown-linux-gnu -> stage2:riscv64gc-unknown-linux-musl)
running: cd "/home/scratch/rust" && AR_riscv64gc_unknown_linux_musl="/home/scratch/riscv/bin/riscv64-unknown-linux-musl-ar" CARGO_INCREMENTAL="1" CARGO_PROFILE_RELEASE_DEBUG="0" CARGO_PROFILE_RELEASE_DEBUG_ASSERTIONS="false" CARGO_PROFILE_RELEASE_OVERFLOW_CHECKS="false" CARGO_TARGET_DIR="/home/scratch/rust/build/x86_64-unknown-linux-gnu/stage1-rustc" CARGO_TARGET_RISCV64GC_UNKNOWN_LINUX_MUSL_LINKER="/home/scratch/riscv/bin/riscv64-unknown-linux-musl-gcc" CC_riscv64gc_unknown_linux_musl="/home/scratch/riscv/bin/riscv64-unknown-linux-musl-gcc" CFG_COMPILER_HOST_TRIPLE="riscv64gc-unknown-linux-musl" CFG_DEFAULT_CODEGEN_BACKEND="llvm" CFG_LIBDIR_RELATIVE="lib" CFG_RELEASE="1.71.0-dev" CFG_RELEASE_CHANNEL="dev" CFG_VERSION="1.71.0-dev" CFLAGS_riscv64gc_unknown_linux_musl="-ffunction-sections -fdata-sections -fPIC -march=rv64gc -mabi=lp64d -mcmodel=medany -static" CXXFLAGS_riscv64gc_unknown_linux_musl="-ffunction-sections -fdata-sections -fPIC -march=rv64gc -mabi=lp64d -mcmodel=medany -static" CXX_riscv64gc_unknown_linux_musl="/home/scratch/riscv/bin/riscv64-unknown-linux-musl-g++" LIBC_CHECK_CFG="1" LLVM_CONFIG="/home/scratch/rust/build/x86_64-unknown-linux-gnu/llvm/build/bin/llvm-config" LLVM_NDEBUG="1" LLVM_RUSTLLVM="1" RANLIB_riscv64gc_unknown_linux_musl="/home/scratch/riscv/bin/riscv64-unknown-linux-musl-ar s" REAL_LIBRARY_PATH_VAR="LD_LIBRARY_PATH" RUSTBUILD_NATIVE_DIR="/home/scratch/rust/build/riscv64gc-unknown-linux-musl/native" RUSTC="/home/scratch/rust/build/bootstrap/debug/rustc" RUSTC_BACKTRACE_ON_ICE="1" RUSTC_BOOTSTRAP="1" RUSTC_BREAK_ON_ICE="1" RUSTC_ERROR_METADATA_DST="/home/scratch/rust/build/tmp/extended-error-metadata" RUSTC_FORCE_UNSTABLE="1" RUSTC_INSTALL_BINDIR="bin" RUSTC_LIBDIR="/home/scratch/rust/build/x86_64-unknown-linux-gnu/stage1/lib" RUSTC_LINT_FLAGS="-Wrust_2018_idioms -Wunused_lifetimes -Wsemicolon_in_expressions_from_macros -Dwarnings" RUSTC_REAL="/home/scratch/rust/build/x86_64-unknown-linux-gnu/stage1/bin/rustc" RUSTC_SNAPSHOT="/home/scratch/rust/build/x86_64-unknown-linux-gnu/stage1/bin/rustc" RUSTC_SNAPSHOT_LIBDIR="/home/scratch/rust/build/x86_64-unknown-linux-gnu/stage1/lib" RUSTC_STAGE="1" RUSTC_SYSROOT="/home/scratch/rust/build/x86_64-unknown-linux-gnu/stage1" RUSTC_TLS_MODEL_INITIAL_EXEC="1" RUSTC_VERBOSE="1" RUSTDOC="/home/scratch/rust/build/bootstrap/debug/rustdoc" RUSTDOCFLAGS="-Clink-args=-lgcc --cfg=windows_raw_dylib -Csymbol-mangling-version=v0 -Zunstable-options --check-cfg=values(bootstrap) --check-cfg=values(parallel_compiler) --check-cfg=values(no_btreemap_remove_entry) --check-cfg=values(crossbeam_loom) --check-cfg=values(span_locations) --check-cfg=values(rustix_use_libc) --check-cfg=values(emulate_second_only_system) --check-cfg=values(windows_raw_dylib) -Dwarnings -Wrustdoc::invalid_codeblock_attributes --crate-version 1.71.0-dev" RUSTDOC_REAL="/path/to/nowhere/rustdoc/not/required" RUSTFLAGS="-Clink-args=-lgcc --cfg=windows_raw_dylib -Csymbol-mangling-version=v0 -Zunstable-options --check-cfg=values(bootstrap) --check-cfg=values(parallel_compiler) --check-cfg=values(no_btreemap_remove_entry) --check-cfg=values(crossbeam_loom) --check-cfg=values(span_locations) --check-cfg=values(rustix_use_libc) --check-cfg=values(emulate_second_only_system) --check-cfg=values(windows_raw_dylib) -Zdual-proc-macros -Zmacro-backtrace -Clink-args=-Wl,-z,origin -Clink-args=-Wl,-rpath,$ORIGIN/../lib -Csplit-debuginfo=off -Zunstable-options -Wrustc::internal -Cprefer-dynamic -Cllvm-args=-import-instr-limit=10 -Clto=off" RUST_TEST_THREADS="32" WINAPI_NO_BUNDLED_LIBRARIES="1" __CARGO_DEFAULT_LIB_METADATA="dev" "/home/scratch/rust/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "build" "--target" "riscv64gc-unknown-linux-musl" "--release" "-Zcheck-cfg=names,values,output,features" "-Zdual-proc-macros" "-Zbinary-dep-depinfo" "-j" "32" "-v" "--features" "llvm" "--manifest-path" "/home/scratch/rust/compiler/rustc/Cargo.toml" "--message-format" "json-render-diagnostics"
error: cannot produce dylib for `rustc_driver v0.0.0 (/home/scratch/rust/compiler/rustc_driver)` as the target `riscv64gc-unknown-linux-musl` does not support these crate types
command did not execute successfully: cd "/home/scratch/rust" && AR_riscv64gc_unknown_linux_musl="/home/scratch/riscv/bin/riscv64-unknown-linux-musl-ar" CARGO_INCREMENTAL="1" CARGO_PROFILE_RELEASE_DEBUG="0" CARGO_PROFILE_RELEASE_DEBUG_ASSERTIONS="false" CARGO_PROFILE_RELEASE_OVERFLOW_CHECKS="false" CARGO_TARGET_DIR="/home/scratch/rust/build/x86_64-unknown-linux-gnu/stage1-rustc" CARGO_TARGET_RISCV64GC_UNKNOWN_LINUX_MUSL_LINKER="/home/scratch/riscv/bin/riscv64-unknown-linux-musl-gcc" CC_riscv64gc_unknown_linux_musl="/home/scratch/riscv/bin/riscv64-unknown-linux-musl-gcc" CFG_COMPILER_HOST_TRIPLE="riscv64gc-unknown-linux-musl" CFG_DEFAULT_CODEGEN_BACKEND="llvm" CFG_LIBDIR_RELATIVE="lib" CFG_RELEASE="1.71.0-dev" CFG_RELEASE_CHANNEL="dev" CFG_VERSION="1.71.0-dev" CFLAGS_riscv64gc_unknown_linux_musl="-ffunction-sections -fdata-sections -fPIC -march=rv64gc -mabi=lp64d -mcmodel=medany -static" CXXFLAGS_riscv64gc_unknown_linux_musl="-ffunction-sections -fdata-sections -fPIC -march=rv64gc -mabi=lp64d -mcmodel=medany -static" CXX_riscv64gc_unknown_linux_musl="/home/scratch/riscv/bin/riscv64-unknown-linux-musl-g++" LIBC_CHECK_CFG="1" LLVM_CONFIG="/home/scratch/rust/build/x86_64-unknown-linux-gnu/llvm/build/bin/llvm-config" LLVM_NDEBUG="1" LLVM_RUSTLLVM="1" RANLIB_riscv64gc_unknown_linux_musl="/home/scratch/riscv/bin/riscv64-unknown-linux-musl-ar s" REAL_LIBRARY_PATH_VAR="LD_LIBRARY_PATH" RUSTBUILD_NATIVE_DIR="/home/scratch/rust/build/riscv64gc-unknown-linux-musl/native" RUSTC="/home/scratch/rust/build/bootstrap/debug/rustc" RUSTC_BACKTRACE_ON_ICE="1" RUSTC_BOOTSTRAP="1" RUSTC_BREAK_ON_ICE="1" RUSTC_ERROR_METADATA_DST="/home/scratch/rust/build/tmp/extended-error-metadata" RUSTC_FORCE_UNSTABLE="1" RUSTC_INSTALL_BINDIR="bin" RUSTC_LIBDIR="/home/scratch/rust/build/x86_64-unknown-linux-gnu/stage1/lib" RUSTC_LINT_FLAGS="-Wrust_2018_idioms -Wunused_lifetimes -Wsemicolon_in_expressions_from_macros -Dwarnings" RUSTC_REAL="/home/scratch/rust/build/x86_64-unknown-linux-gnu/stage1/bin/rustc" RUSTC_SNAPSHOT="/home/scratch/rust/build/x86_64-unknown-linux-gnu/stage1/bin/rustc" RUSTC_SNAPSHOT_LIBDIR="/home/scratch/rust/build/x86_64-unknown-linux-gnu/stage1/lib" RUSTC_STAGE="1" RUSTC_SYSROOT="/home/scratch/rust/build/x86_64-unknown-linux-gnu/stage1" RUSTC_TLS_MODEL_INITIAL_EXEC="1" RUSTC_VERBOSE="1" RUSTDOC="/home/scratch/rust/build/bootstrap/debug/rustdoc" RUSTDOCFLAGS="-Clink-args=-lgcc --cfg=windows_raw_dylib -Csymbol-mangling-version=v0 -Zunstable-options --check-cfg=values(bootstrap) --check-cfg=values(parallel_compiler) --check-cfg=values(no_btreemap_remove_entry) --check-cfg=values(crossbeam_loom) --check-cfg=values(span_locations) --check-cfg=values(rustix_use_libc) --check-cfg=values(emulate_second_only_system) --check-cfg=values(windows_raw_dylib) -Dwarnings -Wrustdoc::invalid_codeblock_attributes --crate-version 1.71.0-dev" RUSTDOC_REAL="/path/to/nowhere/rustdoc/not/required" RUSTFLAGS="-Clink-args=-lgcc --cfg=windows_raw_dylib -Csymbol-mangling-version=v0 -Zunstable-options --check-cfg=values(bootstrap) --check-cfg=values(parallel_compiler) --check-cfg=values(no_btreemap_remove_entry) --check-cfg=values(crossbeam_loom) --check-cfg=values(span_locations) --check-cfg=values(rustix_use_libc) --check-cfg=values(emulate_second_only_system) --check-cfg=values(windows_raw_dylib) -Zdual-proc-macros -Zmacro-backtrace -Clink-args=-Wl,-z,origin -Clink-args=-Wl,-rpath,$ORIGIN/../lib -Csplit-debuginfo=off -Zunstable-options -Wrustc::internal -Cprefer-dynamic -Cllvm-args=-import-instr-limit=10 -Clto=off" RUST_TEST_THREADS="32" WINAPI_NO_BUNDLED_LIBRARIES="1" __CARGO_DEFAULT_LIB_METADATA="dev" "/home/scratch/rust/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "build" "--target" "riscv64gc-unknown-linux-musl" "--release" "-Zcheck-cfg=names,values,output,features" "-Zdual-proc-macros" "-Zbinary-dep-depinfo" "-j" "32" "-v" "--features" "llvm" "--manifest-path" "/home/scratch/rust/compiler/rustc/Cargo.toml" "--message-format" "json-render-diagnostics"
expected success, got: exit status: 101
Traceback (most recent call last):
  File "/home/scratch/rust/./x.py", line 29, in <module>
    bootstrap.main()
  File "/home/scratch/rust/src/bootstrap/bootstrap.py", line 951, in main
    bootstrap(args)
  File "/home/scratch/rust/src/bootstrap/bootstrap.py", line 926, in bootstrap
    run(args, env=env, verbose=build.verbose, is_bootstrap=True)
  File "/home/scratch/rust/src/bootstrap/bootstrap.py", line 167, in run
    raise RuntimeError(err)
RuntimeError: failed to run: /home/scratch/rust/build/bootstrap/debug/bootstrap build --host riscv64gc-unknown-linux-musl --target riscv64gc-unknown-linux-musl --verbose

If I edit the compiler/rustc_driver/Cargo.toml file as suggested here, it works.

I filed a separate bug, #110509, about the error message, but even aside from the diagnostics, this behavior seems wrong. My understanding of what the error means is "we can't build the extended Rust tool set, because that requires a dynamically linked rustc_driver crate, which can't be built for a target with a statically linked C runtime" (if my understanding is wrong, let me know.) That seems like a condition that should be detected at config time, not midway through the build. Moreover, if this really is an intrinsic limitation of compiling Rust for statically linked targets, it seems weird to me that the compiler/rustc_driver/Cargo.toml patch would fix it. On the other hand, if it's not an intrinsic limitation, then manually patching this file shouldn't be necessary and the preferred crate type for rustc_driver should be auto-detected based on the target and target options.

Hope this makes sense, but if further clarification is needed, let me know!

@catamorphism catamorphism added the C-bug Category: This is a bug. label Apr 18, 2023
@jyn514 jyn514 added A-linkage Area: linking into static, shared libraries and binaries T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-cargo Relevant to the cargo team, which will review and decide on the PR/issue. O-musl Target: The musl libc C-enhancement Category: An issue proposing an enhancement or a PR with one. labels Apr 19, 2023
@jyn514
Copy link
Member

jyn514 commented Apr 19, 2023

My understanding of what the error means is "we can't build the extended Rust tool set, because that requires a dynamically linked rustc_driver crate, which can't be built for a target with a statically linked C runtime" (if my understanding is wrong, let me know.) That seems like a condition that should be detected at config time, not midway through the build.

👍 that seems like something we should detect in sanity.rs (maybe somewhere around

for host in &build.hosts {
if !build.config.dry_run() {
cmd_finder.must_have(build.cxx(*host).unwrap());
?). We could either run rustc --crate-type dylib --target ... on a dummy hello world program, or copy the invalid_output_for_target logic into bootstrap (and get the target spec with --print target-spec-json).

Separately, this seems like something cargo should detect as soon as it parses the Cargo.toml files, it's not specific to bootstrapping.

Moreover, if this really is an intrinsic limitation of compiling Rust for statically linked targets, it seems weird to me that the compiler/rustc_driver/Cargo.toml patch would fix it. On the other hand, if it's not an intrinsic limitation, then manually patching this file shouldn't be necessary and the preferred crate type for rustc_driver should be auto-detected based on the target and target options.

I wouldn't call it an instrinsic limitation, but right now bootstrap assumes in several places that rustc_driver is always dynamically linked (e.g.

rust/src/bootstrap/compile.rs

Lines 1602 to 1611 in d6af602

} else if rlib_only_metadata {
if filename.contains("jemalloc_sys") || filename.contains("rustc_smir") {
// jemalloc_sys and rustc_smir are not linked into librustc_driver.so,
// so we need to distribute them as rlib to be able to use them.
keep |= filename.ends_with(".rlib");
} else {
// Distribute the rest of the rustc crates as rmeta files only to reduce
// the tarball sizes by about 50%. The object files are linked into
// librustc_driver.so, so it is still possible to link against them.
keep |= filename.ends_with(".rmeta");
). I am not sure whether it would be easier to change bootstrap to support a statically linked rustc_driver or to change it to expose -C target-feature=-crt-static as a supported config option, both would be non-trivial.

@jyn514
Copy link
Member

jyn514 commented Apr 19, 2023

Oh, it looks like we already expose crt-static=false: #103199 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linkage Area: linking into static, shared libraries and binaries C-enhancement Category: An issue proposing an enhancement or a PR with one. O-musl Target: The musl libc T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-cargo Relevant to the cargo team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants