Difficulty using cargo's `[patch]`

Make a new crate with the following Cargo.toml:

[package]
name = "test-ffi"
version = "0.1.0"
authors = ["Michael Lamparski <diagonaldevice@gmail.com>"]

[dependencies]
mpi = "0.5.4"

[dependencies.libffi-sys]
version = "0.6.2-alpha.0"
git = "https://github.com/ExpHP/libffi-sys-rs"
branch = "system-feature"
features = ["system"]
# For future visitors, in case I later push a commit that resolves the error:
# rev = "11238e18"

[patch.crates-io.libffi-sys]
git = "https://github.com/ExpHP/libffi-sys-rs"
branch = "system-feature"

You'll see this:

$ cargo build
    Updating git repository `https://github.com/ExpHP/libffi-sys-rs`
    Updating registry `https://github.com/rust-lang/crates.io-index`
error: multiple packages link to native library `ffi`, but a native library can be linked only once

package `libffi-sys v0.6.2-alpha.0 (https://github.com/ExpHP/libffi-sys-rs?branch=system-feature#11238e18)`
    ... which is depended on by `test-ffi v0.1.0 (file:///home/lampam/cpp/throwaway/test-ffi)`
links to native library `ffi`

package `libffi-sys v0.6.0`
    ... which is depended on by `libffi v0.6.4`
    ... which is depended on by `mpi v0.5.4`
    ... which is depended on by `test-ffi v0.1.0 (file:///home/lampam/cpp/throwaway/test-ffi)`
also links to native library `ffi`

libffi v0.6.4 requires libffi-sys = "0.6.0" so the second package it lists ought to resolve to the semver-compatible 0.6.2-alpha.0 rather than 0.6.0.

What am I missing?

Prerelease versions can only be matched by prerelease version constraints, you’ll need to give your fork a non-alpha version number.

1 Like