18323 Commits

Author SHA1 Message Date
Ifropc
d4ac929563 test: add tests for CARGO_MANIFEST_PATH in build.rs
- Uses same checks as for already existing CARGO_MANIFEST_DIR
2024-09-26 01:43:16 -04:00
Ifropc
051478c12e
feat: add CARGO_MANIFEST_PATH env variable 2024-08-15 12:31:50 -07:00
bors
2f738d617c Auto merge of #14391 - weihanglo:downgrade-openssl, r=epage
chore: downgrade to openssl v1.1.1 (again)

It happened again in <https://github.com/rust-lang/cargo/pull/14299>.
See <https://github.com/rust-lang/cargo/issues/13546#issuecomment-2285181505> and <https://github.com/rust-lang/cargo/pull/13731>.
2024-08-13 10:57:52 +00:00
Weihang Lo
2289f4680c
chore: pin also openssl crate to 0.10.57 2024-08-12 22:13:27 -04:00
Weihang Lo
29214ba153
chore: downgrade to openssl v1.1.1 (again) 2024-08-12 22:12:43 -04:00
bors
94935a028b Auto merge of #14389 - weihanglo:rustdoc, r=epage
feat(trim-paths): rustdoc supports trim-paths for diagnostics
2024-08-12 20:38:48 +00:00
bors
7ac34d3edc Auto merge of #14380 - jemtucker:fix-14379, r=epage
Use longhand gitoxide path-spec patterns

Closes #14379
2024-08-12 17:50:03 +00:00
Weihang Lo
b8a3dbebd5
feat(trim-paths): rustdoc supports trim-paths for diagnostics
This enables rustdoc invocation from `cargo doc` to trim paths
in diagnostics. Doc tests are out-of-scope, as they are handled
in a different mechanism, which needs more cares.
2024-08-12 13:48:07 -04:00
Weihang Lo
33a800caca
test: show trim-paths=diagnostics doesnt works for rustdoc
It should be working with the next commit.
2024-08-12 13:34:53 -04:00
bors
f3fee6d250 Auto merge of #14141 - hi-rustin:rustin-patch-info, r=epage
feat: Add `info` cargo subcommand

<!-- homu-ignore:start -->

close https://github.com/rust-lang/cargo/issues/14081
close https://github.com/rust-lang/cargo/issues/948

fcp https://github.com/rust-lang/cargo/pull/14141#issuecomment-2243683924

This PR added a new `info` cargo subcommand.

# Background

This adds a new subcommand to Cargo, `cargo info`. This subcommand would allow users to get information about a crate from the command line, without having to go to the web.

The main motivation for this is to make it easier to get information about a crate from the command line. Currently, the way to get information about a crate is to go to the web and look it up on [crates.io] or find the crate's source code and look at the `Cargo.toml` file. This is not very convenient, especially not all information is displayed on the [crates.io] page.
This command also has been requested by the community for a long time. You can find more discussion about this in [cargo#948].

Another motivation is to make the workflow of finding and evaluating crates more efficient. In the current workflow, users can search for crates using `cargo search`, but then they have to go to the web to get more information about the crate. This is not very efficient, especially if the user is just trying to get a quick overview of the crate. This would allow users to quickly get information about a crate without having to leave the terminal.

[crates.io]: https://crates.io
[cargo#948]: https://github.com/rust-lang/cargo/issues/948

Example usage:

```console
./target/debug/cargo info clap --verbose
  Credential cargo:token get crates-io
clap #argument #cli #arg #parser #parse
A simple to use, efficient, and full-featured Command Line Argument Parser
version: 4.5.8 (latest 4.5.9)
license: MIT OR Apache-2.0
rust-version: 1.74
documentation: https://docs.rs/clap/4.5.8
repository: https://github.com/clap-rs/clap
crates.io: https://crates.io/crates/clap/4.5.8
features:
 +default         = [std, color, help, usage, error-context, suggestions]
  color           = [clap_builder/color]
  error-context   = [clap_builder/error-context]
  help            = [clap_builder/help]
  std             = [clap_builder/std]
  suggestions     = [clap_builder/suggestions]
  usage           = [clap_builder/usage]
  cargo           = [clap_builder/cargo]
  debug           = [clap_builder/debug, clap_derive?/debug]
  deprecated      = [clap_builder/deprecated, clap_derive?/deprecated]
  derive          = [dep:clap_derive]
  env             = [clap_builder/env]
  string          = [clap_builder/string]
  unicode         = [clap_builder/unicode]
  unstable-doc    = [clap_builder/unstable-doc, derive]
  unstable-styles = [clap_builder/unstable-styles]
  unstable-v5     = [clap_builder/unstable-v5, clap_derive?/unstable-v5, deprecated]
  wrap_help       = [clap_builder/wrap_help]
dependencies:
 +clap_builder@=4.5.8
  clap_derive@=4.5.8
owners:
  kbknapp (Kevin K.)
  github:rust-cli:maintainers (Maintainers)
  github:clap-rs:admins (Admins)
note: to see how you depend on clap, run `cargo tree --invert --package clap@4.5.8`
```

<img width="1425" alt="image" src="https://github.com/user-attachments/assets/e0813c45-624f-417c-a61d-eda03f9ab5ed">

*note:* this is showing the `--verbose` output to show every thing the user can possibly see.  Normal operation does not include
- dependencies

## Detailed design

| Content                                                                    | Explanation                         | Why                                                                               |
|----------------------------------------------------------------------------|-------------------------------------|-----------------------------------------------------------------------------------|
| clap                                                                       | Name                                | The basic information.                                                            |
| #argument #cli #arg #parser #parse                                         | Keywords (clickable)                           | It's more like a category, which you can use to search for relevant alternatives. |
| A simple to use, efficient, and full-featured Command Line Argument Parser | Description                         | The basic information.                                                            |
| version: 4.5.8 (latest 4.5.9)                                                           | Version                             | The basic information.                                                            |
| license: MIT OR Apache-2.0                                                 | License                             | When choosing a crate, it is crucial to consider the license.                     |
| rust-version: 1.74                                                       | MSRV                                | When choosing a crate, it is crucial to make sure it can work with your MSRV.     |
| documentation: <https://docs.rs/clap/4.5.8>                               | Documentation Link                  | Use these links can find more docs and information.                               |
| repository: <https://github.com/clap-rs/clap>                              | Repo Link                           | Use these links can find more docs and information.                               |
| crates.io: https://crates.io/crates/clap/4.5.8                             | crates.io Link                           | Use these links can find more docs and information.                               |
| features:                                                                  | Default Features And Other Features | It helps for enabling features.                                                   |
| dependencies:                                                              | All dependencies                    | It indicates what it depends on.                                                  |
| owners:                                                                    | Owners                              | It indicates who maintains the crate.                                             |
| note: to see how you depend on clap, run `cargo tree --invert --package clap@4.5.8`                                                                   | A note for cargo tree command                              | It will prompt the user that the package is depended on under the workspace, and the dependencies can be viewed using the cargo tree command.           |

## Rendering features

- For features enabled by users, a + prefix and colored output are now used for better visibility.
- For features enabled automatically, colored output is used to distinguish them.
- For disabled features, non-colored output is used to clearly indicate their status.

## Rendering deps

Only show dependencies in verbose mode.

- For dependencies required by the package, a + prefix and colored output are now used for better visibility.
- For dependencies that are optional and activated, colored output is used to distinguish them.
- For dependencies that are optional and not activated, non-colored output is used to clearly indicate their status.

# Some important notes

## Downloading the crate from any Cargo compatible registry

The `cargo info` command will download the crate from any Cargo compatible registry. It will then extract the information from the `Cargo.toml` file and display it in the terminal.

If the crate is already in the local cache, it will not download the crate again. It will get the information from the local cache.

## Pick the correct version from the workspace

When executed in a workspace directory, the cargo info command chooses the version that the workspace is currently using.

If there's a lock file available, the version from this file will be used. In the absence of a lock file, the command attempts to select a version that is compatible with the Minimum Supported Rust Version (MSRV). And the lock file will be generated automatically.

The following hierarchy is used to determine the MSRV:

- First, the MSRV of the parent directory package is checked, if it exists.
- If the parent directory package does not specify an MSRV, the minimal MSRV of the workspace is checked.
- If neither the workspace nor the parent directory package specify an MSRV, the version of the current Rust compiler (rustc --version) is used.

# Prior art

## NPM

[npm] has a similar command called `npm info`.
For example:

```console
$ npm info lodash

lodash@4.17.21 | MIT | deps: none | versions: 114
Lodash modular utilities.
https://lodash.com/

keywords: modules, stdlib, util

dist
.tarball: https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz
.shasum: 679591c564c3bffaae8454cf0b3df370c3d6911c
.integrity: sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==
.unpackedSize: 1.4 MB

maintainers:
- mathias <mathias@qiwi.be>
- jdalton <john.david.dalton@gmail.com>
- bnjmnt4n <benjamin@dev.ofcr.se>

dist-tags:
latest: 4.17.21

published over a year ago by bnjmnt4n <benjamin@dev.ofcr.se>
```

[npm]: https://www.npmjs.com/

## Poetry

[Poetry] has a similar command called `poetry show`.

For example:

```console
$ poetry show pendulum

name        : pendulum
version     : 1.4.2
description : Python datetimes made easy

dependencies
 - python-dateutil >=2.6.1
 - tzlocal >=1.4
 - pytzdata >=2017.2.2

required by
 - calendar >=1.4.0
```

[Poetry]: https://python-poetry.org/

# insta-stable

As `@weihanglo` mentioned in https://github.com/rust-lang/cargo/pull/14141#issuecomment-2189223552, commands that shadow third-party commands tend to be insta-stabilized to avoid an intermediate period where users can't access the third-party command (built-ins get priority) nor the built-in command (requires nightly)

For the cargo-info command, there are two commands that this would shadow
- [cargo-information](https://github.com/hi-rustin/cargo-information): hasn't been around too long and only has 4k downloads
- [cargo-info](https://gitlab.com/imp/cargo-info) : been around longer and has 63k downloads

We might be able to get away with having this unstable but starting from the assumption of insta-stabilization.
2024-08-12 17:12:39 +00:00
Weihang Lo
0a752c61e7
refactor: extract remap rules into functions 2024-08-12 11:36:56 -04:00
Jem Tucker
978514251a fix: use longhand gitoxide path-spec patterns 2024-08-10 20:21:40 +01:00
Jem Tucker
972d5346a2 test: Add test for issue rust-lang#14379 2024-08-10 20:13:01 +01:00
Rustin170506
ba07215014 docs: add completions for bash and zsh 2024-08-10 20:41:12 +08:00
Rustin170506
24ef77a0fb docs: add cargo-info subcommand and add man page 2024-08-10 20:41:06 +08:00
Rustin170506
9d164aa23e test: migrate all test from cargo-information 2024-08-10 14:10:59 +08:00
Rustin170506
c76c8fd9aa feat: Add info cargo subcommand 2024-08-10 14:10:51 +08:00
bors
ec05ed9f9c Auto merge of #14382 - ehuss:macos-14-nightly, r=epage
CI: Switch macos aarch64 to nightly

We will be promoting aarch64-apple-darwin to tier 1 soon via https://github.com/rust-lang/rust/pull/128592. This updates our CI so that aarch64-apple-darwin runs the full test suite on nightly to keep this in-line with tier-1 support.

This also removes the x86_64 stable macos job and replaces it with aarch64, mainly because aarch64 runs much faster, and presumably x86_64 support will go away some day.
2024-08-10 02:13:22 +00:00
Eric Huss
afe0b2de7a CI: Switch macos aarch64 to nightly
We will be promoting aarch64-apple-darwin to tier 1 soon via
https://github.com/rust-lang/rust/pull/128592. This updates our CI
so that aarch64-apple-darwin runs the full test suite on nightly to
keep this in-line with tier-1 support.

This also removes the x86_64 stable macos job and replaces it with
aarch64, mainly because aarch64 runs much faster, and presumably
x86_64 support will go away some day.
2024-08-09 18:08:28 -07:00
bors
73a1b767b9 Auto merge of #14377 - mo8it:context, r=weihanglo
Use context instead of with_context

Replace `.with_context(|| "…")` with `.context("…")` to avoid calling a trivial closure. It is also shorter :)

On the other hand, use `.with_context(|| format!(…))` instead of `.context(format!(…))` to avoid unneeded string allocation.
2024-08-09 14:27:26 +00:00
Mo
af04e54235
Apply suggestions from code review
Inline variables in `format!`

Co-authored-by: Weihang Lo <weihanglo@users.noreply.github.com>
2024-08-09 15:42:02 +02:00
mo8it
e45c2c0eaa Remove unused import 2024-08-09 14:25:13 +02:00
mo8it
3136c549ab context directly on error instead of Err variant 2024-08-09 14:21:33 +02:00
mo8it
3ccb17c399 Use with_context with format! 2024-08-09 14:20:18 +02:00
mo8it
5ca1add0b0 Use context instead of with_context 2024-08-09 14:01:43 +02:00
bors
b66cad8038 Auto merge of #14359 - linyihai:issue-14354, r=weihanglo
Fix: `cargo package` failed on bare commit git repo.

### What does this PR try to resolve?
Fixes #14354

This approach chose to not generate a `.cargo_vcs_info.json` for bare commit git repo.

### How should we test and review this PR?
Compare the test changes before and after the two commits

### Additional information
2024-08-08 21:22:58 +00:00
bors
0d8d22f83b Auto merge of #14370 - weihanglo:build-std, r=Muscraft
fix: std Cargo.lock moved to `library` dir

https://github.com/rust-lang/cargo/pull/14358 didn't check the correct Cargo.lock existence
Perhaps it was there so the test passed,
but after a new nightly is out it is gone.

```
    Blocking waiting for file lock on package cache
error: "/home/user/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/Cargo.lock" does not exist, unable to build with the standard library, try:
        rustup component add rust-src --toolchain nightly-aarch64-apple-darwin

note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
```

Fixes https://github.com/rust-lang/rust/issues/128808

### How to test the change:

The current nightly `cargo 1.82.0-nightly (94977cb1f 2024-08-06)` would fail when running

```
cargo +nightly build -Zbuild-std --target <host-triple>
```

After this fix, it should just work

```
RUSTC=~/.rustup/toolchains/nightly-<host-triple>/bin/rustc ./target/debug/cargo build -Zbuild-std --target <host-triple>
```
2024-08-08 12:54:24 +00:00
Weihang Lo
50237f4049
fix: std Cargo.lock moved to library dir
rust-lang/cargo#14358 didn't check the correct Cargo.lock existence
Perhaps it was there so the test passed, but after a new nightly
is out it is gone.

```
    Blocking waiting for file lock on package cache
error: "/home/user/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/Cargo.lock" does not exist, unable to build with the standard library, try:
        rustup component add rust-src --toolchain nightly-aarch64-apple-darwin

note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
```
2024-08-08 01:04:42 -04:00
Lin Yihai
37cda2d9a0 feat: don't generate .cargo_vcs_info.json if git repro has no commit 2024-08-08 09:57:39 +08:00
Lin Yihai
ab4ab66c60 fix: cargo package failed on bare commit git repo 2024-08-08 09:57:39 +08:00
Lin Yihai
a562387d2b test: Add test for issue-14354
This a test to reflect that `cargo package --allow-dirty` will fail on a bare commit git repo
2024-08-08 09:57:39 +08:00
bors
f50c592491 Auto merge of #14367 - epage:vendor, r=weihanglo
fix(vendor): Strip excluded build targets

### What does this PR try to resolve?

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

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

The commits are setup to be able to show, through the tests, how the `cargo package` and `cargo vendor` behavior diverge and then how `cargo vendor`s behavior changes over time.

This is a **very** hacky solution, duplicating the minimum of what
`prepare_for_publish` does to fix this one issue and in the least
intrusive way to the vendor code.

The intention is to keep this low risk for backporting to beta and
stable.
We need to revisit this, refactoring the `cargo package` code so that we
can call into that for each vendored dependency.

### Additional information
2024-08-07 20:53:07 +00:00
Ed Page
1ae77f5e09 fix(vendor): Strip excluded build targets
This is a **very** hacky solution, duplicating the minimum of what
`prepare_for_publish` does to fix this one issue and in the least
intrusive way to the vendor code.

The intention is to keep this low risk for backporting to beta and
stable.
We need to revisit this, refactoring the `cargo package` code so that we
can call into that for each vendored dependency.

Fixes #14348
2024-08-07 12:27:37 -05:00
Ed Page
33862df837 test(vendor): Port 'package' tests to 'vendor' 2024-08-07 11:48:51 -05:00
Ed Page
26d654f5c1 test(vendor): Drop explicitlu specified build-target cases
Since we already cover this for `cargo package` and we turn all
implicit targets into explicit targets (making implicit tests cover
explicit cases), this becomes redundant.
2024-08-07 11:48:51 -05:00
Ed Page
700dfebc77 test(vendor): Fork the package tests 2024-08-07 11:48:51 -05:00
Ed Page
f8dd12b3e0 test(vendor): Clarify what vendor config is used 2024-08-07 11:48:47 -05:00
bors
495d02cb47 Auto merge of #14340 - tweag:infer-registry, r=epage
Infer registry

While working on `cargo publish` for workspaces, I noticed a few ways in which the registry inference for `cargo package` seemed wrong. (This only affects the unstable `-Zpackage-workspace` feature.) This is all about the interaction between `--index`/`--registry`, and the `package.publish` fields.

- Previously, if multiple crates were packaged and they had different `package.publish` settings, we would ignore those setting and fall back to "crates-io". After this PR, we will bail out with an error instead (unless they've specified `--registry` or `--index`).
- Previously, we would validate the inferred registry against the `package.publish` settings, even if the `--index` argument would have taken precedence. After this PR, we will skip registry validation in this case.
- Previously, we were just ignoring the registry value inferred from `package.publish`: we'd validate that it was ok, but then just not use it.
2024-08-07 15:00:16 +00:00
Joe Neeman
275d3b6e54 Change registry inference rules when packaging multiple packages
Infer the package registry only if all packages have the same publish
field. If there is confusion, bail out instead of defaulting to
crates-io.
2024-08-07 21:55:11 +07:00
Joe Neeman
010db83cf5 Add misbehaving tests. 2024-08-07 21:53:56 +07:00
bors
94977cb1fa Auto merge of #14357 - dpaoliello:infname, r=epage
Don't specify the depedency name in the `cargo add` inferred name test

The `cargo_add/path_inferred_name` was incorrectly adding the name of the dependency to add in its command line.
2024-08-06 21:42:10 +00:00
Daniel Paoliello
4d49d2d179 Don't specify the depdency name in the inferred name test 2024-08-06 09:29:50 -07:00
bors
403bc5bc74 Auto merge of #14352 - Urgau:fix-cfgs-lint-name, r=weihanglo
Fix renamed disallowed cfg lint name

### What does this PR try to resolve?

In https://github.com/rust-lang/cargo/pull/14153 we allowed the to be merged https://github.com/rust-lang/rust/pull/126158 lint. Since then an FCP was conducted and the lint was renamed to `explicit_builtin_cfgs_in_flags`. This PR renames the lint in the same test so that https://github.com/rust-lang/rust/pull/126158 can be merged.

### Additional information

https://github.com/rust-lang/rust/pull/126158#issuecomment-2267984311 shows the failing test.
2024-08-06 15:43:23 +00:00
bors
2cd657cc33 Auto merge of #14358 - weihanglo:build-std, r=epage
fix(build-std): remove hack on creating virtual std workspace
2024-08-06 12:11:40 +00:00
Weihang Lo
7902bf8cb0
refactor: remove unused Workspace::new_virtual
It was designed for `-Zbuild-std`
2024-08-05 23:38:06 -04:00
Weihang Lo
da8138e3c4
fix(build-std): remove hack on creating virtual std workspace
Starting from rust-lang/rust#128534 (nightly-2024-08-05),
stnadard library has its own Cargo workspace.
Hence `-Zbuild-std` no longer need to fake a virtual workspace.

This also adjusts Cargo.toml in `mock-std` to align with std's Cargo.toml
2024-08-05 23:35:29 -04:00
Weihang Lo
9af3930321
test(build-std): expand assertion to ensure no index update 2024-08-05 23:22:19 -04:00
Urgau
e03f2dbdbf Fix renamed disallowed cfg lint name 2024-08-05 11:14:16 +02:00
bors
fa64658367 Auto merge of #14342 - epage:normalize, r=weihanglo
refactor(toml): Rename 'resolved' to 'normalized'

In a discussion on an issue, it became confusing to talk about "resolved" manifests and dependency resolution,
so I'm switching manifests to use the other term I considered, "normalized".
2024-08-02 16:08:06 +00:00
bors
e5ec01c03c Auto merge of #14336 - soloturn:master, r=weihanglo
faq: rephrase offline usage.

### What does this PR try to resolve?
fixes #14330. FAQ tried to explain the history of cargo offline, and thus
was distracting from the core flags.
2024-08-02 15:32:44 +00:00