Commit graph

3910 commits

Author SHA1 Message Date
Ed Page
bd6b4a9b14 fix(toml): Improve map/sequence error message
This is a follow up to #13375
2024-01-31 10:42:58 -06:00
Ed Page
1c05d412af fix(diagnostic): Don't panic on empty spans
There is another level to this bug where we better point to where the
error occurs.
2024-01-31 09:11:12 -06:00
Ed Page
f2a4a3e88b test(diagnostic): Show panic 2024-01-31 08:48:53 -06:00
bors
f8c152df3b Auto merge of #12852 - weihanglo:lockfile-v4, r=ehuss
feat: stabilize lockfile v4
2024-01-30 19:48:25 +00:00
bors
251d437564 Auto merge of #13367 - epage:new-creating, r=weihanglo
fix(new): Print a 'Creating', rather than 'Created' status

### What does this PR try to resolve?

This has bothered me about `cargo new` and `cargo init` for a while that
the output is read backwards, for example:
```diff
--- i/tests/testsuite/cargo_init/path_contains_separator/stderr.log
+++ w/tests/testsuite/cargo_init/path_contains_separator/stderr.log
`@@` -1,3 +1,3 `@@`
+    Creating binary (application) package
 warning: the path `[ROOT]/case/test:ing/.` contains invalid PATH characters (usually `:`, `;`, or `"`)
 It is recommended to use a different name to avoid problems.
-     Created binary (application) package
```

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

### Additional information
2024-01-30 18:25:27 +00:00
bors
8ed4cb1ec8 Auto merge of #13335 - hi-rustin:rustin-patch-same-name, r=weihanglo
fix: use spec id instead of name to match package
2024-01-30 13:25:13 +00:00
hi-rustin
7a13864f29 test: add a cannot find case
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2024-01-30 20:55:50 +08:00
hi-rustin
240020d546 fix: use spec id instead of name to match package
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2024-01-30 20:55:40 +08:00
Ed Page
db54c040ae fix(new): Print a 'Creating', rather than 'Created' status
This has bothered me about `cargo new` and `cargo init` for a while that
the output is read backwards, for example:
```diff
--- i/tests/testsuite/cargo_init/path_contains_separator/stderr.log
+++ w/tests/testsuite/cargo_init/path_contains_separator/stderr.log
@@ -1,3 +1,3 @@
+    Creating binary (application) package
 warning: the path `[ROOT]/case/test:ing/.` contains invalid PATH characters (usually `:`, `;`, or `"`)
 It is recommended to use a different name to avoid problems.
-     Created binary (application) package
```
2024-01-29 15:29:10 -06:00
bors
3e1a2ddc3e Auto merge of #13333 - weihanglo:precise-yank, r=Eh2406
feat(cargo-update): `--precise` to allow yanked versions
2024-01-29 21:25:44 +00:00
Weihang Lo
caeaaa529c
fix(cargo-update): once warn once for --precise <yanked>
This also tweaks the error message a bit.
2024-01-29 16:00:01 -05:00
Weihang Lo
bc5da432ef
test(cargo-update): verify `--precise <yanked> warns twice
This is not ideal and we need to track selected yanked versions.
2024-01-29 15:50:56 -05:00
Weihang Lo
f1aefdd9f7
test: data layout fix for x86_64-unknown-none-gnu 2024-01-28 15:52:14 -05:00
Ed Page
6eb2ddea20 fix(config): Deprecate non-extension files
In #7295 (released in 1.39), we said we'd want to warn on use of
`.cargo/config` after about 6 months.  Over 4 years later, we are now
getting that warning.

 This is important for addressing user confusion, like in
https://www.reddit.com/r/rust/comments/19fd5q2/cargoconfig/
2024-01-26 15:16:11 -06:00
Ed Page
a1525bca4d test(config): Improve failure output 2024-01-26 15:16:05 -06:00
Ed Page
7e8521162b test(config): Verify output for extension-less 2024-01-26 15:08:48 -06:00
Ed Page
675224b3a0 test(config): Shift to config.toml 2024-01-26 13:40:46 -06:00
Ed Page
51b1200572 fix(cli): Improve bad script errors 2024-01-25 13:28:43 -06:00
Ed Page
2a7e5c05ed test(script): Show existing non-existent behavior 2024-01-25 13:28:43 -06:00
Ed Page
c377c2aae6 test(script): Avoid common subcommand name 2024-01-25 13:28:30 -06:00
Ed Page
c51ea384b0 fix(cli): Suggest fix for scripts that look like external subcommands 2024-01-25 11:28:48 -06:00
bestgopher
f30987fc76
Update stdout.log 2024-01-25 16:31:22 +08:00
Jakub Beránek
262e31e9fd
Fix typo in test 2024-01-24 10:07:46 +01:00
hi-rustin
aa6444734d test: add a case for running binary with same name as dependency
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2024-01-22 21:06:32 +08:00
Weihang Lo
3f2f4ed29b
feat(cargo-update): --precise to allow yanked versions 2024-01-21 20:14:24 -05:00
Weihang Lo
4f1e41ebe3
test(update): demonstrate not able to update --precise <yanked> 2024-01-21 14:45:35 -05:00
bors
7bb7b53955 Auto merge of #12776 - weihanglo:jobserver, r=ehuss
feat: inherit jobserver from env for all kinds of runner
2024-01-20 00:15:32 +00:00
Weihang Lo
678f3ff487
feat: inherit jobserver from env for all kinds of runner
External subcommands are already able to inherit the jobserver from
env since #10511. However, users reported that they've expected
`cargo run` to behave the same as external subcommands.

A popular example "cargo-xtask" pattern is used as scripting to run
arbitrary tasks. Users may want to invoke `cargo run` from Make and
expect some parallelism. This PR provides such an ability to the
general `target.<...>.runner`, which affects `cargo test`,
`cargo bench`, and `cargo run`.

Note that this PR doesn't create any jobserver client if there is no
existing jobserver from the environment. Nor `-j`/`--jobs` would create
a new client. Reasons for this decision:

* There might be crates don't want the jobserver to pollute their
  file descriptors, although they might be rare
* Creating a jobsever driver with the new FIFO named pipe style is not
  yet supported as of `jobserver@0.1.26`. Once we can create a named
  pipe-based jobserver, it will be less risky and inheritance by
  default can be implemented.
2024-01-19 18:36:35 -05:00
bors
c22cc7bb8b Auto merge of #13210 - weihanglo:remap-rules, r=epage
fix(trim-paths): remap common prefix only
2024-01-19 21:31:41 +00:00
bors
63f4af9c51 Auto merge of #13325 - kanru:issue13303-output-generated-json, r=weihanglo
fix(cargo-rustdoc): use same path by output format logic everywhere
2024-01-19 01:54:10 +00:00
Weihang Lo
ac1dc0bb99
test: verify runner doesn't inherit jobserver 2024-01-18 20:24:25 -05:00
Kan-Ru Chen
4160441245
fix(cargo-rustdoc): use same path by output format logic everywhere 2024-01-19 08:42:48 +08:00
Weihang Lo
a62a3c65dc
test: extract making make exectuable to fn 2024-01-18 17:21:04 -05:00
Weihang Lo
eb9e3778dd
test(pkgid): keep package ID format in sync
* Package ID specifications
* machine-readable message via `--message-format=json`
* `cargo metadata` output
2024-01-18 14:05:57 -05:00
bors
9574120bf0 Auto merge of #13316 - Urgau:check-cfg-zero-features-2, r=epage
Go back to passing an empty `values()` when no features are declared

This PR is basically a revert of https://github.com/rust-lang/cargo/pull/13011, which made the `--check-cfg` invocation be `cfg()` when no features are declared instead of `cfg(feature, values())` since it meant declaring that the config `feature` were to be available in this form: `#[cfg(feature)]`, which is not the case.

Thankfully after some brainstorming, I [proposed](https://github.com/rust-lang/rust/pull/119930) changing the behavior of empty `values()` in `rustc` to no longer imply the _none_ value and simply create an empty set of expected values. 😃

For Cargo, always using `cfg(feature, values(...))` means that the config `feature` is always expected, regardless of the number of features. This makes the warning better, as it will now always be `unexpected config value` (instead of `unexpected config name`). 🎉

Fixes https://github.com/rust-lang/cargo/pull/13011#issuecomment-1819427800 as well as the concern in the [tracking issue](https://github.com/rust-lang/cargo/issues/10554).

r? `@epage`
2024-01-18 13:33:11 +00:00
Urgau
fecb8ff0c8 Go back to passing an empty values() when no features are declared
See https://github.com/rust-lang/rust/pull/119930
2024-01-18 09:45:09 +01:00
Weihang Lo
637b5d1eae
fix(--package): accept ? if it's a valid pkgid spec
Previously if a value from `--package` flag contains `?`, Cargo
considered it as a glob pattern. However, staring from 12933 the
Package Id Spec has been extended to accept `?` for git sources.
This PR adjust accordingly to accept `?` from `--package` flag
when it is a valid Package Id Spec.
2024-01-18 00:45:35 -05:00
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