`cargo vendor` and `-Zbuild-std` don't work together?

I have a crate that only depends on libc and core (no std or alloc). Cargo.lock looks like this:

# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3

[[package]]
name = "libc"
version = "0.2.81"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1482821306169ec4d07f6aca392a4681f66c75c9918aa49641a2595db64053cb"

[[package]]
name = <my package>
version = "0.1.0"
dependencies = [
 "libc",
]

I need to build this crate without downloading any crates. This is currently possible using a rustc with the "src" component, cargo vendor, and Xargo.

However I'm currently trying to ditch Xargo for -Zbuild-std, and I'm unable to make it work. I'm not sure what exactly is the problem, but there are a few things that I think may be a part of the problem:

  • cargo vendor doesn't seem to support -Zbuild-std. I tried: cargo vendor -Zbuild-std, which doesn't create core/alloc/std dependencies, cargo vendor -- -Zbuild-std creates the crate in "-Zbuild-std" directory. So it seems like there is no way to include core/alloc/std dependencies in the vendor directory.

  • cargo build -Z build-std=core seems to look for crates that are not really a dependency for core. For example, I'm getting error: no matching package named `getopts` found error even though getopts doesn't seem to be a dependency of core: rust/Cargo.toml at master · rust-lang/rust · GitHub

Is there a way to make this work? Basically I want cargo vendor to also unpack dependencies of core/std/alloc depending on which one of those I need. Currently in my case I only care about core.

core/alloc/std only work for a single rustc version. While the sources of core, alloc and std are already available offline as part of the rust-src component, there are some dependencies from crates.io. This should be solved by vendoring those as part of the rust-src component, not as part of the user project. I believe there is already an issue for this, but I can't find it.

Interesting, thanks. I also searched for it on GitHub but couldn't find anything relevant. If anyone knows the issue and could drop a link that would be appreciated :slight_smile:

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.