Unable to patch libc dependency when working on std

I'm working on adding std support for a couple of new rustc targets. The support in std depends on changes to libc, so I'm trying to patch the version of libc used in the std build to point to my local checkout of libc. I'm following the patch instructions described in the rustc development guide, however the std build seems to be ignoring this patch and not using it.

In the root Cargo.toml in my rust checkout I have:

[patch.crates-io]
libc = { path = "../libc" }

However when the code compiles I can tell it's still using the crates.io version of libc because it's missing the new platform bindings that I added. When I look in the Cargo.lock file I see

[[patch.unused]]
name = "libc"
version = "0.2.160"

Which I take to mean that it's not using the patched version of libc. Can anyone help me understand what's going wrong here? I already made sure that the patch version is greater than the crates.io version, since that seems to matter when patching.

Does it work if you patch library/Cargo.toml instead? The standard library has its own lockfile now.

Moving the patch to library/Cargo.toml doesn't work (the patch is still showing up as unused), but I do get a warning about it now:

warning: Patch `libc v0.2.160 (/home/legare/libc)` was not used in the crate graph.
Check that the patched package version and available features are compatible
with the dependency requirements. If the patch has a different version from
what is locked in the Cargo.lock file, run `cargo update` to use the new
version. This may also occur with an optional dependency that is not enabled.

I'm not sure how to resolve this now. The warning isn't super clear about why exactly the patched version of libc is not compatible. Is there a way to find out the specific reason?

Did you do that? It looks like the current library/Cargo.lock has 0.2.158, so you need to update it.

Huh, I thought I had, but I tried deleting Cargo.lock and re-running the build and now it seems to be using the correct version. So seems like moving the patch into library/Cargo.toml did the trick. Thanks!

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.