Skip to content

The bindeps feature with cdylib artefact doesn't work when cross compiling for musl target #15095

Open
@zzsergant

Description

@zzsergant

I have a workspace with two crates:

  • foo - cdylib library with extern "C" functions
  • bar - application, that uses foo library (as shared library)

The bar crate uses unstable bindeps feature of cargo to specify build dependency on artefact cdylib of foo library in Cargo.toml.

Everything works fine when built for native toolchain, but when I build bar with specifying a --target aarch64-unknown-linux-musl for cross compiling, then I get an error:

/work # cargo build --release --target aarch64-unknown-linux-musl -p bar
error: cannot produce cdylib for `foo v0.1.0 (/work/foo)` as the target `x86_64-unknown-linux-musl` does not support these crate types

In the error above it says it can't produce cdylib for target x86_64, even though I specified aarch64.

If I build foo library, it compiled successfully:

/work # cargo build --release --target aarch64-unknown-linux-musl -p foo
   Compiling foo v0.1.0 (/work/foo)
    Finished `release` profile [optimized] target(s) in 0.14s

I've attached a minimal example to reproduce that issue:
musl_cdylib.zip

It contains a workspace with foo and bar crates, Dockerfile to setup environment for cross compilation, and README.md with steps to build an image.

Meta

rustc --version --verbose:

rustc 1.86.0-nightly (419b3e2d3 2025-01-15)
binary: rustc
commit-hash: 419b3e2d3e350822550eee0e82eeded4d324d584
commit-date: 2025-01-15
host: x86_64-unknown-linux-gnu
release: 1.86.0-nightly
LLVM version: 19.1.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-cross-compilingArea: using --target flag for other platformsC-bugCategory: bugS-triageStatus: This issue is waiting on initial triage.Z-bindepsNightly: binary artifact dependencies

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions