-
Notifications
You must be signed in to change notification settings - Fork 2.6k
cargo-0.15.0 --frozen: Why does it try to query the registry? All dependencies are available locally... #3476
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
(See also #2111 ) |
Hello and thanks for the report! This currently looks like Cargo's working as intended, but I may be able to help clarify a few pieces. You may also be interested in the offline FAQ question. Cargo does indeed support local vendoring and avoiding network requests, so you should be completely covered for your own use case. Precisely how this is done, however, is quite important. In general Cargo follows a simple policy of:
That basically means that Cargo aggressively caches projects/metadata locally as well as creates a deterministic dependency graph through the As a second point, Cargo supports first-class vendoring where you also don't have to modify So with that in mind, what's actually happening here (it looks like) is that you're working with Cargo that doesn't use source replacement and also doesn't have any caches previously. It looks like you may also not have a Here's what I would recommend for your use case:
Does that make sense? Would that work for you locally? |
Thanks for your answer! I'll read up on the matter. In my example (which is just a small proof-of-concept) libc does have a Cargo.lock , created by cargo on the libc build. c-vec, which is a small library that uses libc, doesn't have a Cargo.lock yet. What I would have expected for c-vec: Cargo looks up the dependencies' source directories (however it does that), picks up the "Cargo.lock"s there (for recursion into the dependencies) and builds c-vec. It then creates a Cargo.lock for c-vec containing all the direct and indirect dependencies so we don't have to search for them all over again (for eventual clients of c-vec). The dependencies of c-vec are listed in c-vec's Cargo.toml . It says right there what and which version it needs. Guix builds each package in a chroot so it is ensured that it can't pick up stuff it's not supposed to pick up.
I don't understand yet why it needs to fetch the registry index for anything. The dependencies are listed right in the Cargo.toml . But I guess it has to do with the fact that the dependency is a semver and the replacement is a specific version or something. I'd want to provide this semver by that directory, though. In any case, I'll try source replacement. Seems that's for replacing all the libraries at once, though. Different libraries are in different Guix packages, though. So I'd like to have something like Also, cargo-vendor has like 30 dependencies. How are we supposed to bootstrap that? Also, trying to build it manually, it failed because it can't find "cc" for compiling openssl_shim.c . That's because the compiler is called "gcc". So now I set the environment variable "CC" now. Hmm... if really necessary, we can just bind mount lots of things into each package's source tree. Icky. |
To clarify, Cargo does not use You shouldn't need to actually package up |
We are trying that now. Thanks. It seems that crates (example: https://crates.io/api/v1/crates/fs2/0.4.0/download ) don't actually contain .cargo-ok and .cargo-checksum.json - so we still have to generate them somewhen. It would be nice if they already did contain them... [also, there's a checksum of the crate file, named "package"]; but we'll just generate them when installing. Basically, we already hash packages by content and use the hash value as key to find them, and a versioning system. There's a /gnu/store directory, mounted read-only, containing all the packages in a subdirectory whose name contains the hash. There's already isolation and there's already a feature that allows the system to know what is installed (profile directories linking to the right files in the right /gnu/store directories - only for the toplevel the user actually sees. Other things in store items directly refer to other store items). We'd like not to have all this stuff again redundantly in Cargo, especially since many FFI packages require system packages anyway. On the other hand, if the user wants to use cargo to install custom packages, that should be fine, too. So cargo should somehow check what packages are already installed system-wide by the package manager (i.e. available in the profile). If they aren't yet, fine, install your own. Otherwise use the installed package. As I said, I think Cargo has to do that for the system packages (for example gtk itself etc) anyhow. Does this work? We don't have much Rust experience yet, so I'm not sure if there's something like /usr/lib/python3/site-packages for Rust. |
Hmm we are much farther now. We have a directory with all the dependencies and specify it as
The C directories contain neither a .cargo-checksum.json nor a Cargo.toml - shouldn't it have ignored these? In any case, now we seperated dependencies written in Rust from dependencies written in something else (sigh) and it's working now. Thanks for your help! That means we have a cargo-build-system in Guix. We'll package programs written in Rust real soon (tm). Do you think a local-registry approach would work too? |
@daym hm are you using |
Oh and |
Yes, we're using something like cargo vendor to create vendored directories (I just reimplemented it in Guile because I was too lazy to bootstrap cargo-vendor for this proof-of-concept :P). I'm just saying it would be even nicer if files like .cargo-checksum.json were part of the crate files - it's not like they are system-dependent or anything and it would be easier to set up a vendored directory then. I understand that there's a problem with the "package" entry self-referencing, though. About cargo local-registry: Yeah, we Guix devs have quite some discussion about whether cargo vendor or cargo local-registry should be used for our system. Are there any trade-offs? |
Vendor vs local-registry is basically up to you. One deals with source files and one deals with packed crate files. They're mostly equivalent and it just sorta depends on what you'd like to do. In theory local-registry scales better, but likely not at a point where it ever matters if the number of crates is small. |
To clarify: |
How it's going ? Were you able to integrate it ? Thanks ! |
Yes, we are using "cargo vendor"-like files with a homebrew checksum generator now in the released distribution. It works fine and makes bootstrapping from source a little less bad. Thanks! |
I'm trying to use cargo in an offline manner. For that, I'm trying to build
c-vec
usingcargo build --frozen
with the following (modified) Cargo.toml :Where /gnu/store/qi3fp02sdpc2pp3vjlv3szcvynfkwp1y-rust-libc-0.2.16/rustsrc contains: Cargo.lock Cargo.toml src/ where Cargo.toml contains:
and Cargo.lock contains:
And still it's trying to get something from crates.io:
Why?
Note that I installed a lock file manually for libc, too.
To give a little bit better overview - we're trying to integrate Rust into the Guix System Distribution. Guix has reproducible builds already so we'd rather if Cargo didn't load random things from the internet and just let us use our own packages.
For comparsion, when I allow it to query the registry, it will still not pick up the rust-libc from /gnu/store/qi3fp02sdpc2pp3vjlv3szcvynfkwp1y-rust-libc-0.2.16/rustsrc but rather the one from crates.io . I can't find out why using the debugging log above.
strace shows: When I use --frozen, it never tries to access /gnu/store/qi3fp02sdpc2pp3vjlv3szcvynfkwp1y-rust-libc-0.2.16/rustsrc . When I don't use --frozen it does access /gnu/store/qi3fp02sdpc2pp3vjlv3szcvynfkwp1y-rust-libc-0.2.16/rustsrc/src/lib.rs successfully.
So I'd say it's checking the replacements too late - among other things.
How can I debug this further?
The text was updated successfully, but these errors were encountered: