-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Description
Problem
Actual behavior: running cargo metadata --offline
in a dependency of the primary crate tries to access the Internet. If the host has no access, this fails with a network error.
Expected behavior: cargo metadata --offline
does not attempt to access the Internet & returns a limited set of fields that can be calculated offline.
Weird complicating factor: if the crate in question is vendored as a path dependency, cargo metadata
works without the --offline switch
.
Error example
error: proc macro panicked
--> C:\Users\some_user\.cargo\registry\src\-b20c50870c528e96\windows-0.3.1\build.rs:2:5
2 | windows_macros::build!();
| ^^^^^^^^^^^^^^^^^^^^^^^^^
= help: message: Cargo metadata \\?\C:\src\.rustup\toolchains\stable-x86_64-pc-windows-msvc\bin\cargo.exe did not contain `workspace_root` key. Got stdout . Got stderr
Updating crates.io index
warning: spurious network error (2 tries remaining): failed to send request: The server name or address could not be resolved
; class=Os (2)
warning: spurious network error (1 tries remaining): failed to send request: The server name or address could not be resolved
; class=Os (2)
error: failed to get `const-sha1` as a dependency of package `windows v0.3.1 (C:\Users\some_user\.cargo\registry\src\-b20c50870c528e96\windows-0.3.1)`
Caused by:
failed to load source for dependency `const-sha1`
Caused by:
Unable to update registry `https://github.com/rust-lang/crates.io-index`
Caused by:
failed to fetch `https://github.com/rust-lang/crates.io-index`
Caused by:
failed to send request: The server name or address could not be resolved
; class=Os (2)
.
Ran from "C:\\Users\\some_user\\.cargo\\registry\\src\\-b20c50870c528e96\\windows-0.3.1"
error: aborting due to previous error
Steps
- Create a binary crate
C
that depends onwindows-rs
. - Use
cargo local-registry
to create a local registry forC
's dependencies. - Try to build
C
with the local registry replacingcrates.io
, and no Internet access. The build should fail with a cryptic error from thewindows-rs
build. To reproduce the error message I have above, modifying this line inside the local registry's copy ofwindows_winmd
crate. There is almost certainly a simpler repro, but I suspect an exact repro won't be strictly necessary to address this bug.
Possible Solution(s)
When we make windows-rs
a path dependency, it allows cargo metadata
to run in that crate without errors while offline. Whatever this code path is, can do the same thing in the local registry case? My suspicion is that C
's lockfile somehow applies to the cargo metadata
command when windows-rs
is a path dependency.
Notes
Output of cargo version
:
> cargo version
cargo 1.48.0 (65cbdd2dc 2020-10-14)