Skip to content

cargo-metadata invoked by maturin resolves dependencies differently from cargo fetch with --target specified #2561

@ziyao233

Description

@ziyao233

Bug Description

With --target argument supplied, cargo-metadata invoked by maturin during building may resolve dependencies differently from cargo-fetch, failing a --frozen build with unresolvable crates that are actually unnecessary on the target.

Your maturin version (maturin --version)

1.8.3

Your Python version (python -V)

3.13.3

Your pip version (pip -V)

25.0.1

What bindings you're using

pyo3

Does cargo build work?

  • Yes, it works

If on windows, have you checked that you aren't accidentally using unix path (those with the forward slash /)?

  • Yes

Steps to Reproduce

Taking rpds-py as example,

export CARGO_HOME=$PWD/cargocache # ensure a clean environment
cargo fetch --locked --target x86_64-unknown-linux-musl

maturin build --frozen --target x86_64-unknown-linux-musl
cargo build --frozen --target x86_64-unknown-linux-musl 

Maturin fails to build, with error message like

$ maturin build --frozen --target x86_64-unknown-linux-musl
error: failed to download `cc v1.0.90`

Caused by:
  attempting to make an HTTP request, but --frozen was specified
💥 maturin failed
  Caused by: Cargo metadata failed. Does your crate compile with `cargo build`?
  Caused by: `cargo metadata` exited with an error: 

but cargo builds the crate smoothly,

$ cargo build --target x86_64-unknown-linux-musl --frozen
   Compiling target-lexicon v0.13.2
   Compiling python3-dll-a v0.2.12
   Compiling once_cell v1.19.0
   Compiling proc-macro2 v1.0.86
   Compiling unicode-ident v1.0.12
   Compiling autocfg v1.3.0
   Compiling libc v0.2.155
   Compiling heck v0.5.0
   Compiling memoffset v0.9.1
...

Without specifying --target x86_64-unknown-linux-musl when invoking cargo fetch, both cargo and maturin successfully build the crate. The problematic dependency, cc, is only necessary on windows and shouldn't be pulled in with --target specified.

[target.'cfg(windows)'.dependencies]
cc = "1.0.73"

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions