Skip to content
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 support for -Zbuild-std to cargo fetch #10129

Merged
merged 1 commit into from
May 4, 2022

Conversation

jyn514
Copy link
Member

@jyn514 jyn514 commented Nov 27, 2021

This allows downloading the dependencies for libstd in advance, which
can be useful in e.g. sandboxed build environments.

Fixes rust-lang/wg-cargo-std-aware#22.

r? @ehuss

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 27, 2021
src/cargo/ops/cargo_fetch.rs Outdated Show resolved Hide resolved
Comment on lines 83 to 73
// Fetch the dependencies for `test` just in case
// (cargo could later decide to build libtest even if it wasn't specified in the flags)
to_download.push(std_resolve.query("test")?);
packages.add_set(std_package_set);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was very non-trivial to try and figure out whether test would be necessary ahead of time. (I think it may not even be possible to tell since you need to know whether cargo is checking or building?)

@jyn514
Copy link
Member Author

jyn514 commented Nov 27, 2021

I'd like to test that build -Zbuild-std doesn't download anything if you've previously run fetch, but that takes a very long time to execute because it's building the whole standard library ... is there a way to cut it off after I see the first "Building" line maybe?

@jyn514
Copy link
Member Author

jyn514 commented Nov 27, 2021

Ah, I think testsuite/standard_lib.rs is what I want :)

src/cargo/ops/cargo_fetch.rs Outdated Show resolved Hide resolved
src/cargo/ops/cargo_fetch.rs Outdated Show resolved Hide resolved
src/cargo/ops/cargo_fetch.rs Outdated Show resolved Hide resolved
src/cargo/ops/cargo_fetch.rs Outdated Show resolved Hide resolved
// easy to get the host triple in BuildConfig. Consider changing
// requested_target to an enum, or some other approach.
anyhow::bail!("-Zbuild-std requires --target");
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't delete this, it's here for a reason. The -Zbuild-std unit graph is not correct unless --target is passed and a lot more is needed to get this working without it. Simply because the test suite doesn't fail doesn't mean this can be deleted.

src/cargo/ops/cargo_fetch.rs Outdated Show resolved Hide resolved
@alexcrichton
Copy link
Member

Following up on this, I continue to believe that the hardcoding of "test" should be shared between cargo build and cargo fetch one way or another. I think that the functionality can be shared between the two code paths.

@alexcrichton alexcrichton added S-waiting-on-author Status: The marked PR is awaiting some action (such as code changes) from the PR author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 14, 2021
@jyn514
Copy link
Member Author

jyn514 commented Feb 14, 2022

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: The marked PR is awaiting some action (such as code changes) from the PR author. labels Feb 14, 2022
@jyn514
Copy link
Member Author

jyn514 commented Apr 5, 2022

I tried to address Alex's concerns.

@jyn514 jyn514 force-pushed the fetch-build-std branch 2 times, most recently from 6e2c001 to 56c4f7c Compare April 5, 2022 00:12
Copy link
Member

@weihanglo weihanglo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am trying to pick this up without Alex help 🥲
So far as I read the conversation, it seems that you've resolved Alex's concerns. Thanks for the help!

src/cargo/core/compiler/build_config.rs Outdated Show resolved Hide resolved
src/cargo/core/compiler/standard_lib.rs Show resolved Hide resolved
@weihanglo
Copy link
Member

Could you squash some old commits? It may confuse people when tracing the history. Thanks!

This allows downloading the dependencies for libstd in advance, which
can be useful in e.g. sandboxed build environments.

- Abstract check for `--target` out into a function
- Try to abstract `test` special-casing into a function

  This avoids hard-coding crate names in multiple places.

- Unify handling of checks for `--target` in `BuildConfig::new`

  This makes sure it's checked consistently, without requiring each new command to check it explicitly.

- Share more code between `fetch` and `build` by adding `std_crates()`
- Warn about `--build-plan` and `-Zbuild-std` consistently, not just for `build`

  Currently only `build` uses build-plan. But cargo may choose to add it to new commands in the future (e.g. check and doc).
  Future-proof it, since it's simple to do.
@weihanglo
Copy link
Member

Looks good to go. Thanks!

@bors r+

@bors
Copy link
Collaborator

bors commented May 4, 2022

📌 Commit 55b680c has been approved by weihanglo

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 4, 2022
@bors
Copy link
Collaborator

bors commented May 4, 2022

⌛ Testing commit 55b680c with merge a44758a...

@bors
Copy link
Collaborator

bors commented May 4, 2022

☀️ Test successful - checks-actions
Approved by: weihanglo
Pushing a44758a to master...

@bors bors merged commit a44758a into rust-lang:master May 4, 2022
@jyn514 jyn514 deleted the fetch-build-std branch May 4, 2022 04:39
bors added a commit to rust-lang-ci/rust that referenced this pull request May 4, 2022
Update cargo

7 commits in f63f23ff1f1a12ede8585bbd1bbf0c536e50293d..a44758ac805600edbb6ba51e7e6fb81a6077c0cd
2022-04-28 03:15:50 +0000 to 2022-05-04 02:29:34 +0000
- Add support for `-Zbuild-std` to `cargo fetch` (rust-lang/cargo#10129)
- Migrate tests of `cargo-init` to snapbox (rust-lang/cargo#10620)
- dedupe toml_edit crate, followup rust-lang/cargo#10603 (rust-lang/cargo#10619)
- Update GitHub Actions actions/checkout@v2 to v3 (rust-lang/cargo#10618)
- Integrate snapbox in with cargo-test-support (rust-lang/cargo#10581)
- Fix zsh completion (rust-lang/cargo#10613)
- Update documentation for workspace inheritance (rust-lang/cargo#10611)
@ehuss ehuss added this to the 1.62.0 milestone May 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support cargo fetch
7 participants