Skip to content

"warning: dropping unsupported crate type dylib" for linux-musl targets #110509

Open
@catamorphism

Description

@catamorphism

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-linkageArea: linking into static, shared libraries and binariesE-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.O-muslTarget: The musl libcT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions