-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Description
Problem
0.37 with --offline requires network access for build but 0.35 did not for -Z offline.
According to cargo documentation:
"Cargo, at its heart, will not attempt to access the network unless told to do so. That is, if no crates comes from crates.io, a git repository, or some other network location, Cargo will never attempt to make a network connection."
Steps
cargo new a
- add dependencies and patches to
Cargo.toml
, see sample below cargo build --offline
What happens:
error: failed to load source for a dependency on `memchr`
Caused by:
Unable to update registry `https://github.com/rust-lang/crates.io-index`
Caused by:
unable to fetch registry `https://github.com/rust-lang/crates.io-index` in offline mode
Try running without the offline flag, or try running `cargo fetch` within your project directory before going offline.
Expected:
Compiling memchr v2.2.1 (...)
Compiling a v0.1.0 (...)
Finished dev [unoptimized + debuginfo] target(s) in 2.75s
Cargo.toml
[package]
name = "a"
version = "0.1.0"
authors = ["a@localhost"]
edition = "2018"
[dependencies]
memchr = "2"
[patch.crates-io]
memchr = { path = "path/to/local/copy/of/memchr/source" }
Possible Solution(s)
The change was introduced by #6871, the simplest would be to remove the repo check in update_index
. (I use this as a workaround and everything seems to work fine.)
Or maybe propagate an "advanced usage" flag there, which would be set if e.g. there is a patch in Cargo.toml, and the set flag would prevent early termination. Or maybe even a "keep going" command line flag, which would instruct cargo to only bail out if there is an actual problem.
Notes
Output of cargo version
:
latest test with: cargo 1.36.0
from debian cago 0.37.0-3.