-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Add a flag to force network access to be an error #2811
Conversation
@alexcrichton: no appropriate reviewer found, use r? to override |
r? @wycats |
f3480bd
to
52c5310
Compare
Ok, after some more dicussions with @wycats today this PR has now been modified with the addition of two new flags to Cargo:
The idea here is to follow in Bundler's footsteps in these flags. You don't actually want to only assert that no network access happens, but rather crates want an assertion that nothing changes and Cargo just builds crates. That's why the Eventually, we're also thinking that a Also note that I've added an entry to the FAQ about "How can Cargo work offline?". This is a tricky topic, so I'd appreciate review of that as well! (cc @steveklabnik) |
hence the request for Cargo to work offline comes up frequently. | ||
|
||
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might be nice to link this; just needs []
around it.
The overall strategy here sounds good. I'm a bit unsure about the flag names, they are not intuitive to me are they inherited from somewhere? If not, then I'd suggest |
@nrc yeah currently these names come from Bundler, but they're not perhaps the most appropriate. It may be beneficial to tie up semantic ideas in the flags though rather than specifically what they do in case we want to extend their functionality in the future. |
r? @brson |
☔ The latest upstream changes (presumably #2867) made this pull request unmergeable. Please resolve the merge conflicts. |
52c5310
to
8f803af
Compare
☔ The latest upstream changes (presumably #2849) made this pull request unmergeable. Please resolve the merge conflicts. |
8f803af
to
d7235da
Compare
If a lock file is generated and some equivalent of `cargo fetch` is run then Cargo shouldn't ever touch the network or modify `Cargo.lock` until any `Cargo.toml` later changes, but this often wants to be asserted in some build environments where it's a programmer error if Cargo attempts to access the network. The `--locked` flag added here will assert that `Cargo.lock` does not need to change to proceed. That is, if `Cargo.lock` would be modified (as it automatically is by default) this is turned into a hard error instead. This `--frozen` will not only assert that `Cargo.lock` doesn't change (the same behavior as `--locked`), but it will also will manually prevent Cargo from touching the network by ensuring that all network requests return an error. These flags can be used in environments where it is *expected* that no network access happens (or no lockfile changes happen) because it has been pre-arranged for Cargo to not happen. Examples of this include: * CI for projects want to pass `--locked` to ensure that `Cargo.lock` is up to date before changes are checked in. * Environments with vendored dependencies want to pass `--frozen` as touching the network indicates a programmer error that something wasn't vendored correctly. A crucial property of these two flags is that **they do not change the behavior of Cargo**. They are simply assertions at a few locations in Cargo to ensure that actions expected to not happen indeed don't happen. Some documentation has also been added to this effect. Closes rust-lang#2111
d7235da
to
a504f48
Compare
@nrc @alexcrichton the names aren't exactly taken from bundler, but they're loosely inspired by bundler. The idea is:
In other words, "locked" and "frozen" are states a Cargo directory can be in, and |
@nrc although they are similar they're also doing relatively similar things under the hood, and I was unable to think of some better names. Do you feel ok moving forward with these flag names? |
Yeah, I'm ok with moving forward here. I like @wycats' point that |
Ok cool, in that case, ping r? @brson |
One request before this goes in: since |
@joshtriplett isn't that just |
Put another way, |
@alexcrichton No, I'd like to run Of course, given the existence of crates that actually fetch from the network in their |
@joshtriplett given that the motivation is for packagers, I think that we'll want to have a more dedicated discussion or RFC towards that use case to ensure we've fleshed out everything. We can of course always add more flags to Cargo! |
@alexcrichton @joshtriplett Can you open up an issue on the RFC repo to help flesh out the "motivation" section for a packager RFC? I'd like to fully enumerate the requirements in detail and then move on to a detailed proposal. When doing this, please focus on the underlying motivations rather than the top level requirements (e.g. try to explain why hitting the network is verboten; if the answer is a requirement of a build bot, fleshing out the details of how the build bots work and why they require what they require would be very useful). |
Generally speaking, everything needed to build distro packages should be contained in the distro. If you have to reach a network resource to complete a build, it's clearly not self-contained. |
I also think @joshtriplett's case is important. I've definitely hit cases where I changed the dependencies, but knew the entire graph could be already be solved with cached local deps, but was stuck on an airplane and could not proceed. |
The various flags proposed in this PR assert that you won't need to hit the network. In general, if you don't need to hit the network but end up blocked on proceeding due to the lack of network that is a bug in Cargo. it is important to me and @alexcrichton that this is true. The most common source of this kind of bug is problems with the override feature, which we're in the process of reforming and replacing. |
📌 Commit a504f48 has been approved by |
Add a flag to force network access to be an error If a lock file is generated and some equivalent of `cargo fetch` is run then Cargo shouldn't ever touch the network or modify `Cargo.lock` until any `Cargo.toml` later changes, but this often wants to be asserted in some build environments where it's a programmer error if Cargo attempts to access the network. The `--locked` flag added here will assert that `Cargo.lock` does not need to change to proceed. That is, if `Cargo.lock` would be modified (as it automatically is by default) this is turned into a hard error instead. This `--frozen` will not only assert that `Cargo.lock` doesn't change (the same behavior as `--locked`), but it will also will manually prevent Cargo from touching the network by ensuring that all network requests return an error. These flags can be used in environments where it is *expected* that no network access happens (or no lockfile changes happen) because it has been pre-arranged for Cargo to not happen. Examples of this include: * CI for projects want to pass `--locked` to ensure that `Cargo.lock` is up to date before changes are checked in. * Environments with vendored dependencies want to pass `--frozen` as touching the network indicates a programmer error that something wasn't vendored correctly. A crucial property of these two flags is that **they do not change the behavior of Cargo**. They are simply assertions at a few locations in Cargo to ensure that actions expected to not happen indeed don't happen. Some documentation has also been added to this effect. Closes #2111
☀️ Test successful - cargo-cross-linux, cargo-linux-32, cargo-linux-64, cargo-mac-32, cargo-mac-64, cargo-win-gnu-32, cargo-win-gnu-64, cargo-win-msvc-32, cargo-win-msvc-64 |
If a lock file is generated and some equivalent of
cargo fetch
is run thenCargo shouldn't ever touch the network or modify
Cargo.lock
until anyCargo.toml
later changes, but this often wants to be asserted in some buildenvironments where it's a programmer error if Cargo attempts to access the
network.
The
--locked
flag added here will assert thatCargo.lock
does not need tochange to proceed. That is, if
Cargo.lock
would be modified (as itautomatically is by default) this is turned into a hard error instead.
This
--frozen
will not only assert thatCargo.lock
doesn't change (the samebehavior as
--locked
), but it will also will manually prevent Cargo fromtouching the network by ensuring that all network requests return an error.
These flags can be used in environments where it is expected that no network
access happens (or no lockfile changes happen) because it has been pre-arranged
for Cargo to not happen. Examples of this include:
--locked
to ensure thatCargo.lock
is up todate before changes are checked in.
--frozen
as touchingthe network indicates a programmer error that something wasn't vendored
correctly.
A crucial property of these two flags is that they do not change the behavior
of Cargo. They are simply assertions at a few locations in Cargo to ensure
that actions expected to not happen indeed don't happen. Some documentation has
also been added to this effect.
Closes #2111