Commit Graph

8329 Commits

Author SHA1 Message Date
bors 247ca7fd04 Auto merge of #11087 - weihanglo:issue-11013, r=epage
Report cmd aliasing failure with more contexts

### What does this PR try to resolve?

Commands aliasing resolution should report TOML parsing error to users.

Fixes #11013.

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

https://github.com/rust-lang/cargo/pull/11087/commits/ef7a4ef is the most important commit in this PR. `has_key` now throws errors after this PR, so any use `Config::get<Option<…>>()` is affected if there is a malformed config. Had a skim over all usages of `get::<Option<…>>`, `get_string` and `get_path`, I don't feel any of them should ignore errors.
2022-09-22 14:51:58 +00:00
bors 8882d993f3 Auto merge of #11127 - matklad:unused-mut, r=Eh2406
minor: remove unused mut
2022-09-22 14:06:49 +00:00
Aleksey Kladov 73c79c7821 minor: remove unused mut 2022-09-22 15:04:00 +01:00
Weihang Lo 5caabc0ade
doc: rustdoc for `aliased_command` 2022-09-22 10:52:39 +01:00
Weihang Lo 5dd982d8af
Make `cargo version` work even with malformed configurations 2022-09-22 10:52:39 +01:00
Weihang Lo ef7a4ef062
Dont swallow errors when checking existence of a config key 2022-09-22 10:52:39 +01:00
bors 7c8a5a67d3 Auto merge of #11118 - epage:external, r=weihanglo
fix(cli): Forward non-UTF8 arguments to external subcommands

Whether we allow non-UTF-8 arguments or not, we shouldn't preclude external subcommands from deciding to do so.

I noticed this because clap v4 changed the default for external subcommands from `String` to `OsString` with the assumption that this would help people to "do the right thing" more often.
2022-09-22 07:56:31 +00:00
bors 635a84854b Auto merge of #10938 - ptdecker:add-author-example, r=weihanglo
This change adds an example to the authors attribute in the manifest.

It is submitted to clarify the documenation for new folks such as
myself. See the forum issue linked below which prompted this change
since the error message the compiler issues is not clear for new
folks.

https://users.rust-lang.org/t/compile-error-when-adding-authors-to-cargo-toml/79383

Thank you for considering this contribution. It's my first so go
easy on me please!  :-)
2022-09-21 20:44:58 +00:00
P. Todd Decker 51dc6fb3c4
Update src/doc/src/reference/manifest.md
Adding newline back per @weihanglo's input (thank you)

Co-authored-by: Weihang Lo <weihanglo@users.noreply.github.com>
2022-09-21 15:28:50 -05:00
Ed Page 87fdf7660c fix(cli): Forward non-UTF8 arguments to external subcommands
I noticed this because clap v4 changed the default for external
subcommands from `String` to `OsString` with the assumption that this
would push people to "do the right thing" more often.
2022-09-21 14:35:21 -05:00
bors 23ab870c50 Auto merge of #11106 - x-hgg-x:issue-7992, r=epage
Add support for relative git submodule paths

Fixes #7992.

This is a continuation of #9592, tested on Linux and Windows.

> Git allows submodules to have relative URLs, but cargo does not handle this correctly, and simply fails to update submodules as described in issue https://github.com/rust-lang/cargo/issues/7992. This PR fixes that by passing in the parent git repo url to update_submodules.

The previous PR wasn't compatible on Windows, since it used [`std::path::Path`](https://doc.rust-lang.org/std/path/struct.Path.html) for merging the parent and relative submodule urls.

This PR uses [`url::Url`](https://docs.rs/url/latest/url/struct.Url.html) instead, which has the same behavior on all platforms. It also refers to the [git documentation](https://git-scm.com/docs/git-submodule#Documentation/git-submodule.txt-add-bltbranchgt-f--force--nameltnamegt--referenceltrepositorygt--depthltdepthgt--ltrepositorygtltpathgt) for the definition of a relative git submodule path.
2022-09-21 18:09:09 +00:00
bors bee9c896c0 Auto merge of #11098 - Emilgardis:early-fail, r=epage
make unknown features on `cargo add` more discoverable

When adding an unknown feature via `cargo add -F krate/feat`, it can be easy to miss the fact that the change failed.

This fixes that by showing the following output on fail

<img width="474" alt="image" src="https://user-images.githubusercontent.com/1502855/191100141-3603cc9a-d4b6-4d6a-bbc6-41b34144b3f0.png">
2022-09-21 17:25:19 +00:00
bors a74a8d0456 Auto merge of #11122 - weihanglo:issue-11101, r=epage
Unlink old final artifacts before compilation
2022-09-21 16:43:29 +00:00
Weihang Lo b47cacbacf
fix(artifact): delete old final artifacts before rebuild
Some linkers do not remove the executable, but truncate and modify it.
That results in the old hard-link being modified even after renamed.
We delete the old artifact here to prevent this behavior from confusing users.
See rust-lang/cargo#8348.
2022-09-21 16:09:12 +01:00
bors e320c3e545 Auto merge of #11119 - epage:error, r=ehuss
fix(cli): Error trailing args rather than ignore

This warning has been in for a sufficient time, requires a hack from clap to avoid all argument ID validation, and allows users to run the wrong command (imagine `cargo -- publish --dry-run`).

See also https://rust-lang.zulipchat.com/#narrow/stream/246057-t-cargo/topic/Cargo.20ignoring.20arguments.20with.20.60cargo.20--.20check.20--ignored.60
2022-09-21 14:00:15 +00:00
x-hgg-x 528a8b25af Add fixes from review 2022-09-21 13:08:41 +02:00
x-hgg-x 37fdd714c4 Use Cow<str> when normalizing parent url path 2022-09-21 13:08:41 +02:00
x-hgg-x c29f0b715f Simplify relative submodule handling 2022-09-21 13:08:41 +02:00
x-hgg-x 942f7f9c59 Add support for relative git submodule paths 2022-09-21 13:08:41 +02:00
Emil Gardström 1cc21b65d1
make unknown features on `cargo add` more discoverable 2022-09-21 08:07:16 +02:00
Ed Page 8f8a79a5a4 fix(cli): Error trailing args rather than ignore
This warning has been in for a sufficient time, requires a hack from
clap to avoid all argument ID validation, and allows users to run the
wrong command (imagine `cargo -- publish --dry-run`).

See also https://rust-lang.zulipchat.com/#narrow/stream/246057-t-cargo/topic/Cargo.20ignoring.20arguments.20with.20.60cargo.20--.20check.20--ignored.60
2022-09-20 16:54:01 -05:00
Ed Page b00b59dacb refactor(cli): Use new clap::ErrorKind location 2022-09-20 13:32:11 -05:00
Ed Page 0a78364fd1 refactor(cli): Align with clap 3.1 on terminology
clap 3.1 renamed `App` to `Command`.  When we upgrade to clap v4, the
lifetime will be removed and we can just use `clap::Command` instead of
a type alias.  This is prep for that.
2022-09-20 13:28:36 -05:00
bors 531ce1321d Auto merge of #11093 - mrexodia:patch-1, r=epage
Add a minor clarification

### What does this PR try to resolve?

It tries to clarify the overriding build scripts section. We spent over an hour with 3 people trying to get it to work and it was extremely difficult to figure out.

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

N/A

### Additional information

N/A
2022-09-20 17:51:36 +00:00
Duncan Ogilvie 6b2ff2b950 Add a minor clarification
Hopefully this will save the next person from wasting an hour+ on this.
2022-09-20 18:57:13 +02:00
Emil Gardström d924a253c7
split table and action message prints
also makes gathering of features a function
2022-09-19 23:43:37 +02:00
Ed Page 7df918eb87
Revert "Clarify when cargo detects changes" 2022-09-17 18:58:30 -05:00
Weihang Lo d87d57dbbd
CVE-2022-36114: add tests 2022-09-14 10:54:49 +02:00
Josh Triplett d1f9553c82
CVE-2022-36114: limit the maximum unpacked size of a crate to 512MB
This gives users of custom registries the same protections, using the
same size limit that crates.io uses.

`LimitErrorReader` code copied from crates.io.
2022-09-14 10:54:48 +02:00
Josh Triplett 97b80919e4
CVE-2022-36113: avoid unpacking .cargo-ok from the crate 2022-09-14 10:54:44 +02:00
Cassaundra Smith d1b041d639
Better document `util::toml_mut`
Notable changes:
- Add/improve module documentation.
- Add missing item documentation.
- Add "editable" to `Dependency` and `Manifest` to further distinguish them from
  similarly named items in the library.

Stylistic changes:
- Terminate doc comments with a period.
- Wrap doc comments.
2022-09-13 14:59:57 -07:00
Cassaundra Smith dd5d61c65b
Expose cargo add internals as utils
Move cargo add utils out for future use by other subcommands (namely cargo
remove, per #10520).
2022-09-13 14:09:28 -07:00
Ed Page f39f8dc5d4 docs(ref): Provide path for people to finding why shared Cargo.lock matters 2022-09-13 14:08:01 -05:00
Ed Page cad833d9a6 docs(ref): Include workspace inheritane 2022-09-13 14:06:17 -05:00
Ed Page f1da8c4c2b docs(ref): Add --workspace as a key point
This is a frequent reason I use them
2022-09-13 14:06:02 -05:00
Ed Page c08ecbb519 docs(ref): Remove redundant workspace description 2022-09-13 14:03:48 -05:00
bors 082503982e Auto merge of #11032 - lqd:priority_pending_queue, r=Eh2406
Take priority into account within the pending queue

This is the PR for the work discussed in [this zulip thread](https://rust-lang.zulipchat.com/#narrow/stream/246057-t-cargo/topic/pending.20queue.20scheduling.20experiments) and whose detailed description and some results are available [here](https://github.com/lqd/rustc-benchmarking-data/tree/main/experiments/cargo-schedules/pending-queue-sorted) with graphs, summaries and raw data -- much of which was shown in the thread as well.

Units of works have a computed priority that is used in the dependency queue, so that higher priorities are dequeued sooner, as documented [here](996a6363ce/src/cargo/util/dependency_queue.rs (L34-L35)).

This PR further applies that principle to the next step before being executed: if multiple pieces of work are waiting in the pending queue, we can sort that according to their priorities. Here as well, higher priorities should be scheduled sooner.

They are more often than not wider than pure chains of dependencies, and this should create more parallelism opportunities earlier in the pipeline: a high priority piece of work represents more future pieces of work down the line, and try to sustain CPU utilization longer (at the potential cost of this parallelism being distributed differently than today, between cargo invoking rustc and rustc's own codegen threads -- when applicable).

This is a scheduling tradeoff that behaves differently for each project, machine configuration, amount of available parallelism at a given point in time, etc, but seems to help more often than hinders: at low-core counts and with enough units of work to be done, so that there is jobserver token contention where choosing a "better" piece of work to work on next may be possible.

There's of course a bit of noise in the results linked above and 800 or so of the most popular crates.io crates is still a limited sample, but they're mostly meant to show a hopefully positive trend: while there are improvements and regressions, that trend looks to be more positive than negative, with the wins being more numerous and with higher amplitudes than the corresponding losses.

(A report on another scheduling experiment -- a superset of this PR, where I also simulate users manually giving a higher priority to `syn`, `quote`, `serde_derive` -- [is available here](https://github.com/lqd/rustc-benchmarking-data/tree/main/experiments/cargo-schedules/pending-queue-prioritized) and also improves this PR's results: the regressions are decreased in number and amplitude, whereas the improvements are bigger and more numerous. So that could be further work to iterate upon this one)

Since this mostly applies to clean builds, for low core counts, and with a sufficient number of dependencies to have some items in the pending queue, I feel this also applies well to CI use-cases (esp. on the free tiers).

Somewhat reassuring as well, and discussed in the thread but not in the report: I've also tried to make sure cargo and bootstrapping rustc are not negatively affected. cargo saw some improvements, and bootstrap stayed within today's variance of +/- 2 to 3%. Similarly, since 3y old versions of some tokio crates (`0.2.0-alpha.1`) were the most negatively affected, I've also checked that recent tokio versions (`1.19`) are not disproportionately impacted: their simple readme example, the more idiomatic `mini-redis` sample, and some of my friends' tokio projects were either unaffected or saw some interesting improvements.

And here's a `cargo check -j2` graph to liven up this wall of text:

![some results of `cargo check -j2`](https://github.com/lqd/rustc-benchmarking-data/raw/main/experiments/cargo-schedules/pending-queue-sorted/images/check-j2-sorted.png)

---

I'm not a cargo expert so I'm not sure whether it would be preferable to integrate priorities deeper than just the dependency queue, and e.g. have `Unit`s contain a dedicated field or similar. So in the meantime I've done the simplest thing: just sort the pending queue and ask the units' priorities to the dep queue.

We could just as well have the priority recorded as part of the pending queue tuples themselves, or have that be some kind of priority queue/max heap instead of a Vec.

Let me know which you prefer, but it's in essence a very simple change as-is.
2022-09-13 17:49:38 +00:00
bors c633b27cb8 Auto merge of #11075 - epage:feat, r=weihanglo
fix(add): Clarify which version the features are added for

### What does this PR try to resolve?

This gives a hint to users that we might not be showing the feature list
for the latest version but the earliest version.

Also when using a workspace dependency, this is a good reminder of what the version requirement is that was selected.  That could also be useful for reused dependencies but didn't want to bother with the relevant plumbing for that.

ie we are going from
```console
$ cargo add chrono@0.4
    Updating crates.io index
      Adding chrono v0.4 to dependencies.
             Features:
             - rustc-serialize
             - serde
```
to
```console
$ cargo add chrono@0.4
    Updating crates.io index
      Adding chrono v0.4 to dependencies.
             Features as of v0.4.2:
             - rustc-serialize
             - serde
```

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

I'd recommend looking at this commit-by-commit.  This is broken up into several refactors leading up the main change.  The refactors are focused on pulling UI logic out of dependency editing so we can more easily evolve the UI without breaking the editing API.  I then tweaked the behavior in the final commit to be less redundant / noisy.

The existing tests are used to demonstrate this is working.

### Additional information

I'm also mixed on whether the meta version should show up.

Fixes #11073
2022-09-13 17:08:01 +00:00
Ed Page 0e09e5cbca docs(ref): Move metadata to last 2022-09-13 12:02:11 -05:00
bors fedd172f3a Auto merge of #11079 - weihanglo:issue-10991, r=epage
doc: clarify config-relative paths for `--config <path>`
2022-09-13 16:20:12 +00:00
Ed Page 5a6cfc9a56 style(add): Use implicit argument capture 2022-09-13 11:18:00 -05:00
Ed Page 1a20200e09 chore: Document new add implementation 2022-09-13 11:17:29 -05:00
Ed Page fb510f5713 docs(ref): Have workspace docs link out to patch/replace docs
The workspace behavior doesn't seem to be documented at all, so a blurb
was brought in that is like the profile blurb.  The workspace docs then
link out to it so users can be aware of this special workspace behavior.
2022-09-13 11:04:17 -05:00
Ed Page a8412742ad docs(ref): Have workspace docs link out to profile section docs
In a workspace, only the workspace's profile is respected.  This is
already documented in the profile documentation but we should raise
visibility of it within the workspace documentation.
2022-09-13 11:03:31 -05:00
Ed Page 5189a81cae docs(ref): Have workspace docs link out to resolver field docs
This is a part of the schema we were missing.  A first step before
encouraging people to use it is to document it!
2022-09-13 11:03:08 -05:00
Ed Page b5bcd47872 docs(ref): Re-org workspace docs to be like package docs
In looking over #10625, I remembered we've been having growing pains
with the workspace documentation.  It was originally written when there
were a lot fewer workspace features.  As more workspace features have
been added, they've been tacked on to the documentation.

This re-thinks the documentation by focusing on the schema, much like
`manifest.md` does.
2022-09-13 11:03:05 -05:00
Weihang Lo d94ce9fc90
Don't mention current ResolveVersion in comment 2022-09-15 23:16:08 +01:00
Weihang Lo c38ca2d26d
Link to `ResolveVersion::default` 2022-09-15 21:11:05 +01:00
Weihang Lo 293431da1e
Update comment about ResolveVersion default version 2022-09-15 20:55:47 +01:00
Ryan Butler 53a106450d
Update build-scripts.md 2022-09-14 13:41:46 -04:00