192 Commits

Author SHA1 Message Date
Eric Huss
1ce8023626 Rustfmt 2024 2025-07-05 19:50:36 -07:00
Joe Neeman
340a4f9bbd Add a dry-run packaging mode that munges checksums 2025-06-27 14:48:04 -05:00
Joe Neeman
95e961b4a0 Add a test showing the changed checksum. 2025-06-27 13:49:14 -05:00
Ed Page
4ac865d3d7
Rework cargo-test-support & testsuite to use CARGO_BIN_EXE_* for Cargo (#15692)
### What does this PR try to resolve?

This PR reworks `cargo-test-support` and `testsuite` to use Snapbox's
[`cargo_bin!()`](https://docs.rs/snapbox/latest/snapbox/cmd/macro.cargo_bin.html)
instead of
[`cargo_bin()`](https://docs.rs/snapbox/latest/snapbox/cmd/fn.cargo_bin.html)
which makes assumptions about the structure of Cargo's build directory.
`cargo_bin!()` uses `CARGO_BIN_EXE_*` for locating the `cargo` binary
which should be more resilient to directory/layout changes.

Linking a relevant Zulip discussion
[here](https://rust-lang.zulipchat.com/#narrow/channel/246057-t-cargo/topic/cargo_bin_exe.20and.20tests/with/513638220)[#t-cargo
> cargo_bin_exe and
tests](https://rust-lang.zulipchat.com/#narrow/channel/246057-t-cargo/topic/cargo_bin_exe.20and.20tests/with/513638220)

As shown in that link, we could make these variables available at
runtime and not need to do this. However, `cargo-test-support`, as an
API, is a bit weird in that it is baking in support for one specific
binary. This can be confusing for callers and makes it more annoying for
callers provide their own `fn cargo`, e.g. see crate-ci/cargo-fixit#7

### Implementation Notes

`cargo_bin!()` only works when being called from the `testsuite` as it's
only set when executing integration tests and `cargo-test-support` is a
regular crate.
To make this change, I introduced an extension trait `CargoProjectExt`
in `testsuite` for running `.cargo()` and implemented it on `Project`.

In `cargo-test-support` other functionality relies on `.cargo()` so
these also needed to be moved to `testsuite`
*
[`src/tools.rs`](https://github.com/rust-lang/cargo/blob/master/crates/cargo-test-support/src/tools.rs)
* Parts
[`src/cross_compile`](https://github.com/rust-lang/cargo/blob/master/crates/cargo-test-support/src/cross_compile.rs)
* I had to split this up unfortunately, as `disabled()` requires running
Cargo to check if we should disable cross compile tests.
* Other fns in `cross_compile` are used in `cargo-test-support` so
moving everything to `testsuite` would have ended up requiring moving
many things to test suite.

### How to test and review this PR?

I'd definitely recommend reviewing commit by commit.
There are a lot of diffs due to the nature of reorganizing things.
I did my best to split things things into smaller PRs but they still
contain a lot of `use` statement diffs.

r? @epage
2025-06-26 15:21:51 +00:00
motorailgun
8f4ae79cb5 fix: Expand error messages around path dependency on cargo package and cargo publish 2025-06-26 02:53:54 +00:00
Ross Sullivan
92d9a94d02
chore: Migrated testsuite to testsuite::prelude 2025-06-25 22:37:24 +09:00
Eric Huss
9e307b180c Update "time out" to "timeout"
This read a little awkwardly to me. "time out" is a verb, but normally a
noun follows "due to".
2025-06-05 07:24:41 -07:00
Ed Page
2e1f971c43 fix(publish): Don't tell people to ctrl-c without knowing consequences
Fixes #15005
2025-06-04 20:00:19 -05:00
Ed Page
f0161607fb refactor(publish): Remove manual package list 2025-06-04 19:54:35 -05:00
Ed Page
355bc56244 fix(publish): Remove quotes around packages
These aren't there elsewhere
2025-06-04 19:54:27 -05:00
Ed Page
ba789f04c7 fix(publish): Pluralize the wait message 2025-06-04 19:53:42 -05:00
Ed Page
0d391bd86c test(publish): Make package_selection tests consistent 2025-06-03 19:46:33 -05:00
Ed Page
103b13d858 test(publish): Split package_selection into nightly/stable 2025-06-03 19:45:19 -05:00
Ed Page
6061553bf1 test(publish): Use proper registry for workspace tests
On stabilization of `-Zpackage-workspace`, these will start passing and
will need a full registry
2025-06-03 19:42:40 -05:00
Weihang Lo
090dcfe9af
fix(publish): better message when nothing to publish
This doesn't need to be an hard error because missing
publish for the entire worspace should be a fairly visible.
However, this is open for future to configure via Cargo lint system.
2025-05-14 01:22:30 -04:00
Weihang Lo
4f7494c4ec
feat(publish): workspace publish skips publish=false
This changes how cargo-publish works with the unstable
`-Zpackage-workspace` feature.

Before this, when publishing the entire workspace,
like `cargo publish --workspace`,
if there is a package with `package.pulibsh=false,
it'll fail the entire publish process.

After this, when `--workspace` is passed,
or when publishing the virtual workspace,
the intent is more like “publish all publishable in this workspace”,
so skip `publish=false` packages and proceed to publish others.

The new overall behavior looks like this:

- `cargo publish` (inside a `package.publish = false` package): error
- `cargo publish -p publishable -p unpublishable`: error
- `cargo publish --workspace`: skips `package.publish = false

See https://github.com/rust-lang/cargo/issues/15006#issuecomment-2847660911
2025-05-14 01:22:29 -04:00
Weihang Lo
2421496c92
test(publish): prepare tests for skipping unpublishable
For `-Zpackage-workspace`.
2025-05-14 01:08:22 -04:00
Ed Page
e78a8a19db fix: Align new help messages with their error 2025-02-04 10:46:09 -06:00
Ed Page
5408bd9f52 fix: Update generic 'did you meann' reports to not say that 2025-02-03 13:07:47 -06:00
Ed Page
1eafdb2656 fix(publish): Report all unpublishable packages
I didn't extend this to multiple packages restricted to specific
registries.
It seems less likely to be a problem and more complex to gather and
report.

This was inspired by feedback left at #10948
2025-01-15 20:24:52 -06:00
Ed Page
a282233ae4 test(publish): Check with multiple unpublishable packages 2025-01-15 20:23:19 -06:00
Ed Page
4e5af28150 refactor(schema): Group TomlManifest fields to clarify requires_package
I found a bug in the manifest parser and figured this would help make it
more obvious.

Since I was already changing the order, I figure I'm make things a
little more logical (user-facing first, implementtion details later)
2024-12-13 10:31:53 -06:00
Ed Page
563b1a27b5 test: Harden against 2027(?) edition 2024-11-27 13:10:32 -06:00
Ed Page
81411ec545 feat: Stabilize Edition 2024 2024-11-25 09:27:09 -06:00
Sebastian Dröge
dd698ff048 Always include Cargo.lock in published crates
Originally it was only included for packages that have executables or
examples for `cargo install`, however this causes inconsistencies and
is kind of unexpected nowadays, e.g. with cdylib crates.

Including it always only slightly increases the crate size and allows
for all crates to know a set of dependency versions that were working,
which can make regression tracking easier.

Fixes https://github.com/rust-lang/cargo/issues/13447
2024-11-14 09:06:18 +02:00
Ed Page
af3cfd5abe fix(test): Un-deprecate contains assertions 2024-11-07 15:55:35 -06:00
bors
92f94a54ac Auto merge of #14742 - epage:publish, r=ehuss
fix(publish): Downgrade version-exists error to warning on dry-run

### What does this PR try to resolve?

Especially for beta, this was the most conservative, minimal change.

Fixes #14721

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

### Additional information

This will get cherry-picked to beta
2024-10-29 16:04:22 +00:00
Ed Page
947e1ffe3f fix(publish): Downgrade version-exists error to warning on dry-run
This will get cherry-picked to beta

Fixes #14721
2024-10-29 10:21:52 -05:00
Ed Page
ae6b279277 test(publish): Verify version-exists error in dry-run 2024-10-29 10:14:22 -05:00
todd
11f84a964c fix: use Registry::describe_source to fix error message and related test cases
`Registry::describe_source` will be used as default error message, but if the message
come from `Registry::describe_source` is empty, then it uses `SourceId` message
2024-10-25 00:35:30 +08:00
Ed Page
5b84fc99c5 feat(test): Snapshot .crate validation 2024-10-17 06:26:47 +08:00
Joe Neeman
4e051c47be Support package selection in cargo publish 2024-10-10 09:37:10 +07:00
Joe Neeman
3ffcdee1ce Add failing test 2024-10-10 09:17:27 +07:00
Ed Page
7be5a2146b fix: Remove implicit feature removal
Due to problems we ran into with #14016, we're removing implicit
features from the 2024 edition to give ourselves more time to design it
as we should.

I could have added a new flag for this or made an EditionNext but I
decided to remove it in the hopes to avoid any path dependency in
solving this the next time.
2024-10-01 11:48:31 -05:00
Ed Page
5e35e271bc feat(toml): Add autolib
PR #5335 added `autobins`, etc for #5330.  Nowhere in there is
discussion of `autolib`.

Cargo script disables support for additional build-targets by disabling
discovery.
Except we don't have a way to disable discovery of `autolib`, leading to #14476.
By adding `autolib`, we can continue in that direction.

This also allows us to bypass inferring of libs on published packages,
like all other build-targets which were handled in #13849.

As this seems fairly low controversy, this insta-stabilizes the field.
In prior versions of Cargo, users will get an "unused manifest key"
warning.
For packags where this is set by `cargo publish`, the warning will be suppressed and things will work as normal.
For `cargo vendor`, the same except there will be some churn in the
vendored source as this field will now be set.
For local development, it should be rare to set `autolib` so the lack of
error by discovering a file when this is set shouldn't be a problem.

Fixes #14476
2024-09-24 11:24:24 -05:00
Weihang Lo
5dfdd59009
feat: make lockfile v4 the default
This commit makes lockfile version 4 the default version when Cargo
tries to write to a lockfile.

The lockfile version 4 has been stabilized since 1.78.0,
and will become default in 1.83.0.
the length of transition period is pretty similar as before.

One caveat is that in other output from Cargo,
e.g., `cargo metatada`, status messages,
`SourceID` will display in the v4 URL encoded format.
This shouldn't affect the majority of Rust users,
as `SourceId` representation should be opaque to them,
unless comparing `SourceId` across different version of toolchains.
2024-09-24 20:43:02 -04:00
Ed Page
a6cf1be655 test: Switch from allow to expect deprecated
This caught a couple of lingering items.
2024-09-23 20:44:06 -05:00
sanchitlegalai
6ede1e2b27 fix(publish): Bail on existing version 2024-09-06 13:25:55 -05:00
sanchitlegalai
e0a1918cf2 test(publish): Show publishing existing version 2024-09-06 13:24:29 -05:00
Joe Neeman
a016e5f5c2 Multi-package publishing
Co-authored-by: Tor Hovland <55164+torhovland@users.noreply.github.com>
Co-authored-by: Ed Page <eopage@gmail.com>
2024-09-06 19:05:27 +07:00
Joe Neeman
faee9a7e91 Use the shared infer_registry function for publishing 2024-09-06 19:05:27 +07:00
Joe Neeman
de8b64ee59 Add publish workspace tests
Co-authored-by: Tor Hovland <55164+torhovland@users.noreply.github.com>
2024-09-06 19:05:27 +07:00
Ed Page
be5064e561 test(publish): More dev-dep stripping cases 2024-07-31 08:24:04 -05:00
Ed Page
eddf7b7b7b fix(publish): Don't strip non-dev features
First, we added support for stripping of local-only dev-dependencies.
This was dual-implemented for `Cargo.toml` and `Summary`.

This left off stripping of `dep/feature` that reference dev-dependencies
(enabling features within dev-dependencies).
When we fixed this, we again dual-implemented it.

The `Cargo.toml` version was correct but the `Summary` version was
instead stripping too many features,
particularly features that reference renamed dependencies.
We didn't have tests for this case and it wasn't caught earlier because
crates.io re-generates the `Summary` from `Cargo.toml`, ignoring what we
post.
That makes this only show up with custom registries that trust what
Cargo posts.

Rather than fixing the `Summary` generation, I remove the
dual-implementation and instead generate the `Summary` from the
published `Cargo.toml`.
Unfortunately, we don't have access directly to the packaged
`Cargo.toml`.
It could be passed around and I originally did so, hoping to remove use
of the local `Package`.
However, the local `Package` is needed for things like reading the
`README`.
So I scaled back and isolate the change to only what needs it.
This also makes it easier for `prepare_transmit` callers.
Fully open to someone exploring removing this extra `prepare_for_publish` in the future.

Fixes #14321
2024-07-30 14:54:37 -05:00
Ed Page
9e730ec7ff test(publish): Show bad dev-dep stripping
See #14321
2024-07-30 13:46:58 -05:00
Ed Page
691c5a25cb test(publish): Add more dev-dep stripping regression cases 2024-07-30 13:38:11 -05:00
Ed Page
0ece9b9d93 test(publish): Consolidate dev-dep stripping tests 2024-07-30 13:38:10 -05:00
Ed Page
5b9799c6f4 refactor: Migrate from extern crate to test-support prelude
We now include the prelude in so many places, this simplifies how we can
present how `cargo-test-support` works.

Yes, this included some `use` clean ups but its already painful enough
walking through every test file, I didn't want to do it twice.
2024-07-12 15:57:00 -05:00
eth3lbert
798108d047
test: migrate publish to snapbox 2024-06-27 12:55:35 +08:00
Joe Neeman
c0287bec8d Change verification order during packaging.
Once we support packaging workspaces with dependencies, dependency
packages need to be built before anything is verified. In addition to a
little refactoring, this commit reorders the console messages so that
package metadata (archive size, etc.) is reported before verification
results.

Co-Authored-By: Tor Hovland <55164+torhovland@users.noreply.github.com>
2024-06-14 15:15:03 -05:00