Commit graph

12399 commits

Author SHA1 Message Date
Arlo Siemsen 8a1f4011a2 Refactor check_yanked to avoid some duplication 2022-07-08 13:31:11 -05:00
bors 686727775c Auto merge of #10831 - arlosi:sparse-publish-fix, r=Eh2406
Fix publishing to crates.io with -Z sparse-registry

Attempting to publish a crate to crates.io with `-Z sparse-registry` failed with the following error:

```
error: failed to publish to registry at https://crates.io

Caused by:
  the remote server responded with an error: Dependency `serde` is hosted on another registry. Cross-registry dependencies are not permitted on crates.io.
```

The check in `registry.rs` `dep_registry_id != registry_id` caused the `publish` operation include the crates.io index url in the HTTP request because the id was replaced. The crates.io API seems to require that the `registry` field is not present.

This change fixes the issue by making the `registry` function return the non-replaced crates.io `source_id` only for this case. Other replacement indices of crates.io continue to include the registry URL when publishing.

Tested manually by publishing `arlosi-cargo-test` to crates.io with `-Z sparse-registry`

Fixes #10828
r? `@Eh2406`
2022-07-07 18:05:08 +00:00
bors bc28260320 Auto merge of #10830 - arlosi:parallel_yank, r=Eh2406
Make `is_yanked` return `Poll<>`

The `is_yanked` check performed by `cargo install` and `cargo package` was running sequentially (calling `block_until_ready` after every check).

This change makes `is_yanked` return `Poll<>` and runs the check in parallel, which gives better performance for `cargo install --locked` and `cargo package` when using a sparse registry.

fixes #10821
r? `@ehuss`
2022-07-07 14:55:56 +00:00
bors 9c4bae65b7 Auto merge of #10829 - ehuss:corrupted-checkout, r=weihanglo
Fix corrupted git checkout recovery.

This fixes an issue where cargo would not recover from a corrupted git checkout correctly when using `net.git-fetch-with-cli`.

Git dependencies have two clones, the "db" and the "checkout". The "db" is shared amongst multiple checkout revisions from the same repository. The "checkout" is each individual revision. There was some code in `copy_to` which creates the "checkout" that tries to recover from an error. The "checkout" can be invalid if cargo was interrupted while cloning it, or if there is fs corruption. However, that code was failing when using the git CLI.  For reasons I did not dig into, the "db" does not have a HEAD ref, so that special-case fetch was failing with a `couldn't find remote ref HEAD` error from `git`.

This changes it so that if the "checkout" is invalid, it just gets blown away and a new clone is created (instead of calling `git fetch` from the "db").

I believe there is some long history for this `copy_to` code where it made more sense in the past. Previously, the "checkout" directories used the `GitReference` string as-is. So, for example, a branch would checkout into a directory with that branch name. At some point, it was changed so that each checkout uses a short hash of the actual revision.  Rebuilding the checkout made sense when it was possible for that checkout revision to change (like if new commits were pushed to a branch).  That recovery is no longer necessary since a checkout is only ever one revision.

Fixes #10826
2022-07-06 22:26:17 +00:00
Arlo Siemsen 132afd3f1b Fix publishing to crates.io with -Z sparse-registry 2022-07-06 14:20:59 -05:00
Arlo Siemsen 72ed97bffa Run the is_yanked check in parallel for better performance with -Z sparse-registry 2022-07-06 12:48:59 -05:00
Eric Huss c46e57b0cf Fix corrupted git checkout recovery. 2022-07-05 21:02:08 -07:00
bors ca190acce0 Auto merge of #10776 - Muscraft:cache-workspace-discovery, r=weihanglo
add a cache for discovered workspace roots

## History
`@ehuss` [noticed that](https://github.com/rust-lang/cargo/pull/10736#discussion_r894071933) workspace inheritance caused a significant increase in startup times when using workspace inheritance. This brought up the creation of #10747.

When using a similar test setup [to the original](https://github.com/rust-lang/cargo/pull/10736#discussion_r894822022) I got
```
Benchmark 1: cd rust; ../../../target/release/cargo metadata
  Time (mean ± σ):     149.4 ms ±   3.8 ms    [User: 105.9 ms, System: 31.7 ms]
  Range (min … max):   144.2 ms … 162.2 ms    19 runs

Benchmark 2: cd rust-ws-inherit; ../../../target/release/cargo metadata
  Time (mean ± σ):     191.6 ms ±   1.4 ms    [User: 145.9 ms, System: 34.2 ms]
  Range (min … max):   188.8 ms … 193.9 ms    15 runs
```

This showed a large increase in time per cargo command when using workspace inheritance.

During the investigation of this issue, other [performance concerns were found and addressed](https://github.com/rust-lang/cargo/pull/10761). This resulted in a drop in time across the board but heavily favored workspace inheritance.
```
Benchmark 1: cd rust; ../../../target/release/cargo metadata
  Time (mean ± σ):     139.3 ms ±   1.7 ms    [User: 99.8 ms, System: 29.4 ms]
  Range (min … max):   137.1 ms … 144.5 ms    20 runs

Benchmark 2: cd rust-ws-inherit; ../../../target/release/cargo metadata
  Time (mean ± σ):     161.7 ms ±   1.4 ms    [User: 120.4 ms, System: 31.2 ms]
  Range (min … max):   158.0 ms … 164.6 ms    18 runs
```

## Performance after changes
`hyperfine --warmup 10 "cd rust; ../../../target/release/cargo metadata" "cd rust-ws-inherit; ../../../target/release/cargo metadata" --runs 40`
```
Benchmark 1: cd rust; ../../../target/release/cargo metadata
  Time (mean ± σ):     140.1 ms ±   1.5 ms    [User: 99.5 ms, System: 30.7 ms]
  Range (min … max):   137.4 ms … 144.0 ms    40 runs

Benchmark 2: cd rust-ws-inherit; ../../../target/release/cargo metadata
  Time (mean ± σ):     141.8 ms ±   1.6 ms    [User: 100.9 ms, System: 30.9 ms]
  Range (min … max):   138.4 ms … 145.4 ms    40 runs
```

[New Benchmark](https://github.com/rust-lang/cargo/pull/10754)
`cargo bench -- workspace_initialization/rust`
```
workspace_initialization/rust
    time:   [14.779 ms 14.880 ms 14.997 ms]
workspace_initialization/rust-ws-inherit
    time:   [16.235 ms 16.293 ms 16.359 ms]
```

## Changes Made
- [Pulled a commit](bbd41a4dca) from `@ehuss` that deduplicated finding a workspace root to make the changes easier
- Added a cache in `Config` to hold found `WorkspaceRootConfig`s
  - This makes it so manifests should only be parsed once
- Made `WorkspaceRootConfig` get added to the cache when parsing a manifest

## Testing Steps
To check the new benchmark:
1. `cd benches/benchsuite`
2. `cargo bench -- workspace_initialization/rust`

Using `hyperfine`:
1. run `cargo build --release`
2. extract `rust` and `rust-ws-inherit` in `benches/workspaces`
3. cd `benches/workspaces`
4. Prime the target directory with a cache of `rustc` info. In `rust` and `rust-ws-inherit`, run: `cargo +nightly c -p linkchecker`. Otherwise it would be measuring `rustc` overhead.
4. run `hyperfine --warmup 10 "cd rust; ../../../target/release/cargo metadata" "cd rust-ws-inherit; ../../../target/release/cargo metadata" --runs 40`

closes #10747
2022-07-05 21:47:59 +00:00
Scott Schafer fd8bcf9bde add a cache for discovered workspace roots 2022-07-05 09:54:27 -05:00
bors c0bbd42ce5 Auto merge of #10818 - Byron:flyby-fixes, r=weihanglo
fix typo
2022-07-03 13:41:11 +00:00
bors f2c52767ad Auto merge of #10817 - epage:fix, r=weihanglo
fix(add): Don't panic with `--offline`

For some reason, I defined my own `--offline` flag and it didn't get
updated with the global `--offline` flag, so it started failing.

The new test previously paniced and now it doesn't.

Fixes #10814
2022-07-03 05:41:45 +00:00
Ed Page 18f7dfe0f5 fix(add): Don't panic with --offline
For some reason, I defined my own `--offline` flag and it didn't get
updated with the global `--offline` flag, so it started failing.

Fixes #10814
2022-07-02 23:04:00 -05:00
bors 64c803f0ec Auto merge of #10816 - turrisxyz:Pinned-Dependencies-GitHub, r=epage
chore: Set permissions for GitHub actions

 Restrict the GitHub token permissions only to the required ones; this way, even if the attackers will succeed in compromising your workflow, they won’t be able to do much.

- Included permissions for the action. https://github.com/ossf/scorecard/blob/main/docs/checks.md#token-permissions

https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#permissions

https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs

[Keeping your GitHub Actions and workflows secure Part 1: Preventing pwn requests](https://securitylab.github.com/research/github-actions-preventing-pwn-requests/)

Signed-off-by: naveen <172697+naveensrinivasan@users.noreply.github.com>
2022-07-03 03:45:05 +00:00
naveen a4ac0438a2 chore: Set permissions for GitHub actions
Restrict the GitHub token permissions only to the required ones; this way, even if the attackers will succeed in compromising your workflow, they won’t be able to do much.

- Included permissions for the action. https://github.com/ossf/scorecard/blob/main/docs/checks.md#token-permissions

https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#permissions

https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs

[Keeping your GitHub Actions and workflows secure Part 1: Preventing pwn requests](https://securitylab.github.com/research/github-actions-preventing-pwn-requests/)

Signed-off-by: naveen <172697+naveensrinivasan@users.noreply.github.com>
2022-07-03 00:31:05 +00:00
Sebastian Thiel 5bed4e8758
fix typo 2022-07-02 12:52:24 +08:00
bors 2aa12cbb92 Auto merge of #10812 - ehuss:version-bump, r=Eh2406
Bump to 0.65.0, update changelog
2022-07-01 19:33:33 +00:00
Eric Huss 77aebb5024 Update changelog for 1.63 2022-07-01 12:26:12 -07:00
Eric Huss fa39fd4cd9 Bump to 0.65.0 2022-07-01 11:43:25 -07:00
bors cf26c4aed3 Auto merge of #10810 - Diomendius:bugfix-zsh-completions, r=weihanglo
Fix zsh completions for add and locate-project

Currently, trying to tab-complete either the `cargo add` or `cargo locate-project` subcommands results in output such as this:
```
cargo add _cargo:67: command not found: --default-features[enable the default features]
_cargo:68: command not found: --no-default-features[don't enable the default features]
_cargo:69: command not found: --optional[mark the dependency as optional]
```

This is because some line continuations are missing from `src/etc/_cargo`. This PR adds these line continuations.

This file gets packaged for Rust releases by acdcdfb61b/src/bootstrap/dist.rs (L956) and Rustup ultimately places it in `~/.rustup/toolchains/*/share/zsh/site-functions/_cargo`. `rustup completions zsh cargo` outputs a script which sources this filepath.

The easier approach to testing this is probably to manually copy `_cargo` to its proper location under `~/.rustup`, assuming Rust is already installed via Rustup and Zsh completions for Cargo are already installed, but however you choose to install this, testing is as simple as observing that Zsh can correctly tab complete `cargo add` and `cargo locate-project`.
2022-07-01 08:14:18 +00:00
Diomendius f44e2b5053 Fix zsh completions for add and locate-project
The zsh tab-completion script had missing line continuations which would
cause `command not found:` errors when trying to complete the
`cargo add` or `cargo locate-project` subcommands.
2022-07-01 17:12:09 +12:00
bors 501b56b26e Auto merge of #10804 - ehuss:bump-cargo-util, r=joshtriplett
Bump cargo-util version.

#10546 made a semver-incompatible change to the API of `ProcessBuilder::get_args`. Unfortunately we did not catch that until it was published. This bumps the version of cargo-util to 0.2.1 to accommodate that change. Stable will get version 0.2.0 so that the changes on beta can be released as 0.2.1 in their own time.

cc #10803
2022-07-01 04:21:25 +00:00
bors 6a83e04fc3 Auto merge of #10802 - ehuss:update-os_info, r=epage
Update os_info

This updates os_info which has had a number of improvements for detecting more platforms.

Changelog: https://github.com/stanislav-tkach/os_info/blob/master/CHANGELOG.md
Changes: https://github.com/stanislav-tkach/os_info/compare/v3.0.7...v3.4.0

Fixes #10800
2022-07-01 03:36:07 +00:00
Eric Huss 41ac6078aa Bump cargo-util version. 2022-06-30 14:25:28 -07:00
Eric Huss 72320bdcca Update os_info 2022-06-30 14:00:23 -07:00
bors 42311063f0 Auto merge of #10799 - Urgau:check-cfg-fix-config-deserialization, r=ehuss
Fix deserialization of check-cfg in config.toml

When improving the check-cfg implementation in https://github.com/rust-lang/cargo/pull/10566 I changed the internal representation of `check_cfg` from multiple `bool` options to one `Option<(bool, bool, bool, bool)>` but I didn't realize until https://github.com/rust-lang/rust/issues/82450#issuecomment-1169836928 that the internal representation is actually somewhat public as it's used in the `[unstable]` in `.cargo/config.toml`.

And because TOML cannot represent tuples there is no way to set it from the `[unstable]` section. This PR fix this oversight by using a custom deserializer method similar to what was already done for `build-std`.
2022-06-29 22:13:09 +00:00
bors a3ae66804c Auto merge of #10798 - scop:patch-1, r=ehuss
fix: bash complete `install --path` with dirs

`--path` takes a mandatory dir argument.
2022-06-29 21:24:58 +00:00
Urgau 23f59d4eeb Add regression tests for check-cfg unstable config 2022-06-29 14:52:20 +02:00
Urgau c08a666a24 Fix config deserilization of check-cfg 2022-06-29 14:16:36 +02:00
Ville Skyttä ca08dadff6
feat: bash complete install --path with dirs 2022-06-29 10:31:18 +03:00
bors dbff32b278 Auto merge of #10079 - dtolnay-contrib:fetch, r=ehuss
Fetch GitHub commits by long hash more efficiently

Closes #10078.

**Tested with the following Cargo.toml:**

```toml
[package]
name = "repro"
version = "0.0.0"
edition = "2021"
publish = false

[dependencies]
cargo = { git = "https://github.com/rust-lang/cargo", rev = "b30694b4d9b29141298870b7993e9aee10940524" }
```

```console
$ rm -rf ~/.cargo/git/db/cargo-* ~/.cargo/git/checkouts/cargo-*
$ time $CARGO generate-lockfile
$ du -shc ~/.cargo/git/db/cargo-* ~/.cargo/git/checkouts/cargo-*
```

Using current cargo from the most recent nightly, the `generate-lockfile` command downloads 69704 git objects in 7.0 seconds, consuming 41 MB on disk.

Using cargo built from this PR by `cargo build --release`, the same command downloads 21481 objects in 2.2 seconds, consuming 17 MB on disk.

Once libgit2 is able to do shallow clones (https://github.com/libgit2/libgit2/issues/3058) this can be even more of a speedup. Using command-line git (which does not use libgit2) and `time git fetch --depth=1 https://github.com/rust-lang/cargo b30694b4d9b29141298870b7993e9aee10940524` indicates that it downloads just 262 objects in 1.1 seconds.
2022-06-24 19:25:13 +00:00
bors 47620e2060 Auto merge of #10778 - epage:test, r=ehuss
refactor(test): Clarify asserts are for UI

In writing the contrib documentation for functional vs ui tests, I
realized that as we work to make snapbox work for the functional tests,
we'll need distinct `Assert` objects since we'll want to elide a lot
more content in functional tests.  I'm making room for this by
qualifying the existing asserts as being for "ui".
2022-06-24 18:27:15 +00:00
bors a5e08c4703 Auto merge of #10785 - ehuss:fix-dead_code-diag, r=Eh2406
Fix tests due to change in dead_code diagnostic.

https://github.com/rust-lang/rust/pull/97853 changed some diagnostics which is causing some tests to fail on the latest nightly.  This updates the tests to work on both stable and nightly.
2022-06-23 20:12:03 +00:00
Eric Huss 502a9c5407 Fix tests due to change in dead_code diagnostic. 2022-06-23 13:08:08 -07:00
bors ed549d8717 Auto merge of #10755 - jonhoo:stabilize-config-cli, r=ehuss
Stabilize config-cli

This stabilizes the `--config` CLI argument as per [this FCP](https://github.com/rust-lang/cargo/issues/7722#issuecomment-1114369809).

It also makes the adjustment [suggested by `@ehuss](https://github.com/rust-lang/cargo/issues/7722#issuecomment-1098612205)` to allow stabilizing `--config path` without _also_ stabilizing [`config-include`](https://doc.rust-lang.org/cargo/reference/unstable.html#config-include).

I took a guess that this would land in 1.63 and put that in the tombstone entry in the unstable docs, but let me know if that's likely to be wrong.

Closes https://github.com/rust-lang/cargo/issues/7722.

Also, I think this should probably be tagged `relnotes`.
2022-06-22 20:02:24 +00:00
Ed Page cbd4edb266 refactor(test): Clarify asserts are for UI
In writing the contrib documentation for functional vs ui tests, I
realized that as we work to make snapbox work for the functional tests,
we'll need distinct `Assert` objects since we'll want to elide a lot
more content in functional tests.  I'm making room for this by
qualifying the existing asserts as being for "ui".
2022-06-21 14:59:54 -05:00
Jon Gjengset 7eefb4221f Include --config in cargo help output 2022-06-21 16:24:41 +00:00
Jon Gjengset 0ecdde53eb Don't refer to --config as unstable 2022-06-21 16:07:49 +00:00
bors c9d8c28cba Auto merge of #10767 - danilhendrasr:master, r=epage
Restrict duplicate deps warning only to published packages

Fixes #10752
2022-06-21 01:37:37 +00:00
Danil Hendra Suryawan 08d10184aa Restrict duplicate deps warning only to published packages 2022-06-21 00:28:25 +00:00
David Tolnay 7da3c360bc
Fetch GitHub commits by long hash more efficiently 2022-06-20 16:47:32 -07:00
bors 5db8295f92 Auto merge of #10746 - shkoo:nils/custom_target_path_cache, r=weihanglo
Use fingerprint_hash when computing fingerprints for custom targets

This makes it easier to get reproducible builds for custom targets.
2022-06-20 22:56:09 +00:00
Eric Huss 971caf5df6 Rework how workspace roots are discovered.
This centralizes the workspace discovery code into one location
`find_workspace_root_with_loader` so that it isn't duplicated.
2022-06-20 12:51:52 -05:00
Josh Triplett da5f35d950
Merge pull request #10761 from Muscraft/reduce-parsing
Add preloading for workspace packages in `resolve_with_previous`
2022-06-20 10:46:11 -07:00
bors 056313dbfb Auto merge of #10772 - tshepang:patch-2, r=Eh2406
capitalise, for consistency
2022-06-20 16:35:32 +00:00
Nils McCarthy b424f90edb Don't use the full pathname of a custom target json in fingerprint hashes.
This makes it easier to get reproducible builds for custom targets.
2022-06-20 09:09:52 -07:00
bors 5f5c1966a8 Auto merge of #10774 - Muscraft:update-benchsuite-deps, r=Eh2406
remove unused dependency from benchsuite

In #10754 I added a new benchmark to the benchsuite. While figuring out the best way to add the new benchmark, I added `cargo-test-support` as a dependency. It appears I missed removing it before making the PR.

This PR removes `cargo-test-support` since it is not needed
2022-06-20 15:34:50 +00:00
bors 8fd9f82a5e Auto merge of #10758 - epage:docs, r=weihanglo
docs(contrib): Add documentation for ui tests

### What does this PR try to resolve?

This only adds information about snapshot testing using `snapbox` and
keeps the functional testing documentation focused on the existing
facilities.  We can updated this as our use of `snapbox` matures.

### How should we test and review this PR?

I did not generate and verify the HTML

In writing this, I did notice that we define
`cargo_test_support::compare::assert` but only use it for filesystem
asserts and not binary asserts.  We should probably add our own function
that wraps `snapbox::cmd::Command::cargo()` and passes in
`cargo_test_support::compare::assert`.  I've left that out of this PR to
keep things focused.
2022-06-20 14:47:36 +00:00
Scott Schafer 5b368820a7 remove unused dependency from benchsuite 2022-06-20 09:44:48 -05:00
Ed Page 619630c3ec docs(contrib): Update API item links 2022-06-20 09:35:54 -05:00
Tshepang Mbambo f5b21bfe6e
capitalise, for consistency 2022-06-19 18:37:50 +02:00