Commit graph

13090 commits

Author SHA1 Message Date
bors 67398aec95 Auto merge of #11325 - weihanglo:changelog, r=ehuss
Mention fix on build script deadlock

I think it is worth mentioning this beta backport in the changelog.
2022-11-02 14:42:11 +00:00
Weihang Lo 1400fd0858
Mention fix on build script deadlock 2022-11-02 14:36:41 +00:00
bors 352175f810 Auto merge of #11285 - jonhoo:cargo-env, r=weihanglo
Make cargo forward pre-existing CARGO if set

Currently, Cargo will always set `$CARGO` to point to what it detects its own path to be (using `std::env::current_exe`). Unfortunately, this runs into trouble when Cargo is used as a library, or when `current_exe` is not actually the binary itself (e.g., when invoked through Valgrind or `ld.so`), since `$CARGO` will not point at something that can be used as `cargo`. This, in turn, means that users can't currently rely on `$CARGO` to do the right thing, and will sometimes have to invoke `cargo` directly from `$PATH` instead, which may not reflect the `cargo` that's currently in use.

This patch makes Cargo re-use the existing value of `$CARGO` if it's already set in the environment. For Cargo subcommands, this will mean that the initial invocation of `cargo` in `cargo foo` will set `$CARGO`, and then Cargo-as-a-library inside of `cargo-foo` will inherit that (correct) value instead of overwriting it with the incorrect value `cargo-foo`. For other execution environments that do not have `cargo` in their call stack, it gives them the opportunity to set a working value for `$CARGO`.

One note about the implementation of this is that the test suite now needs to override `$CARGO` explicitly so that the _user's_ `$CARGO` does not interfere with the contents of the tests. It _could_ remove `$CARGO` instead, but overriding it seemed less error-prone.

Fixes #10119.
Fixes #10113.
2022-11-02 12:38:30 +00:00
bors 65b2149770 Auto merge of #11242 - cassaundra:remove-workspace, r=epage
Clean up workspace dependencies after cargo remove

### What does this PR try to resolve?

After successful removal of an inherited dependency from a workspace member, clean up the root workspace manifest.

This PR is part of the continued working on cargo remove (#11099, see deferred work).

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

Make sure the tests cover all possible use cases. After posting this PR, I will post a short self-review regarding some design concerns.

### Additional information

#11194 is currently blocked on this feature.
2022-11-01 20:15:55 +00:00
Cassaundra Smith 38b23d5c68
Clean up workspace dependencies after cargo remove 2022-11-01 12:08:16 -07:00
Weihang Lo a4d2e29e21
Gleaning rustdocflags from target.cfg(…) is not supported
The bug was `rustflags_from_target` trying to learn rustdocflags from
`target.cfg(…).rustflags`, which is definitely wrong.
As of this writing, either `target.cfg(…).rustdocflags` or
`target.<triple>.rustdocflags` is not supported.
2022-11-01 15:01:44 +00:00
Weihang Lo f8d1b30ad3
test(rustdocflags): shouldn't be affected by rustflags from target.cfg 2022-11-01 15:00:26 +00:00
bors 16c9c4ea63 Auto merge of #11322 - hi-rustin:rustin-patch-links, r=ehuss
Update the outdated link for rust-semverver

### What does this PR try to resolve?

Update the outdated link for rust-semverver. It works but better to keep it updated.
2022-11-01 14:09:16 +00:00
hi-rustin e51a781aa9 Update outdated link for rust-semverver
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2022-11-01 21:04:37 +08:00
bors 5f3a9d1f36 Auto merge of #11317 - krtab:fix_broken_link_cargo_compile, r=weihanglo
Fix broken link to compilation entry point

A dead link was pointing to `cargo_compile.rs` instead of `cargo_compile/mod.rs`.
Cf: 886c9d2153
2022-11-01 12:49:40 +00:00
bors 9e71316fcb Auto merge of #10621 - LovecraftianHorror:more-precise-artifact-cleanup, r=weihanglo
Only remove fingerprints and build script artifacts of the requested package

Fixes #10069

This is my first PR to cargo. Let me know if you want me to add tests, or if there are any other changes you would like to see :)

This PR changes the globs used to remove fingerprints and build artifacts when running `cargo clean -p <pkid>`. The glob used was `<package_name>-*` which would match artifacts for packages that are prefixed by `<package_name>-` (e.g. `cargo clean -p sqlx` would also remove artifacts for `sqlx-{core,macros,etc.}`). This problem is not seen with other artifacts since those use the crate name instead of package name which normalize hyphens to underscores.

The changes follow the naive approach mentioned in #10069 where some basic string manipulation is done to strip off the last hyphen, hash, and potential extension to get the original package name which can be used to determine if the artifact is actually for the desired package. This means that this **does not** handle trying to resolve the package to determine the artifacts, so it still ignores the url and version that may be passed in the pkgid
2022-11-01 11:49:13 +00:00
bors cdc22d4dfe Auto merge of #11316 - kornelski:invalid-anyhow, r=weihanglo
Newer anyhow features are required

anyhow doesn't follow semver rules for new features, and Cargo won't compile with anyhow older than this version due to dependence on captured variables in format strings.
2022-11-01 11:01:38 +00:00
bors 37cad5bd7f Auto merge of #11308 - ehuss:clean-tmp-libgit2, r=weihanglo
Clean stale git temp files

### What does this PR try to resolve?

When cargo is interrupted while libgit2 is indexing the pack file, it will leave behind a temp file that never gets deleted. These files can be very large. This checks for these stale temp files and deletes them.

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

There is a simulated test here. To test with the actual behavior:

1. Run `CARGO_HOME=chome cargo fetch`
2. While it is "resolving deltas", hit Ctrl-C.
3. Notice that there is a 200MB file in `chome/registry/index/github.com-1ecc6299db9ec823/.git/objects/pack/`
4. Do that several times if you want, each time adds another 200MB file.
5. Build this PR: `cargo b -r`
6. Run `CARGO_HOME=chome CARGO_LOG=cargo::sources::git::utils=debug ./target/release/cargo fetch`
7. Notice that it deletes the `pack_git2_*` files.
2022-11-01 09:21:14 +00:00
Lovecraftian Horror 2ebcc75bf4 Actually make test effective 2022-10-31 20:43:20 -06:00
Arthur Carcano 0665777e6b Fix broken link to compilation entry point
Was cargo_compile.rs instead of cargo_compile/mod.rs
Cf: 886c9d2153
2022-10-31 16:37:24 +01:00
Kornel 589d704209 Newer anyhow features are required 2022-10-31 15:33:27 +00:00
Lovecraftian Horror 604aeb5c24 Address review comments 2022-10-29 23:05:19 -06:00
Lovecraftian Horror a6d0e96798 Add test to verify functionality 2022-10-29 22:28:49 -06:00
Lovecraftian Horror 738f0846c9 Merge branch 'master' of github.com:rust-lang/cargo into more-precise-artifact-cleanup 2022-10-29 11:49:16 -06:00
bors da204963d6 Auto merge of #11270 - antonok-edm:report-packagesize, r=weihanglo
Report crate size on package and publish

### Motivation

Fixes #11251.

This adds a line like `Packaged 42 files, 727.0KiB (143.8KiB compressed)` to the output of `cargo package` and `cargo publish`. See the associated issue for more details.

### Test info

I've updated associated tests to account for the new line in the output, including the file count where relevant. I've also added a few additional tests specifically to address the uncompressed and compressed file sizes.

If you'd like to test this manually, simply run `cargo package` or `cargo publish` within a project of your choice. The new `Packaged` line will appear at the end of the stderr output, or directly before the `Uploaded` line, respectively.

### Review info

This PR touches many test files to account for the additional line of stderr output. For convenience, I've split the PR into 4 commits.
1. contains the actual implementation
2. updates existing tests unrelated to `cargo package` and `cargo publish`
3. updates existing tests related to `cargo package` and `cargo publish`, including file counts where relevant
4. adds new tests specifically for the file sizes, which are generally not covered by existing tests

### Additional information

The feature was discussed [on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/246057-t-cargo/topic/Report.20crate.20size.20when.20packaging) prior to implementation.

Potential future extensions to explore include:
- Report size per file when using `--verbose`
- Compare to the size of the previously uploaded version to warn if the increase is sufficiently large
- Consider designs that can draw more attention to the most important information
- Warn if large binary files are included ([#9058](https://github.com/rust-lang/cargo/issues/9058))
2022-10-29 00:27:56 +00:00
Anton Lazarev 24500354bf
add new tests for filesizes 2022-10-28 17:13:25 -07:00
Anton Lazarev 9333b8f5ba
update package, publish, and publish_lockfile tests 2022-10-28 17:13:25 -07:00
Anton Lazarev d70a4ee93c
update stderr in tests for unrelated functionality 2022-10-28 17:13:25 -07:00
Anton Lazarev 81f0f63c6a
report crate size on package and publish 2022-10-28 17:13:25 -07:00
Eric Huss 754de17df3 Clean stale git temp files 2022-10-28 15:39:02 -07:00
bors 2d04bcd1b0 Auto merge of #10989 - Muscraft:add-auto-fix-note, r=weihanglo
add a note that some warnings (and/or errors) can be auto-fixed

This adds a note that some warnings (and/or errors) can be auto-fixed by running `cargo --fix`. This only supports `cargo check` as we can't show the same note for `cargo clippy` since it is an external subcommand.

The message for the note was taken from [#10976 (comment)](https://github.com/rust-lang/cargo/issues/10976#issuecomment-1212517765).
2022-10-28 05:18:17 +00:00
bors 9e0b10f5cd Auto merge of #11307 - ehuss:update-curl, r=epage
Update libcurl

This updates to the latest libcurl from 7.83.1 to 7.86.0. There are extensive changes documented thoroughly at https://curl.se/changes.html. There are 5 CVEs as documented at https://curl.se/docs/security.html, though none of them look particularly serious for our use case.

This adds a limit of TLS 1.2 for Windows. There have been some issues with TLS 1.3 (which was recently added), and I'm not confident enabling it, yet. Perhaps some day in the future when it looks like it is more reliable, the limit can be removed.
2022-10-28 01:53:51 +00:00
bors d4c38af120 Auto merge of #11183 - weihanglo:issue/10526, r=ehuss
artifact deps shoud works when target field specified coexists with `optional = true`
2022-10-28 00:50:23 +00:00
Eric Huss d014c2929d Update libcurl 2022-10-27 17:20:09 -07:00
Scott Schafer 8ff8eaa496 add a note that some warnings can be auto-fixed 2022-10-27 19:07:59 -05:00
bors 92d8826ed4 Auto merge of #11300 - DAmNRelentless:patch-1, r=ehuss
Fix singular verb in tests page

The word "compile" refers to the "code samples" which is plural.
2022-10-27 18:34:26 +00:00
bors 7e484fc1a7 Auto merge of #11062 - epage:wait, r=weihanglo
fix(publish): Block until it is in index

Originally, crates.io would block on publish requests until the publish
was complete, giving `cargo publish` this behavior by extension.  When
crates.io switched to asynchronous publishing, this intermittently broke
people's workflows when publishing multiple crates.  I say interittent
because it usually works until it doesn't and it is unclear why to the
end user because it will be published by the time they check.  In the
end, callers tend to either put in timeouts (and pray), poll the
server's API, or use `crates-index` crate to poll the index.

This isn't sufficient because
- For any new interested party, this is a pit of failure they'll fall
  into
- crates-index has re-implemented index support incorrectly in the past,
  currently doesn't handle auth, doesn't support `git-cli`, etc.
- None of these previous options work if we were to implement
  workspace-publish support (#1169)
- The new sparse registry might increase the publish times, making the
  delay easier to hit manually
- The new sparse registry goes through CDNs so checking the server's API
  might not be sufficient
- Once the sparse registry is available, crates-index users will find
  out when the package is ready in git but it might not be ready through
  the sparse registry because of CDNs

So now `cargo` will block until it sees the package in the index.
- This is checking via the index instead of server APIs in case there
  are propagation delays.  This has the side effect of being noisy
  because of all of the "Updating index" messages.
- This blocks by default but there is an unstable `publish.timeout` config field that will disable blocking when set to 0.  See #11222 for stablization

Blocking is opt-out as that is the less error prone case for casual users while those doing larger integrations are also likely to do the testing needed to make more complicated scenarios work where blocking is disabled.

Right now we block after the publish.  An alternative would be to block until all dependencies are in the index which makes the blocking only happen when needed
- Blocking on dependencies can be imprecise to detect when to block vs propagate an error up
- This is the less error prone case for users.  For example I recently publish a crate in one tab and immediately switched to another tab to use it and this only worked because `cargo-release` blocked until it was ready to use

In reviewing this change, be sure to look at the individual commits
- The first makes it possible to write the tests for this
- The second adds a test that shows the current behavior
- The third updates the test to the expected behavior, showing all of this works

In addition to the publish tests:
- We want to maximize the nightly-to-stable time to collect feedback
- We will put this in TWiR's testing section to raise visibility

Fixes #9507
2022-10-27 15:20:57 +00:00
Relentless fea7d799df
Fix incorrect plural typo in tests page 2022-10-27 16:36:05 +02:00
bors 1985caf190 Auto merge of #11292 - arlosi:compression, r=epage
Add Accept-Encoding request header to enable compression

### What does this PR try to resolve?

Cargo does not request compression from servers. Enabling compression can save bandwidth and improve performance.

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

I validated locally that the header was being sent using a local proxy (Fiddler). It sent `Accept-Encoding: deflate, gzip` on Windows.
2022-10-27 01:37:25 +00:00
bors 1c1e9a61cb Auto merge of #11294 - ehuss:highfive-docs, r=weihanglo
Update contrib docs for highfive transition

As of #11293, this repo is now using triagebot (AKA `@rustbot)` for auto-assignment of PRs. This PR updates the contributor documentation to accommodate this change.
2022-10-27 00:16:45 +00:00
Weihang Lo 2b913b664f
doc(features2): explain the meaning of presence in activated_features 2022-10-27 08:06:25 +08:00
Eric Huss cf38262995 Update contrib docs for highfive transition 2022-10-26 16:58:34 -07:00
bors 1cb94b0733 Auto merge of #11293 - ehuss:highfive-triagebot, r=Mark-Simulacrum
Migrate from highfive to triagebot

This migrates the rust-lang/cargo repo to use triagebot instead of highfive.
2022-10-26 23:19:08 +00:00
Weihang Lo 9e8395904d
doc(features2): clarify some docs 2022-10-26 20:41:56 +08:00
Weihang Lo c31e017885
fix(bindeps): target field specified and optional = true coexist
Previously, `is_dep_activated` depends on `activated_dependencies`,
which is a map of `PackageFeaturesKey` to its own activated `DepFeature`s.
`PackageFeaturesKey` in feature resolver is always comprised of

* A `PackageId` of a given dependency, and
* A enum value that helps decoupling activated features for that dependency.
  Currently depending on the type of given dependency.

Looking into issue 10526, it has an `activated_dependencies` of

```
{
    (mycrate, NormalOrDevOrArtifactTarget(None)) -> [dep:mybindep]
}
```

However, this [line][1] accidentally use a parent's `pkgid`
and a dependency's `FeaturesFor` to compose a key:

```
(mycrate, NormalOrDevOrArtifactTarget("x86_64-unknown-linux-gnu"))
```

That is never a valid key to query features for artifacts dependency.
A valid key should be comprised of components both from the parent:

```
(mycrate, NormalOrDevOrArtifactTarget(None))
```

Or both from the dependency itself:

```
(mybindep, NormalOrDevOrArtifactTarget("x86_64-unknown-linux-gnu"))
```

As aforementioned `activated_dependencies` only stores parent packages
and their activated features. Those informations are included in
`activated_features` as well, so this commit goes with the route that
removes `activated_dependencies` and uses only dependency's infomation
to query if itself is activated.

[1]: 0b84a35c2c/src/cargo/core/compiler/unit_dependencies.rs (L1097-L1098)
2022-10-26 20:41:56 +08:00
Weihang Lo 7089bbf2e4
test(bindeps): target field specified and optional = true coexist 2022-10-26 20:41:56 +08:00
bors 1945b44853 Auto merge of #11287 - Rageking8:fix-dupe-word-typos, r=weihanglo
Fix dupe word typos
2022-10-26 07:41:02 +00:00
Rageking8 61813d9d72 fix dupe word typos 2022-10-26 12:15:45 +08:00
bors da63337681 Auto merge of #11283 - arlosi:sparse-error, r=weihanglo
Fix confusing error messages when using -Zsparse-registry

Built-in replacements of crates.io have confusing a description:
> crates.io index (which is replacing registry `crates-io`)

This adds a special case for built-in source replacements of `crates-io`. User-defined replacements of crates.io continue to use the existing description.

Also fixes the test framework `__CARGO_TEST_CRATES_IO_URL_DO_NOT_USE_THIS` variable to strip the `sparse+` prefix when checking if a url `is_crates_io`.

Fixes #11277
2022-10-26 04:09:55 +00:00
Arlo Siemsen 7c89237104 Add Accept-Encoding request header to enable compression 2022-10-25 17:36:39 -05:00
bors 9210810d1f Auto merge of #11286 - ehuss:410-gone, r=Eh2406
Fix 410 gone response handling

This changes the sparse-registry support for the 410 "Gone" HTTP response code. This is out of sync with the [load function](8adf1df292/src/cargo/sources/registry/http_remote.rs (L375)) mentioned in the comment. I assume it is supposed to be 410 and not 401 since 401 is "Unauthorized", and that doesn't signify that the resource is "not found".

r? `@arlosi`
2022-10-25 22:31:50 +00:00
Eric Huss c8c6a963c0 Fix 410 gone response handling 2022-10-25 14:45:41 -07:00
Jon Gjengset 724a1977ce Make cargo forward pre-existing CARGO if set
Currently, Cargo will always set `$CARGO` to point to what it detects
its own path to be (using `std::env::current_exe`). Unfortunately, this
runs into trouble when Cargo is used as a library, or when `current_exe`
is not actually the binary itself (e.g., when invoked through Valgrind
or `ld.so`), since `$CARGO` will not point at something that can be used
as `cargo`. This, in turn, means that users can't currently rely on
`$CARGO` to do the right thing, and will sometimes have to invoke
`cargo` directly from `$PATH` instead, which may not reflect the `cargo`
that's currently in use.

This patch makes Cargo re-use the existing value of `$CARGO` if it's
already set in the environment. For Cargo subcommands, this will mean
that the initial invocation of `cargo` in `cargo foo` will set `$CARGO`,
and then Cargo-as-a-library inside of `cargo-foo` will inherit that
(correct) value instead of overwriting it with the incorrect value
`cargo-foo`. For other execution environments that do not have `cargo`
in their call stack, it gives them the opportunity to set a working
value for `$CARGO`.

One note about the implementation of this is that the test suite now
needs to override `$CARGO` explicitly so that the _user's_ `$CARGO` does
not interfere with the contents of the tests. It _could_ remove `$CARGO`
instead, but overriding it seemed less error-prone.

Fixes #10119.
Fixes #10113.
2022-10-25 13:51:27 -07:00
Arlo Siemsen 40293266b2 Fix confusing error messages when using -Zsparse-registry 2022-10-25 13:51:43 -05:00
bors 8adf1df292 Auto merge of #11281 - smheidrich:fix-stale-mtime-log-ineq, r=ehuss
Fix inequality in "stale mtime" log messages

### What does this PR try to resolve?

If `CARGO_LOG=cargo::core::compiler::fingerprint=info` is set, cargo will print log messages that are useful for finding out why something is being recompiled. E.g. if the modification time (mtime) of a source file is newer than the cached build result, it will print something like:

```
stale: changed "/host//home/runner/.cargo/registry/src/github.com-1285ae84e5963aae/proc-macro2-1.0.47/build.rs"
          (vs) "/host/home/runner/target/release/build/proc-macro2-45f04ea9067a46ed/output"
               FileTime { seconds: 1666559031, nanos: 16426033 } != FileTime { seconds: 1666559080, nanos: 324117075 }
```

However, the `!=` in the log message is misleading, as equality is not the [criterion that's actually used](071eeaf210/src/cargo/core/compiler/fingerprint.rs (L1761)) to determine when to rebuild.

This PR fixes that by changing `!=` to `<`, corresponding to the actual criterion.

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

Look at the [criterion](071eeaf210/src/cargo/core/compiler/fingerprint.rs (L1761)) I linked and trace `stale_mtime` in the log message back to `path_mtime` in said criterion to see why it has to be `<`.
2022-10-25 02:55:45 +00:00