Skip to content

cargo requires network acces for build when it should not #7582

@iu0zjp2

Description

@iu0zjp2

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

  1. cargo new a
  2. add dependencies and patches to Cargo.toml, see sample below
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-networkingArea: networking issues, curl, etc.C-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions