19069 Commits

Author SHA1 Message Date
Ed Page
6da546c9e1 chore: Bump versions 2024-11-29 10:43:19 -06:00
renovate[bot]
1ec49b8947
chore(deps): update msrv 2024-11-29 03:54:45 +00:00
Eric Huss
81e0670ddd
fix(fix): Migrate cargo script manifests across editions (#14864)
### What does this PR try to resolve?

At this point it is unlikely for a script to be written for pre-2024
edition and migrated to 2024+ but this code is independent of Editions
so this means we have one less bug and are better prepared for the next
edition.

When we add `cargo fix` support for regular manifest warnings, we'll
need to take into account cargo scripts.

This is a part of #12207.

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

### Additional information

While looking for where the tests go, I found a couple places with a
hard coded latest-edition in test output and fixed it.
2024-11-27 20:05:19 +00:00
Ed Page
ed3947f2ef fix(fix): Migrate cargo script manifests across editions
At this point it is unlikely for a script to be written for pre-2024
edition and migrated to 2024+ but this code is independent of Editions
so this means we have one less bug and are better prepared for the next
edition.

When we add `cargo fix` support for regular manifest warnings, we'll
need to take into account cargo scripts.

This is a part of #12207.
2024-11-27 13:24:37 -06:00
Ed Page
a609028eae test(fix): Show cargo-script behavior 2024-11-27 13:18:34 -06:00
Ed Page
563b1a27b5 test: Harden against 2027(?) edition 2024-11-27 13:10:32 -06:00
Eric Huss
92de1a2944
feat(toml): Allow adding/removing from cargo scripts (#14857)
### What does this PR try to resolve?

This adds support for cargo script for more cargo commands and is a part
of #12207

Unfortunately, there is a double-warning for unspecified editions for
`cargo remove`. Rather than addressing that here, I'll be noting it in
the tracking issue.

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

### Additional information
2024-11-26 20:23:59 +00:00
Weihang Lo
10c255ad07
Add future-incompat warning against keywords in cfgs and add raw-idents (#14671)
### What does this PR try to resolve?

This PR tries to address this thread
https://github.com/rust-lang/cargo/pull/14649#discussion_r1790468829 in
#14649 regarding `cfg(true)`/`cfg(false)` (and keywords more generally)
which are wrongly accepted[^1] as ident.

To address this, this PR does two things:
1. it introduce a future-incompatibility warning against those (wrongly)
accepted keywords as ident
2. it add parsing for raw-idents (`r#true`) add suggest-it in the
warning

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

This PR should be reviewed commit-by-commit.
Tests are included in preliminary commits.

### Additional information

I added a new struct for representing `Ident`s which is rawness aware.
Which implied updating `cargo-platform` to `0.2.0` due to the API
changes.

r? @epage

[^1]:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=ccfb9c894dbf14e791c8ae7e4798efd0
2024-11-26 19:45:45 +00:00
Ed Page
c4a9e45519
test(build-std): download deps first (#14861)
### What does this PR try to resolve?

Download dependencies first,
So that we can assert the full output of `cargo test` without wildcard.

This regressed since #14850

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

CI passes.
2024-11-26 19:12:16 +00:00
Weihang Lo
47c2095b1d
test(build-std): download deps first
So that we can assert the full output of `cargo test` without wildcard
2024-11-26 13:39:36 -05:00
Ed Page
917e646a48
test(pgo): ensure PGO works (#14859)
### What does this PR try to resolve?

This is a regression test to prevent issues like #7416.

The test only run on Linux,
as other platforms have different requirements for PGO,
or emit different PGO function missing warnings.

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

Not sure how brittle it is. We can optionally run it only on Cargo's CI?

cc #14830
2024-11-26 18:25:05 +00:00
Ed Page
26844a3331 feat(toml): Allow adding/removing from cargo scripts 2024-11-26 12:23:48 -06:00
Ed Page
89d1fafbfd refactor(toml): Expose ScriptSource for reuse 2024-11-26 12:23:48 -06:00
Ed Page
a0ccb13cb1 refactor(toml): Switch to using accessors with ScriptSource 2024-11-26 12:23:48 -06:00
Ed Page
e82a4beaed refactor(toml): Move the parse fn onto ScriptSource 2024-11-26 12:23:48 -06:00
Ed Page
7ec1867ba0 refactor(toml): Give more specific name to ScriptSource 2024-11-26 12:23:48 -06:00
Ed Page
0b99414479 refactor(remove): Consolidate how we mutate manifests
This will make it easier to add cargo script support
2024-11-26 12:23:48 -06:00
Ed Page
6ebd1aec17 refactor(remove): Clarify variable names 2024-11-26 12:23:48 -06:00
Ed Page
589d09917c test(script): Verify manifest modification commands 2024-11-26 12:23:48 -06:00
Ed Page
e0477a3869 test(remove): Show what happens with last dep in a table 2024-11-26 12:23:48 -06:00
Weihang Lo
7aa570ac7d
git-fetch-with-cli: Set GIT_DIR for bare repository compatibility (#14860)
When using `net.git-fetch-with-cli = true` , Cargo fails to clone the
git repository into the cache because `safe.bareRepository` defaults to
`explicit`. This results in an error stating that a bare repository
cannot be used.

This patch sets the `GIT_DIR` environment variable to the correct
repository path instead of removing it. This ensures that Git uses the
correct repository directory and avoids the "cannot use bare repository"
error.

Fixes #14758
2024-11-26 17:00:21 +00:00
Charalampos Mitrodimas
b38d06d6d0 git-fetch-with-cli: Set GIT_DIR for bare repository compatibility
When using `net.git-fetch-with-cli = true` , Cargo fails to clone the
git repository into the cache because `safe.bareRepository` defaults
to `explicit`. This results in an error stating that a bare repository
cannot be used.

This patch sets the `GIT_DIR` environment variable to the correct
repository path instead of removing it. This ensures that Git uses the
correct repository directory and avoids the "cannot use bare
repository" error.

Fixes #14758

Signed-off-by: Charalampos Mitrodimas <charmitro@posteo.net>
2024-11-26 18:28:20 +02:00
Eric Huss
8ba3ec2895
fix(build-std): always link to std when testing proc-macros (#14850)
### What does this PR try to resolve?

Fixes #14735

https://github.com/rust-lang/rust/pull/131188 removes libstd.so from
sysroot so `cargo test -Zbuild-std` no longer links to it. That results
in a "Library not loaded: @rpath/libstd-[HASH].dylib" when testing a
proc macro.

This is a pretty niche use case, though it can be easily reproduced by
running `cargo test -Zbuild-std` in any proc-macro package. Like in
[serde-rs/serde](b9dbfcb4ac)
running it would fail.

This patch adds a special case that if it is `cargo run/test` against a
proc-macro, fill in std dynamic library search path for it.

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

```
CARGO_RUN_BUILD_STD_TESTS=1 cargo +nightly t --test build-std test_proc_macro
```

or

```
git clone https://github.com/serde-rs/serde
cd serde
git switch -d b9dbfcb4ac3b7a663d9efc6eb1387c62302a6fb4
cargo +nightly t --test build-std
```

### Additional information
2024-11-26 16:26:51 +00:00
Weihang Lo
02e25d5608
test(pgo): ensure PGO works
This is a regression test to prevent issues like #7416.

The test only run on Linux,
as other platforms have different requirements for PGO,
or emit different PGO function missing warnings.
2024-11-26 10:20:53 -05:00
Urgau
e2028d4bc2 Adjust future-incompatibility cfg keyword with raw-idents in cfgs 2024-11-25 22:01:44 +01:00
Urgau
9450706a03 Add support for raw-idents in cfgs 2024-11-25 22:01:44 +01:00
Urgau
3c3bfb0310 Add preliminary test for raw-idents in cfgs 2024-11-25 21:51:19 +01:00
Urgau
4946828211 Add future-incompatibility warning against some keyword-as-ident 2024-11-25 21:51:19 +01:00
Urgau
ac10b55e72 Add preliminary test for keywords in cfgs 2024-11-25 21:51:19 +01:00
Urgau
80dde854b4 Bump cargo-platform to 0.2.0 in preparation for cfg(<true/false>) 2024-11-25 21:51:18 +01:00
Eric Huss
4c39aaff66
feat: Stabilize Edition 2024 (#14828)
### What does this PR try to resolve?

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

### Additional information
2024-11-25 16:36:17 +00:00
Ed Page
81411ec545 feat: Stabilize Edition 2024 2024-11-25 09:27:09 -06:00
Eric Huss
52c62ee9fe Update edition stabilization docs
Updating `first_version` is another thing that needs to be checked when
updating.
2024-11-25 09:22:32 -06:00
Ed Page
5306252c70 test(msrv): Workaround Edition 2024 stabilization
With 2024 stabilized, there will be a "first supported" version which is
above the versions used in tests.

In particular, for the `cargo install` test, we can't test the scenario
until a couple of versions have passed.
We have to rely on Edition 2024 changing ony resolver v3 which is
already covered.
2024-11-25 09:20:54 -06:00
Weihang Lo
f1767d0a4b
Improve error handling when PathSource is relative (#14854)
When editing dependencies with cargo, if a relative PathSource is
supplied cargo panics with "both paths are absolute". This is the
opposite of what's actually wrong leading to confusion.

Instead, use the same error formatting we use in other diff_paths calls
and return that error instead of panicking.
2024-11-24 14:40:31 +00:00
morganamilo
6b74183d8a
Improve error handling when PathSource is relative
When editing dependencies with cargo, if a relative PathSource is
supplied cargo panics with "both paths are absolute". This is the
opposite of what's actually wrong leading to confusion.

This commit changes the error message to say what is actually wrong.
2024-11-24 14:05:49 +00:00
Ed Page
9bda8808fb
test: address test output nondeterminism (#14855)
### What does this PR try to resolve?

Some nondeterminism test output was found in other pull requestss

The first one was found in
<https://github.com/rust-lang/cargo/pull/14854>

The second one was found in
https://github.com/rust-lang/cargo/pull/14853

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

CI passes.
2024-11-23 16:33:37 +00:00
Weihang Lo
ddc63f2575
test: simplify rebuild tests to address nondeterminism
```
---- freshness::rebuild_tests_if_lib_changes stdout ----
running `/home/runner/work/cargo/cargo/target/debug/cargo build`
running `/home/runner/work/cargo/cargo/target/debug/cargo test`
running `/home/runner/work/cargo/cargo/target/debug/cargo build -v`
running `/home/runner/work/cargo/cargo/target/debug/cargo test -v`
error: test failed, to rerun pass `-p cargo --test testsuite`
thread 'freshness::rebuild_tests_if_lib_changes' panicked at tests/testsuite/freshness.rs:633:10:

---- expected: tests/testsuite/freshness.rs:623:27
++++ actual:   stderr
   1    1 | [DIRTY] foo v0.0.1 ([ROOT]/foo): the dependency foo was rebuilt ([TIME_DIFF_AFTER_LAST_BUILD])
   2    2 | [COMPILING] foo v0.0.1 ([ROOT]/foo)
   3    3 | [RUNNING] `rustc --crate-name foo [..]
   4      - [RUNNING] `rustc --crate-name foo [..]
   5    4 | error[E0425]: cannot find function `foo` in crate `foo`
        5 +  --> tests/foo.rs:4:34
   6    6 | ...
   7    7 | [ERROR] could not compile `foo` (test "foo") due to 1 previous error
   8    8 | ...∅
```
2024-11-23 11:05:15 -05:00
Weihang Lo
efbb9ab9cc
chore: move supports-unicode to workspace deps (#14853)
We should have a lint for it :)
2024-11-23 15:55:55 +00:00
Weihang Lo
d8a2a61303
test: switch to unordered assertions
This was caused by rust-lang/cargo@ffe59de494

```
---- expected: tests/testsuite/registry_overlay.rs:246:27
++++ actual:   stderr
   1    1 | [UPDATING] `sparse+http://127.0.0.1:[..]/index/` index
   2    2 | [LOCKING] 3 packages to latest compatible versions
   3    3 | [ADDING] workspace-package v0.0.1 (available: v0.1.1)
   4    4 | [DOWNLOADING] crates ...
   5    5 | [UNPACKING] workspace-package v0.1.1 (registry `[ROOT]/alternative-registry`)
   6      - [DOWNLOADED] registry-package v0.1.0 (registry `sparse+http://127.0.0.1:[..]/index/`)
   7      - [DOWNLOADED] workspace-package v0.0.1 (registry `sparse+http://127.0.0.1:[..]/index/`)
        6 + [DOWNLOADED] workspace-package v0.0.1 (registry `sparse+http://127.0.0.1:51512/index/`)
        7 + [DOWNLOADED] registry-package v0.1.0 (registry `sparse+http://127.0.0.1:51512/index/`)
   8    8 | [CHECKING] workspace-package v0.1.1
   9    9 | [CHECKING] workspace-package v0.0.1
  10   10 | [CHECKING] registry-package v0.1.0
  11   11 | [CHECKING] foo v0.0.1 ([ROOT]/foo)
  12   12 | [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
```
2024-11-23 10:20:59 -05:00
Weihang Lo
ceaaab39f0
chore: move supports-unicode to workspace deps 2024-11-22 17:27:43 -05:00
Weihang Lo
4527567c9f
fix(build-std): always link to std when testing/running proc-macros 2024-11-22 00:01:14 -05:00
Weihang Lo
33e6b331c8
test(build-std): shows that proc macro unittest fails
This starts failing since https://github.com/rust-lang/rust/pull/131188
2024-11-21 23:57:51 -05:00
Weihang Lo
88edf01fe3
Check build target supports std when building with -Zbuild-std=std (#14183)
**What does this PR try to resolve?**

Ensures that Cargo first verifies whether a given target supports
building the standard library when the `-Zbuild-std=std` option is
passed to Cargo ([see issue
here](https://github.com/rust-lang/wg-cargo-std-aware/issues/87)). This
information can be obtained by querying `rustc
--print=target-spec-json`. The target spec "metadata" contains an
`Option<bool>` determining whether the target supports building std.

In the case this value is `false`, cargo will stop the build. This
avoids the numerous "use of unstable library" errors, giving a cleaner,
and simpler, "building std is not supported on this target".

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

It can be manually tested by running `cargo build --target <target>
-Zbuild-std=std`. If a target who's target-spec marks std as false is
passed, cargo will exit. This works with multiple `--target`'s, and if
any of them don't support std, cargo will exit.

**Additional Information**

This change relies on two things:
* The target-spec metadata in rustc needs to be filled out. Currently,
most fields are None, which is treated as OK with this change. Meaning
this can be merged before the rustc changes.
* The new test case added with this change will fail without at least
`aarch64-unknown-none` having it's target-spec metadata completed.
* Some targets have std support marked as "?". If this state is properly
represented in the target-spec in the future, it needs to be determined
whether this is allowed, so the build can continue, or whether it fails.
2024-11-22 01:31:41 +00:00
Weihang Lo
e444425d4e
fix(publish): Allow dry-run of a non-bumped workspace (#14847)
### What does this PR try to resolve?

A dry-run release process won't be bumping the versions, making it so it
can't do a dry-run publish because the local/remote registries will
collide. This switches it to give the local registry precedence over the
remote registry to make the dry-run release process work.

Fixes #14789

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

### Additional information
2024-11-21 22:22:48 +00:00
Weihang Lo
81848c3c5e
test: Switch from 'exec_with_output' to 'run' (#14848)
### What does this PR try to resolve?

This is a follow up to #14846 which changed `run` to return the
`RawOutput`.

Reasons I didn't "update" some code to the new `run` return value
- We were actually using `ProcessBuilder::exec_with_output` and I didn't
want to disentangle what it would take to switch to `Execs`
- We did processing on the `Result` and I didn't want to check how that
could be updated

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

### Additional information
2024-11-21 21:14:22 +00:00
Ed Page
55350fc670 test: Switch from 'exec_with_output' to 'run'
This is a follow up to #14846 which changed `run` to return the
`RawOutput`.

Reasons I didn't "update" some code to the new `run` return value
- We were actually using `ProcessBuilder::exec_with_output` and I didn't
  want to disentangle what it would take to switch to `Execs`
- We did processing on the `Result` and I didn't want to check how that
  could be updated
2024-11-21 13:48:27 -06:00
Weihang Lo
dfcfa4481a
test(rustflags): Verify -Cmetadata directly, not through -Cextra-filename (#14846)
### What does this PR try to resolve?

This unblocks experimenting with having these diverge for #8716

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

### Additional information
2024-11-21 19:22:48 +00:00
Ed Page
0b10d6f368 test(rustflags): Verify -Cmetadata directly, not through -Cextra-filename
This unblocks experimenting with having these diverge for #8716
2024-11-21 12:48:04 -06:00
Ed Page
ad23d73fae fix(publish): Allow dry-run of a non-bumped workspace
Fixes #14789
2024-11-21 09:48:26 -06:00