Commit graph

5723 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
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 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 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
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
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 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 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
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
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 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 88599985e9 Auto merge of #13269 - weihanglo:zhelp, r=epage
feat(cli): add colors to `-Zhelp` console output
2024-01-09 02:57:19 +00:00
Weihang Lo dbfe4277d3
test: loop over aliases to asser -Zhelp output 2024-01-08 21:34:07 -05:00
Weihang Lo 8fee74d47b
refactor(cli): tweak to align existing style 2024-01-08 21:33:12 -05:00
Weihang Lo 3d4407dcb9
test(cli): snapshot test for -Z help 2024-01-08 21:33:11 -05:00
Ed Page 62eab55ed2 refactor(toml): Make it more obvious to update package-dependent fields
Inspired by my having forgotten to add `[lints]` to the if sequence.
Previously, we added a comment to suggest this but the further the code
is, the harder it is to track.

I considered a custom `Deserialize` impl, possibly through a new type,
that would error.
This would be the more "pure" solution.
Unfortunately, this would also have worse errors because the errors
would be reported to the `Deserializer` at the document-level, rather
than directly on the individual fields.
Well, we don't do on individual fields now but it is something we will
soon be exploring.
2024-01-08 15:34:38 -06:00
bors 0c98d6ec3a Auto merge of #13204 - hi-rustin:rustin-patch-test-out-dir, r=ehuss
fix: set OUT_DIR for all units with build scripts
2024-01-08 17:45:14 +00:00
Ed Page 6e86530ae2 fix(manifest): Provide unused key warnings for lints table
The use of `flatten` was getting in the way of `serde_ignored`.
A common workaround is to add our own `unused` tracking but that would
cause duplicates with `workspace.lints` (or we'd just ignore it).

Since the manual deserializer was relatively simple, I went that route.

Fixes #12917
2024-01-08 09:12:46 -06:00
Ed Page 4760ef7822 test(lints): Verify we can't un-inherit 2024-01-08 08:49:04 -06:00
Ed Page ef6954cd01 test(lints): Check unused key status 2024-01-08 08:27:34 -06:00
Ed Page 96fa278540 test(manifest): Verify we warn on unused workspace.package fields
Inspired by #13258
2024-01-08 09:21:31 -06:00
hi-rustin 6739c7e95e fix: set OUT_DIR for all units with build scripts
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2024-01-08 20:59:18 +08:00
hi-rustin 8bba4f48c4 test: include a case for setting OUT_DIR
Signed-off-by: hi-rustin <rustin.liu@gmail.com>

test: remove the env set by Cargo

Signed-off-by: hi-rustin <rustin.liu@gmail.com>

Fix

Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2024-01-08 20:58:52 +08:00
Jakub Beránek e954099394
Update existing tests 2024-01-07 09:48:02 +01:00
Jakub Beránek af46bbd264
Add tests 2024-01-07 09:48:02 +01:00
Jakub Beránek 872aa8f4f7
Fix existing test 2024-01-07 09:48:02 +01:00
heisen-li 5023f20c4c delete --lib unit test description 2024-01-05 11:40:33 +08:00
Weihang Lo e6f2dfd452
test(cargo-update): verify a oid-like tag triggers a re-fetch 2024-01-04 17:43:19 -05:00
Weihang Lo 2734097f12
fix(git): represent deferred and resolved revision with an enum
`cargo update --precise` might pass in any arbitrary Git reference,
and `git2::Oid::from_str` would always zero-pad the given str if it is
not a full SHA hex string.

This introduces an enum `Revision` to represent `locked_rev`
that is either deferred or resolved to an actual object ID.
When `locked_rev` is a short ID or any other Git reference,
Cargo first performs a Git fetch to resolve it (without --offline),
and then locks it to an actual commit object ID.
2024-01-04 16:32:58 -05:00
Weihang Lo 4be3614264
test(cargo-update): --precise not work with tag or short id
This demonstrates the bug described in 13188
2024-01-04 10:56:55 -05:00
bjorn3 f26e2fe1da Deprecate rustc plugin support in cargo
It has been removed entirely from rustc itself already
2024-01-04 13:17:50 +01:00
Lin Yihai 35d5fae5b6 test: support publish package with a public field. 2024-01-03 04:08:59 +08:00
Eric Huss e7eaa51909 cargo fix: Call rustc fewer times.
This changes `cargo fix` so that it keeps track of the output so that it
doesn't need to run the final "show the output" step.
2024-01-02 15:03:06 -08:00
Eric Huss 8ffd9cd86f Add tests validating the sequence for cargo fix.
This adds a set of tests which validates various edge cases around how
`cargo fix` works in terms of calling `rustc` multiple times. This uses
a replacement of `rustc` so it doesn't depend on the behavior of rustc
itself which is not always stable.
2024-01-02 14:54:41 -08:00
heisen-li 9cf0936121 Clarify the function of the test flag 2024-01-02 16:57:06 +08:00
Eric Huss 1ef1b7e313 Fix fix::fix_in_dependency to not rely on rustc 2023-12-29 12:56:23 -08:00
bors 4f70d1781a Auto merge of #13213 - stupendoussuperpowers:mulpack-features-git, r=epage
`cargo add` - fix for adding features from repository with multiple packages.

Fixes #13121

As discussed in the issue, when using `cargo add` to add a package with features from a git repository from one of it's members, the command might fail due to improper target for querying for said features.

This PR adds a test for this edge-case where we expect it to fail with current code. It also adds a fix for this, and updates the test to expect success.

While populating available features, the current code does a `Fuzzy` search which might lead to searching for features in a wrong member package. If we change it to an `Exact` query, we get back the proper member to search within.
2023-12-29 18:46:27 +00:00
cui fliter 5c7fbd80f2 Remove repetitive words
Signed-off-by: cui fliter <imcusg@gmail.com>
2023-12-29 13:55:24 +08:00
sanchit e46d80e24e Fixes #13121: Use Exact query during populating features. Update test
fix target output
2023-12-29 10:03:54 +05:30
sanchit 61f6248a07 add test expecting failure: adding features from git repo w multiple packages 2023-12-29 04:54:50 +05:30
Weihang Lo 48cffc6729
fix(cargo-install): clarify --path is installation source 2023-12-26 10:42:57 -05:00
Weihang Lo 14ef091bd0
fix(cargo-install): remove imprecise install root descriptions 2023-12-26 10:42:57 -05:00
hi-rustin dec9e8cc1b Add tests for msrv check
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-12-23 13:24:53 +08:00
hi-rustin eac79ec152 Update other docs to use cargo:: syntax
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-12-23 13:17:55 +08:00
hi-rustin ed9dc44f47 Update other tests to use cargo:: syntax
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-12-23 13:17:55 +08:00
hi-rustin 9eeffbf0d7 Add some syntax tests
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-12-23 13:17:55 +08:00