Commit graph

16481 commits

Author SHA1 Message Date
Weihang Lo a37d122949
test: show pkgid spec + query doesnt work with --package 2024-01-18 00:37:52 -05:00
bors 1ae631085f Auto merge of #13311 - weihanglo:pkgid-json-message, r=epage
fix(json-msg): use pkgid spec in in JSON messages
2024-01-17 17:26:41 +00:00
Weihang Lo ad1a3b3758
docs: more links to JSON messages 2024-01-17 11:31:19 -05:00
Weihang Lo b5457ac883
docs(json-msg): pkgid spec as package_id 2024-01-17 11:31:19 -05:00
Weihang Lo f9fd4ff4ee
fix(json-msg): use pkgid spec in in JSON messages
In 12914 we stabilized pkgid spec as unique package identifier for
`cargo metadata`. However, we forgot to make the same change to
JSON message format[^1]. This PR does so.

Note that the `package_id` field in JSON message is not clearly stated
as "opaque", so it might be considered as a breaking change to some extent.

[^1]: https://doc.rust-lang.org/nightly/cargo/reference/external-tools.html#compiler-messages
2024-01-17 11:31:19 -05:00
bors a383063b00 Auto merge of #13307 - epage:unstable, r=weihanglo
doc(features): Highlight the non-blocking feature gating technique

We already discussed non-blocking gates but the language makes it sound like it was limited to `config.toml`.
Since I haven't been touching that, I had always overlooked that section.

This change brings the blocking / non-blocking decision front and center.
To support this, the later sections focus more on mechanisms (the gate) rather than on what is being done (new syntax for `cargo-features`).

I also feel this makes the content more scannable.

This is adapted from what I did for `[lints]` (see #12148).
2024-01-16 23:07:24 +00:00
Ed Page 354e1989f8 doc(features): Highlight the non-blocking feature gating technique
We already discussed non-blocking gates but the language makes it sound
like it was limited to `config.toml`.
Since I haven't been touching that, I had always overlooked that
section.

This change brings the blocking / non-blocking decision front and
center.
To support this, the later sections focus more on mechanisms (the gate)
rather than on what is being done (new syntax for `cargo-features`).

I also feel this makes the content more scannable.

This is adapted from what I did for `[lints]` (see #12148).
2024-01-16 12:51:27 -06:00
bors 1cff2ee6b9 Auto merge of #13305 - linyihai:issue-13289, r=epage
doc: add a heading to highlight "How to find features enabled on dependencies"

### What does this PR try to resolve?

Maybe fixes https://github.com/rust-lang/cargo/issues/13289

Add a title to highlight "How to find features enabled on dependencies"?

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

### Additional information
2024-01-16 16:56:57 +00:00
Lin Yihai aa9a1cfa40 doc: add a heading to highlight "How to find features enabled on dependencies" 2024-01-16 23:52:52 +08:00
bors 350098d5ef Auto merge of #13250 - weihanglo:cargo-update, r=ehuss
fix(cargo-update): `--precise` accept arbitrary git revisions
2024-01-15 17:57:47 +00:00
bors fbf9251b4d Auto merge of #13257 - Kobzol:profile-strip-debuginfo, r=ehuss
Strip debuginfo when debuginfo is not requested

### What does this PR try to resolve?

This PR implements [this proposal](https://github.com/rust-lang/cargo/issues/4122#issuecomment-1868318860). It contains a detailed description of the change.

As a summary, this PR modifies Cargo so that if the user doesn't set `strip` explicitly, and debuginfo is not enabled for any package being compiled, Cargo will implicitly set `strip = "debuginfo"`, to strip pre-existing debuginfo coming from the standard library. This reduces the default size of release binaries considerably (~4.5 MiB => ~450 KiB for helloworld on Linux x64).

Perhaps we could only add the `-Cstrip` option for the leaf/root target (i.e., a binary), but cargo already passes `-Cstrip` to libraries if it's set by `[profile.<...>.package.<lib>]`, so it seems harmless.

Fixes: https://github.com/rust-lang/cargo/issues/4122

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

Best reviewed commit by commit. There is one commit that fixes an existing related test that was using wrong assertion.

### Additional information

The implementation of the deferred option was inspired by `DebugInfo`, which already uses a similar concept.

### Unresolved questions
Should we also do this on macOS by default? It [seems](https://github.com/rust-lang/cargo/issues/11641) that there can be some issues with `strip` there. If it doesn't work, it basically inhibits compilation in release mode, with no easy way to opt out (unless the user explicitly requests debuginfo, but that's not the same as the previous state).
2024-01-15 17:20:27 +00:00
bors d90d32199f Auto merge of #13301 - Amanieu:update-ahash, r=epage
Update ahash dependency to 0.8.7

Previous versions use the `stdsimd` nightly feature if it detects that it is available (on a nightly toolchain). This will stop working once rust-lang/rust#117372 is merged.
2024-01-15 16:47:50 +00:00
bors 6c9f33a909 Auto merge of #13298 - weihanglo:pkgid, r=epage
docs: add more links to pkgid spec chapter
2024-01-15 16:15:54 +00:00
bors 77f2da7b92 Auto merge of #12914 - epage:metadata, r=weihanglo
fix(metadata): Stabilize id format as PackageIDSpec

### What does this PR try to resolve?

For tools integrating with cargo, `cargo metadata` is the primary interface.  Limitations include:
-  There isn't an unambiguous way to map a package entry from `cargo metadata`  to a parameter to pass to other `cargo` commands.  An `id` field exists but it is documented as an opaque string, useful only for comparisons with other `id`s within the document.
- There isn't an unambiguous way of taking user parameters (`--package`) and mapping them to `cargo metadata` entries.  `cargo pkgid` could help but it returns a `PackageIdSpec` which doesn't exist within the `cargo metadata` output.

This attempts to solve these problems by switching the `id` field from `PackageId` to `PackageIdSpec` which is a [publicly documented format](https://doc.rust-lang.org/cargo/reference/pkgid-spec.html), can be generated by `cargo pkgid`, and is accepted by most commands via the `--package` flag.

As the `"id"` field is documented as opaque, this technically isn't a breaking change though people could be parsing it.

For `cargo_metadata` they do [use a new type that documents it as opaque but publicly expose the inner `String`](https://docs.rs/cargo_metadata/latest/cargo_metadata/struct.PackageId.html).  The `String` wasn't publicly exposed due to a request by users but instead their `PackageId` type replaced using `String`s in the API in oli-obk/cargo_metadata#59 with no indication given as to why the `String` was still exposed.  However, you'll note that before that PR, they had `WorkspaceMember` that parsed `PackageId`.  This was introduced in oli-obk/cargo_metadata#26 without a motivation given.

**Note that `PackageIdSpec` has multiple representation that might uniquely identify a package and we can return any one of them.**

Fixes #7267

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

### Additional information

cc `@oli-obk`
2024-01-15 15:45:36 +00:00
Amanieu d'Antras e0df99e196 Update ahash dependency to 0.8.7
Previous versions use the `stdsimd` nightly feature if it detects that
it is available (on a nightly toolchain). This will stop working once
rust-lang/rust#117372 is merged.
2024-01-15 15:40:08 +00:00
bors 19eb0f0b27 Auto merge of #13296 - eopb:precise-pre-release-flag, r=epage
Introduce `-Zprecise-pre-release` unstable flag

Tracking Issue: [#13290](https://github.com/rust-lang/cargo/issues/13290)

This change introduces the feature but does not yet attempt an implementation. The actual implementation will happen in future PRs.

r? `@epage`
2024-01-15 15:15:56 +00:00
Weihang Lo 7b8acb15c5
docs: add more links to pkgid spec chapter 2024-01-14 19:28:43 -05:00
Ethan Brierley c8ec94c765 Introduce -Zprecise-pre-release unstable flag
This change introduces the feature but does not yet attempt an implementation.
The actual implementation will happen in future PRs

r? @epage
2024-01-14 18:52:33 +00:00
bors 9d3473c727 Auto merge of #13292 - dtolnay-contrib:parentheses, r=weihanglo
Delete sentence about parentheses being unsupported in license

Parentheses have been supported by crates.io since 2 years ago.

- https://github.com/rust-lang/crates.io/pull/4257

Their functionality is tested by this test: 3acd63c1f3/tests/utils/license-test.js (L68-L79).

I think a separate test in Cargo is most likely not valuable because Cargo does not parse these license strings, they are just treated as `Option<String>`.

Here is an example of an extremely widely used package (147 million downloads) with parentheses in its license: https://crates.io/crates/unicode-ident.
2024-01-14 18:39:10 +00:00
bors d530b46da2 Auto merge of #13293 - dtolnay-contrib:homepage, r=weihanglo
Add guidance on setting homepage in manifest

Carried over from the Rust API Guidelines: https://rust-lang.github.io/api-guidelines/documentation.html#cargotoml-includes-all-common-metadata-c-metadata

This guidance has been in place since 6.5 years ago (350619f84e).
2024-01-14 17:47:22 +00:00
David Tolnay 7ccb4d3a79
Add guidance on setting homepage in manifest 2024-01-13 18:56:30 -08:00
David Tolnay c78b2ca1dd
Delete sentence about parentheses being unsupported in license 2024-01-13 18:48:28 -08:00
bors 92395d9010 Auto merge of #13236 - heisen-li:test, r=epage
Clarify the function of the test options

### What does this PR try to resolve?

Make the description of test options clearer.

from #10936
2024-01-12 22:20:03 +00:00
bors 84976cd699 Auto merge of #13287 - weihanglo:sort-summaries, r=Eh2406
fix(resolver): do not panic when sorting empty summaries
2024-01-12 15:55:43 +00:00
bors bf27f90f12 Auto merge of #13252 - connorworley:shallow_libgit2_fetches, r=weihanglo
Implementation of shallow libgit2 fetches behind an unstable flag

This is my first contribution, so guidance is appreciated.

Fixes #1171 by moving the `shallow-index` and `shallow-deps` aspects of `-Zgitoxide` to a new `-Zgit` unstable flag.

The only change in interaction with libgit2 happens in `src/cargo/sources/git/utils.rs`, where we set the depth fetch option if applicable.

Shallow fetch tests for gitoxide continue to pass, but libgit2 is harder to test as it silently ignores the depth option for local fetches. I would love any ideas on how to test it in a lightweight way or whether it's OK to wait for an upstream fix.
2024-01-12 15:18:17 +00:00
Connor Worley 426b9e3085 Update docs with tracking issue and note about consecutive fetches 2024-01-12 14:40:48 +09:00
Weihang Lo 6cee9bf72f
fix(resolver): do not panic when sorting empty summaries 2024-01-12 00:34:42 -05:00
Weihang Lo c677f73353
test(resolver): empty summaries passed in sort_summaries 2024-01-12 00:29:13 -05:00
bors 54fd66a51e Auto merge of #13284 - charmitro:output-format-doc-entry, r=weihanglo
Add documentation entry for unstable `--output-format` flag

This is a follow-up to #12252 adding a documentation entry for the newly supported unstable flag `--output-format`.
2024-01-11 21:51:16 +00:00
bors 269783715b Auto merge of #13272 - linyihai:cargo-add-public-manpage, r=epage
doc: add `public` info in `cargo-add` man page.

### What does this PR try to resolve?
follow up https://github.com/rust-lang/cargo/pull/13046
add `public/private` explanation for `cargo-add` in man page.

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

### Additional information

The help info would be like this

- `cargo help add`
```
        --public
           Mark the dependency as public.

           The dependency can be referenced in your library’s public API.

           Unstable (nightly-only) <https://doc.rust-lang.org/cargo/reference/unstable.html#public-dependency>

       --no-public
           Mark the dependency as private.

           While you can use the crate in your implementation, it cannot be referenced in your public API.

           Unstable (nightly-only) <https://doc.rust-lang.org/cargo/reference/unstable.html#public-dependency>
```
- `cargo add -h`
```
      --public               Mark the dependency as public (unstable)
      --no-public            Mark the dependency as private (unstable)
```

- `cargo add --help`
```
      --public
          Mark the dependency as public (unstable)

          The dependency can be referenced in your library's public API.

      --no-public
          Mark the dependency as private (unstable)

          While you can use the crate in your implementation, it cannot be referenced in your public API.
```
2024-01-11 21:13:02 +00:00
Charalampos Mitrodimas 40aa8b14b7 Add documentation entry for unstable --output-format flag
This is a follow-up to #12252.

Signed-off-by: Charalampos Mitrodimas <charmitro@posteo.net>
2024-01-11 22:46:06 +02:00
bors 55f6aeb020 Auto merge of #13286 - Manishearth:prereleases, r=epage
More docs on prerelease compat

We had some questions about semver compat of prereleases when discussing https://github.com/unicode-org/icu4x/issues/4445, figured I'd document our findings.
2024-01-11 20:12:57 +00:00
Manish Goregaokar 200e9f6e7f More docs on prerelease compat 2024-01-11 15:05:21 -05:00
bors f4e2eac630 Auto merge of #12252 - charmitro:master, r=weihanglo
Add unstable `--output-format` option to  `cargo rustdoc`

Add unstable `--output-format` option to "rustdoc"

We achieved this by:
* Handle `--output-format` argument, accepting `html` or `json`
* A new field `json` in `CompileMode::Doc`.
* If `json` is passed, we append the following in
   `prepare_rustdoc`:
  1. `-Zunstable-options`
  2. `--output-format=json`

Fixes #12103
2024-01-11 18:32:07 +00:00
Charalampos Mitrodimas 9276399342 Add unstable --output-format option to "rustdoc"
We achieved this by:
   * Handle `--output-format` argument, accepting `html` or `json`
   * If `json` is passed, we append the following in
   `prepare_rustdoc`:
     	1. `-Zunstable-options`
	2. `--output-format`

Fixes #12103

Signed-off-by: Charalampos Mitrodimas <charmitro@posteo.net>
2024-01-11 17:37:56 +02:00
Connor Worley 5eb2899415 Fix z_help test case 2024-01-11 17:10:51 +09:00
Connor Worley 0088121d21 Update error message about removed -Zgitoxide aspects 2024-01-11 17:08:21 +09:00
Connor Worley 64716fee99 Add dummy link to appease CI 2024-01-11 17:08:21 +09:00
Connor Worley a1559be493 Implementation of shallow libgit2 fetches behind an unstable flag 2024-01-11 17:08:21 +09:00
Lin Yihai f141c10bda doc: add public info in cargo-add man page. 2024-01-11 15:11:08 +08:00
bors 4eef543a4d Auto merge of #13172 - Muscraft:diagnostic-system, r=epage
feat: Add `rustc` style errors for manifest parsing

#12235 is tracking user control over warnings. One part of that is making `cargo`'s diagnostic system output messages in the style of `rustc`. To make it so that `cargo` doesn't have to manage a formatter and renderer, I decided to use [`annotate-snippets`](https://crates.io/crates/annotate-snippets), which matches `rustc`'s style well (at one time it was meant to be the formatted for `rustc`).

To get this work kicked off, it was suggested to me that we should start with styling manifest parsing errors, and that is what his PR does.

What manifest parsing errors look like after this change:
![image](https://github.com/rust-lang/cargo/assets/23045215/0eb388b9-8d72-48ad-84a9-585160995078)

---

Note: `cargo` does not currently match `rustc` in color (#12740), `rustc`  specifies their colors [here](740cea81d6/compiler/rustc_errors/src/lib.rs (L1755-L1768)) and [here](740cea81d6/compiler/rustc_errors/src/emitter.rs (L2689-L2723)). I used `annotate-snippets` default colors which match what `rustc` currently uses for colors. I did this as a stopgap while I work to unify the colors used between `rustc` and `cargo`.

---

Note: the error messages come directly from `toml` and can be quite long. It would be nice if we could put some of the message below the highlight but this would require changes to `toml`.
Example:
```
error: invalid type: integer `3`
 --> Cargo.toml:7:7
  |
7 | bar = 3
  |       ^ expected a version string like "0.9.8" or a detailed dependency like { version = "0.9.8" }
  |
```
2024-01-11 01:07:36 +00:00
bors 187d4cf35e Auto merge of #13273 - BD103:master, r=weihanglo
Document why `du` function uses mutex

### What does this PR try to resolve?

After closing #13253, it [was suggested](https://github.com/rust-lang/cargo/pull/13253#issuecomment-1883286035) to document why the `du` function uses a `Mutex` instead of an `AtomicU64`. This will prevent others from making the same mistake I did. :)

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

N/A

### Additional information

N/A
2024-01-10 14:19:06 +00:00
BD103 0a6fe230d6 fix: update lockfile 2024-01-10 08:09:55 -05:00
BD103 c832cdf068
bump: cargo-util to 0.2.10 2024-01-10 08:01:47 -05:00
bors 3e428a38a3 Auto merge of #13275 - weihanglo:iter-join, r=epage
refactor: replace `iter_join` with `itertools::join`
2024-01-09 20:46:36 +00:00
Weihang Lo cfc6e4b1d2
refactor: replace iter_join with itertools::join 2024-01-09 15:38:22 -05:00
bors 87b4cb2182 Auto merge of #13274 - weihanglo:unstable-features-doc, r=epage
docs(unstable): doc comments for items and fields
2024-01-09 18:05:02 +00:00
BD103 529130fe54
fix: missing word in comment
Co-authored-by: Weihang Lo <weihanglo@users.noreply.github.com>
2024-01-09 12:50:49 -05:00
Weihang Lo 4105a153d4
docs(unstable): doc comments for Features and Feature 2024-01-09 12:47:38 -05:00
Weihang Lo d0390c22b1
docs(unstable): doc comments for CliUnstable 2024-01-09 12:47:38 -05:00