Can a programmer use Rust and its packages without internet access?

Hello,

Today I was looking at the evening news and was seeing that many political commentators think that war is eminent in Ukraine, in my beloved Europe, I live in Portugal. I hope that all the parts talk things out and that war never begins. Historically wars are something that every part involved knows how to start but no part evolved in a war knows how it will end. Normally those are uncertain times. So please give humanity many years of peace, health and prosperity and not war and suffering .

But that makes me thinking about several scenarios, imagine a world without internet, a programmer as to make an income even in a war time, right? And a programmer, what he knows best is how to program. But languages like Rust, Python, Javascript and in certain ways Java, C# and C++, the normal usage of the language bring there packages/libs stuff from crates.io, npm, anaconda packages, right.

My question here is specific to Rust. Can the Rust latest versions of all packages in crates.io be easily downloadable and used from a crates.io disk copy in the case that internet is attacked and goes down?

Has the Rust language any degree of resilience, for the normal and usual programmer, against war times and war chaos?

Thank you,

Best regards,
João

Yes. The website has a page dedicated to exactly this.

Accessing the Crates.io Data

There are several ways of accessing the Crates.io data. You should try the options in the order listed.

  1. The crates.io index. This git repository is updated by crates.io, and it is used by Cargo to speed up local dependency resolution. It contains the majority of the data exposed by crates.io and is cheap to clone and get updates.
  2. The database dumps (experimental). The dump contains all information exposed by the API in a single download. It is updated every 24 hours. The latest dump is available at the address https://static.crates.io/db-dump.tar.gz. Information on using the dump is contained in the tarball. You can find the changelog for the database dumps in GitHub Issue #3617.
  3. Crawl the crates.io API. This should be used as a last resort, and doing so is subject to our crawling policy. If the index and the database dumps do not satisfy your needs, we're happy to discuss solutions that don't require you to crawl the registry. You can email us at help@crates.io.

In particular you will probably want to check out that db-dump.tar.gz link.


If you just want to download a single crate and not half the crates.io registry (which will probably get you banned/rate limited because it's rude to waste all their bandwidth), metadata for the entire crates.io registry is available on GitHub.

At the top level you'll find a config.json file with a download URL that follows this format.

When you dive into the folders you'll see a JSON file that contains dependency information and a checksum for a particular crate.

Using serde as an example, the latest version is 1.0.136 and the dl URL in config.json doesn't contain any replacement strings, therefore we can download the crate with

$ curl -L https://crates.io/api/v1/crates/serde/1.0.136/download > serde-1.0.136.crate
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100 76158  100 76158    0     0  84002      0 --:--:-- --:--:-- --:--:-- 84002

$ file serde-1.0.136.crate
serde-1.0.136.crate: gzip compressed data, was "serde-1.0.136.crate", max compression, original size modulo 2^32 525312

The *.crate file is just a gzipped tarball that we can extract.

$ tar -xvf serde-1.0.136.crate
serde-1.0.136/.cargo_vcs_info.json
serde-1.0.136/Cargo.toml
serde-1.0.136/Cargo.toml.orig
serde-1.0.136/LICENSE-APACHE
serde-1.0.136/LICENSE-MIT
serde-1.0.136/README.md
serde-1.0.136/build.rs
serde-1.0.136/crates-io.md
serde-1.0.136/src/de/format.rs
serde-1.0.136/src/de/ignored_any.rs
serde-1.0.136/src/de/impls.rs
serde-1.0.136/src/de/mod.rs
serde-1.0.136/src/de/seed.rs
serde-1.0.136/src/de/utf8.rs
serde-1.0.136/src/de/value.rs
serde-1.0.136/src/integer128.rs
serde-1.0.136/src/lib.rs
serde-1.0.136/src/macros.rs
serde-1.0.136/src/private/de.rs
serde-1.0.136/src/private/doc.rs
serde-1.0.136/src/private/mod.rs
serde-1.0.136/src/private/ser.rs
serde-1.0.136/src/private/size_hint.rs
serde-1.0.136/src/ser/fmt.rs
serde-1.0.136/src/ser/impls.rs
serde-1.0.136/src/ser/impossible.rs
serde-1.0.136/src/ser/mod.rs
serde-1.0.136/src/std_error.rs
3 Likes

Some old blog posts which might also be interesting:

https://gmjosack.github.io/posts/dissecting-cratesio-minimum-mirror/

crates-io also has a doc on setting up a mirror:

And there's a crate that claims to set up a caching mirror (downloads when-first-needed, doesn't grab everything up front):

Also, cargo vendor for a specific dependency tree.

2 Likes

Tank you both, I will study all the info that you sent me.

Best regards,
João

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.