Description
Code
$ rustc - --crate-name ___ --print=file-names --target riscv64gc-unknown-linux-musl --crate-type dylib
[EOF]
Current output
warning: dropping unsupported crate type `dylib` for target `riscv64gc-unknown-linux-musl`
warning: 1 warning emitted
Desired output
I found this error message confusing, because it implies that the target doesn't support dynamic libraries. The real issue is that rustc assumes by default that musl targets statically link libc (see https://github.com/rust-lang/rust/blob/master/compiler/rustc_target/src/spec/linux_musl_base.rs#L12 ). Even the name of the function that indirectly determines if the warning is emitted (invalid_output_for_target()
-- https://github.com/rust-lang/rust/blob/master/compiler/rustc_session/src/output.rs#L178 ) is a bit misleading, as its result isn't just based on the target, but also on the target options.
It would be helpful to reword the warning to something like:
warning: crate type `dylib` for target `riscv64gc-unknown-linux-musl` is unsupported with target options: `crt_static_default = true, crt_static_allows_dylibs = false, ...`
and/or include a suggestion to add the -Ctarget-feature=-crt-static
flag if desired.
It appears there might be some underlying unresolved issues ( I found rust-lang/compiler-team#422 ), but it seems like improving the error message isn't blocked on resolving those.
Rationale and extra context
I originally ran into this while cross-compiling rustc, but was able to isolate it to the the --print=file-names ...
output.