Commit graph

3315 commits

Author SHA1 Message Date
cassaundra 30a445b9a4
Add tests for cargo add's rust-version behavior 2023-05-23 11:06:08 -07:00
bors feb9bcf630 Auto merge of #12168 - epage:lints2, r=weihanglo
fix(lints): Switch to -Zlints so stable projects can experiment

### What does this PR try to resolve?

In #12115, we explored how we can let stable projects
experiment with `[lints]` to provide feedback.  What we settled on is
switching from the `cargo-features` manifest key to the `-Z` flag as
`cargo-features` always requires nightly while `-Z` only requires it
when being passed in.  This means a project can have a `[lints]` table
and have CI / contributors run `cargo +nightly check -Zlints` when they
care about warnings.

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

Demonstrate how you test this change and guide reviewers through your PR.
With a smooth review process, a pull request usually gets reviewed quicker.

If you don't know how to write and run your tests, please read the guide:
https://doc.crates.io/contrib/tests

### Additional information

I considered reworking the code to show the user the errors they would encounter once the feature is stable but held off.  I wasn't quite sure what language to use and most likely a user would have something doing error reporting, like CI, so it should be fine.
2023-05-23 13:52:22 +00:00
hi-rustin 821725dcd1 Add a inherit test for init
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-05-23 10:36:48 +08:00
hi-rustin 5265b1d0ec Add tests for inherit_workspace_package_table
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-05-23 10:36:08 +08:00
bors e5e68c4093 Auto merge of #12148 - epage:lints, r=weihanglo
feat: `lints` feature

### What does this PR try to resolve?

Implement rust-lang/rfcs#3389 which shifts a subset of `.cargo/config.toml` functionality to `Cargo.toml` by adding a `[lints]` table.

This **should** cover all of the user-facing aspects of the RFC
- This doesn't reduce what flags we fingerprint
- This will fail if any lint name as `::` in it.  What to do in this case was in the RFC discussion but I couldn't find the thread to see what all was involved in that discussion
- This does not fail if a `[lints]` table is present or malformed unless nightly with the `lints` feature enabled
  - The idea is this will act like a `[lints]` table is present in an existing version of rust, ignore it
  - The intent is to not force an MSRV bump to use it.
  - When disabled, it will be a warning
  - When disabled, it will be stripped so we don't publish it

Tracking issue for this is #12115.

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

1. Look at this commit by commit to see it gradually build up
2. Look through the final set of test cases to make sure everything in the RFC is covered

I tried to write this in a way that will make it easy to strip out the special handling of this unstable feature, both in code and commit history

### Additional information

I'd love to bypass the need for `cargo-features = ["lints"]` so users today can test it on their existing projects but hesitated for now.  We can re-evaluate that later.

I broke out the `warn_for_feature` as an experiment towards us systemitizing this stabilization approach which we also used with #9732.  This works well when we can ignore the new information which isn't too often but sometimes happens.

This does involve a subtle change to `profile.rustflags` precedence but
its nightly and most likely people won't notice it?  The benefit is its
in a location more like the rest of the rustflags.
2023-05-22 19:54:39 +00:00
Ed Page 08fdd86d84 fix(lints): Switch to -Zlints so stable projects can experiment
In rust-lang/cargo#12115, we explored how we can let stable projects
experiment with `[lints]` to provide feedback.  What we settled on is
switching from the `cargo-features` manifest key to the `-Z` flag as
`cargo-features` always requires nightly while `-Z` only requires it
when being passed in.  This means a project can have a `[lints]` table
and have CI / contributors run `cargo +nightly check -Zlints` when they
care about warnings.
2023-05-22 13:45:20 -05:00
Ed Page 2c48b10ef0 test(lints): Remove unused cargo-features 2023-05-22 13:44:56 -05:00
Ed Page e4b01367a1 test(lints): Simplify failure tests 2023-05-22 10:14:35 -05:00
Ed Page be76a55358 test(lints): Verify precedence with build.rustflags 2023-05-22 10:06:57 -05:00
Ed Page 3cba0c1b52 test(lints): Verify dependency behavior 2023-05-22 09:59:23 -05:00
Ed Page 12bc06aaf2 test(lints): Clarify why verbose is used 2023-05-22 09:59:23 -05:00
Ed Page 66a9116f03 fix(lints): Put lints after profile.rustflags
This does involve a subtle change to `profile.rustflags` precedence but
its nightly and most likely people won't notice it?  The benefit is its
in a location more like the rest of the rustflags.
2023-05-22 09:58:42 -05:00
Ed Page e82fe885b5 test(lints): Verify precedence with profile.rustflags 2023-05-22 09:53:25 -05:00
Ed Page 1dfa101cd1 fix(lints): Tie into manifest warnings
This improves the messaging experience (sometimes showing manifest path)
and hiding the warning when not relevant).
2023-05-22 09:53:25 -05:00
Ed Page a8d7c8a58f fix(lints): Clean up warnings about lints feature 2023-05-22 09:53:25 -05:00
Ed Page 5072d9b789 fix(lints): Ignore lints table on stable 2023-05-22 09:53:25 -05:00
Ed Page 66038fad36 test(lints): Show bug with lints on stable 2023-05-22 09:53:25 -05:00
Ed Page a7555f976e fix(lints): Only warn when seeing lints on stable
This will make it easier for users to test this feature
2023-05-22 09:53:25 -05:00
Ed Page 4279d0d56c feat(lints): Pass lints to tools 2023-05-22 09:53:25 -05:00
Ed Page fad2ea5cfd feat(lints): Error check the lints table 2023-05-22 09:53:22 -05:00
Ed Page 8de25292fd feat(lints): Parse [lints] table on nightly 2023-05-22 09:52:03 -05:00
Weihang Lo 277e65bf4c
fix: pass -C debuginfo after weakening if explicitly set
The weakening of debuginfo for build script shouldn't turn debuginfo
to `DebugInfo::None`. That will result in not passing `-C debuginfo=0`
to rustc, leading to build artifact cache miss.
2023-05-22 00:37:08 +01:00
Eval EXEC e906797b91
Add test case for confilict README.md check
Signed-off-by: Eval EXEC <execvy@gmail.com>
2023-05-14 16:55:23 +08:00
Eric Huss a0f832f4e8 Fix dep/feat syntax with hidden implicit optional dependencies 2023-05-11 09:34:38 -07:00
Eric Huss 2dccb71acd Disallow RUSTUP_TOOLCHAIN in the [env] table. 2023-05-08 09:30:59 -07:00
Eric Huss 4ec06f4820 Disallow RUSTUP_HOME in the [env] table. 2023-05-07 10:01:43 -07:00
bors 27a41d6789 Auto merge of #12095 - ehuss:fix-token-redact, r=weihanglo
Fix redacting tokens in http debug.

Unfortunately it seems like #8222 didn't properly redact tokens when connecting to an http2 server. There were multiple problems:

* For some reason, curl changes the authorization header to be lowercase when using http2.
* Curl also logs the h2h3 lines separately with a different syntax.

This fixes it by checking for these additional cases.

This also adds a test, but it doesn't actually detect this problem because we don't have an http2 server handy. You can test this yourself by running `CARGO_LOG=trace CARGO_HTTP_DEBUG=true cargo publish --token a-unique-token --allow-dirty --no-verify`, and verifying the output does not contain the given token text.
2023-05-06 23:16:31 +00:00
Eric Huss a2ed96df6a Fix self_signed_should_fail for macOS. 2023-05-06 12:41:34 -07:00
Eric Huss d6c20cf109 Fix redacting tokens in http debug. 2023-05-06 12:41:06 -07:00
bors e2d14882a5 Auto merge of #12083 - Eh2406:names, r=weihanglo
do not try an exponential number of package names

re #11934, and as discussed in the cargo team meeting, this changes the strategy to "the original, all underscore, and all dashes".

I was excessively proud of the `hyphen_combination_num` based implementation when I came up with it. But it's always been a hack. I'm glad to be the one to remove it.
2023-05-05 17:18:08 +00:00
Jacob Finkelman d6021c9c34 do not try an exponential number of package names 2023-05-05 17:15:06 +00:00
Weihang Lo 3df35edca7
fix: hack around libsysroot instead of libtest 2023-05-05 14:48:37 +01:00
bors 2d693e20ea Auto merge of #11917 - ehuss:rustup-circumvent, r=weihanglo
Optimize usage under rustup.

Closes #10986

This optimizes cargo when running under rustup to circumvent the rustup proxies. The rustup proxies introduce overhead that can make a noticeable difference.

The solution here is to identify if cargo would normally run `rustc` from PATH, and the current `rustc` in PATH points to something that looks like a rustup proxy (by comparing it to the `rustup` binary which is a hard-link to the proxy). If it detects this situation, then it looks for a binary in `$RUSTUP_HOME/toolchains/$TOOLCHAIN/bin/$TOOL`. If it finds the direct toolchain executable, then it uses that instead.

## Considerations

There have been some past attempts in the past to address this, but it has been a tricky problem to solve. This change has some risk because cargo is attempting to guess what the user and rustup wants, and it may guess wrong. Here are some considerations and risks for this:

* Setting `RUSTC` (as in https://github.com/rust-lang/rustup/pull/2958) isn't an option. This makes the `RUSTC` setting "sticky" through invocations of different toolchains, such as a cargo subcommand or build script which does something like `cargo +nightly build`.

* Changing `PATH` isn't an option, due to issues like https://github.com/rust-lang/rustup/issues/3036 where cargo subcommands would be unable to execute proxies (so things like `+toolchain` shorthands don't work).

* Setting other environment variables in rustup (as in https://github.com/rust-lang/rustup/pull/3207 which adds `RUSTUP_TOOLCHAIN_DIR` the path to the toolchain dir) comes with various complications, as there is risk that the environment variables could get out of sync with one another (like with `RUSTUP_TOOLCHAIN`), causing tools to break or become confused.

  There was some consideration in that PR for adding protections by using an encoded environment variable that could be cross-checked, but I have concerns about the complexity of the solution.

  We may want to go with this solution in the long run, but I would like to try a short term solution in this PR first to see how it turns out.

* This won't work for a `rustup-toolchain.toml` override with a [`path`](https://rust-lang.github.io/rustup/overrides.html#path) setting. Cargo will use the slow path in that case. In theory it could try to detect this situation, which may be an exercise for the future.

* Some build-scripts, proc-macros, or custom cargo subcommands may be doing unusual things that interfere with the assumptions made in this PR. For example, a custom subcommand could call a `cargo` executable that is not managed by rustup. Proc-macros may be executing cargo or rustc, assuming it will reach some particular toolchain. It can be difficult to predict what unusual ways cargo and rustc are being used. This PR (and its tests) tries to make extra sure that it is resilient even in unusual circumstances.

* The "dev" fallback in rustup can introduce some complications for some solutions to this problem. If a rustup toolchain does not have cargo, such as with a developer "toolchain link", then rustup will automatically call either the nightly, beta, or stable cargo if they are available. This PR should work correctly, since rustup sets the correct `RUSTUP_TOOLCHAIN` environment variable for the *actual* toolchain, not the one where cargo was executed from.

* Special care should be considered for dynamic linking. `LD_LIBRARY_PATH` (linux), `DYLD_LIBRARY_PATH` (macos), and `PATH` (windows) need to be carefully set so that `rustc` can find its shared libraries. Directly executing `rustc` has some risk that it will load the wrong shared libraries. There are some mitigations for this. macOS and Linux use rpath, and Windows looks in the same directory as `rustc.exe`. Also, rustup configures the dyld environment variables from the outer cargo. Finally, cargo also configures these (particularly for the deprecated compiler plugins).

* This shouldn't impact installations that don't use rustup.

* I've done a variety of testing on the big three platforms, but certainly nowhere exhaustive.
    * One of many examples is making sure Clippy's development environment works correctly, which has special requirements for dynamic linking.

* There is risk about future rustup versions changing some assumptions made here. Some assumptions:
    * It assumes that if `RUSTUP_TOOLCHAIN` is set, then the proxy *always* runs exactly that toolchain and no other. If this changes, cargo could execute the wrong version. Currently `RUSTUP_TOOLCHAIN` is the highest priority [toolchain override](https://rust-lang.github.io/rustup/overrides.html) and is fundamental to how toolchain selection becomes "sticky", so I think it is unlikely to change.
    * It assumes rustup sets `RUSTUP_TOOLCHAIN` to a value that is exactly equal to the name of the toolchain in the `toolchains` directory. This works for user shorthands like `RUSTUP_TOOLCHAIN=nightly`, which gets converted to the full toolchain name. However, it does not work for `path` overrides (see above).
    * It assumes the `toolchains` directory layout is always `$RUSTUP_HOME/toolchains/$TOOLCHAIN`. If this changes, then I think the only consequence is that cargo will go back to the slow path.
    * It assumes downloading toolchains is not needed (since cargo running from the toolchain means it should already be downloaded).
    * It assumes there is no other environment setup needed (such as the dyld paths mentioned above).

  My hope is that if assumptions are no longer valid that the worst case is that cargo falls back to the slow path of running the proxy from PATH.

## Performance

This change won't affect the performance on Windows because rustup currently alters PATH to point to the toolchain directory. However, https://github.com/rust-lang/rustup/pull/3178 is attempting to remove that, so this PR will be required to avoid a performance penalty on Windows. That change is currently opt-in, and will likely take a long while to roll out since it won't be released until after the next release, and may be difficult to get sufficient testing.

I have done some rough performance testing on macOS, Windows, and Linux on a variety of different kinds of projects with different commands. The following attempts to summarize what I saw.

The timings are going to be heavily dependent on the system and the project. These are the values I get on my systems, but will likely be very different for everyone else.

The Windows tests were performed with a custom build of rustup with https://github.com/rust-lang/rustup/pull/3178 applied and enabled (stock rustup shows no change in performance as explained above).

The data is summarized in this spreadsheet: https://docs.google.com/spreadsheets/d/1zSvU1fQ0uSELxv3VqWmegGBhbLR-8_KUkyIzCIk21X0/edit?usp=sharing

`hello-world` has a particularly large impact of about 1.68 to 2.7x faster. However, a large portion of this overhead is related to running `rustc` at the start to discover its version and querying it for information. This is cached after the first run, so except for first-time builds, the effect isn't as noticeable. The "check with info" row is an benchmark that removes `target/debug/deps` but keeps the `.rustc_info.json` file.

Incremental builds are a bit more difficult to construct since it requires customizing the commands for each project. I only did an incremental test for cargo itself, running `touch src/cargo/lib.rs` and then `cargo check --lib`.

These measurements excluded the initial overhead of launching the rustup proxy to launch the initial cargo process. This was done just for simplicity, but it makes the test a little less characteristic of a typical usage, which will have some constant overhead for running the proxy.

These tests were done using [`hyperfine`](https://crates.io/crates/hyperfine) version 1.16.1. The macOS system was an M2 Max (12-thread). The Windows and Linux experiments were run on a AMD Ryzen Threadripper 2950X (32-thread). Rust 1.68.2 was used for testing. I can share the commands if people want to see them.
2023-05-04 23:51:38 +00:00
Eric Huss d4b0b494f1 Add an optimization when running under rustup. 2023-05-03 13:45:54 -07:00
Eric Huss 52317aa8f8 Add some tests for simulating behavior under rustup. 2023-05-03 13:45:54 -07:00
charles-r-earp 61df6bb418 Fixed test update::update_precise_first_run. 2023-05-03 13:08:51 -07:00
charles-r-earp f43e6d947f Added workspace_default_members to more tests. 2023-05-03 12:44:08 -07:00
charles-r-earp e421345d22 Added workspace_default_members to tests. 2023-05-03 12:44:08 -07:00
charles-r-earp 8c96a28ff7 Added workspace_default_members. 2023-05-03 12:44:08 -07:00
bors 2f06c80bd0 Auto merge of #11840 - Byron:shallow-support, r=weihanglo
support for shallow clones and fetches with `gitoxide`

This PR makes it possible to enable shallow clones and fetches for git dependencies and crate indices independently with the `-Zgitoxide=fetch,shallow_deps` and `-Zgitoxide=fetch,shallow_index` respectively.

### Tasks

* [x] setup the shallow option when fetching, differentiated by 'registry' and 'git-dependency'
* [x] validate registries are cloned shallowly *and* fetched shallowly
* [x] validate git-dependencies are cloned shallowly *and* fetched shallowly
* [x] a test to show what happens if a shallow index is opened with `git2` (*it can open it and fetch like normal, no issues*)
* [x] assure that `git2` can safely operate on a shallow clone - we unshallow it beforehand, both for registries and git dependencies
* [x] assure git-deps with revisions are handled correctly (they should just not be shallow, and they should unshallow themselves if they are)
* [x] make sure shallow index clones aren't seen by older cargo's
* [x] make sure shallow git dependency clones aren't seen by older cargo's
* [x] shallow.lock test and more test-suite runs with shallow clones enabled for everything
* [x] release new version of `gix` with full shallow support and use it here
* [x] check why `shallow` files remain after unshallowing. Should they not rather be deleted if empty? - Yes, `git` does so as well, implemented [with this commit](2cd5054b0a)
* ~~see if it can be avoided to ever unshallow an existing `-shallow` clone by using the right location from the start. If not, test that we can go `shallow->unshallow->shallow` without a hitch.~~ Cannot happen anymore as it can predict the final location perfectly.
* [x] `Cargo.lock` files don't prevent shallow clones
* [x] assure all other tests work with shallow cloning enabled (or fix the ones that don't with regression protection)
* [x] can the 'split-brain' issue be solved for good?

### Review Notes

* there is a chance of 'split brain' in git-dependencies  as the logic for determining whether the clone/fetch is shallow is repeated in two places. This isn't the case for registries though.

### Notes

* I am highlighting that this is the `gitoxide` version of shallow clones as the `git2` version [might soon be available](https://github.com/libgit2/libgit2/pull/6396) as well. Having that would be good as it would ensure interoperability remains intact.
* Maybe for when `git2` has been phased out, i.e. everything else is working, I think (unscientifically) there might be benefits  in using worktrees for checkouts. Admittedly I don't know the history of why they weren't used in the first place. Also: `gitoxide` doesn't yet support local clones and might not have to if worktrees were used instead.
2023-05-03 07:12:20 +00:00
Weihang Lo 7fb35c9c4e
test(install): correct the term workspace -> local packagd 2023-05-03 01:04:18 +01:00
Sebastian Thiel 3bd08d934b
Move helper functions to the bottom for consistency; fix name 2023-05-02 18:57:42 +02:00
Ted Kaminski 79bb2d7143 Update pkg-spec comment, and add 2 more test cases 2023-05-01 17:23:17 -05:00
Ted Kaminski 31d679e81a Build by PackageIdSpec, not name, to avoid ambiguity 2023-05-01 17:23:17 -05:00
Sebastian Thiel 2aaebcbcaa
Only fetch single object in shallow mode for compatibility 2023-04-29 14:29:11 +02:00
Sebastian Thiel d4b8fc68ab
Allow fetching a single object, shallow or not.
Doing so seems cleaner as there should be no logical difference between
shallow or not-shallow when fetching. We want a specific object, and should
get it with the refspec. `git` will assure we see all objects we need,
handling shallow-ness for us.

Note that one test needed adjustments due to the different mechanism used
when fetching local repositories, requiring more changes to properly 'break'
the submodule repo when `gitoxide` is used.
2023-04-29 12:21:45 +02:00
Sebastian Thiel 8b3508cad7
Move all tests for shallow fetching into their own module
Note that those which test both with and without shallow still go
into the shallow module.
2023-04-29 09:52:08 +02:00
bors a285008c8e Auto merge of #12044 - jrose-signal:cargo-tree-no-proc-macro, r=epage
cargo-tree: Handle -e no-proc-macro when building the graph

### What does this PR try to resolve?

Makes `-e no-proc-macro` more useful when combined with `-i` or `-d`. Fixes #12030.

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

The new and existing tests should cover this, I hope!

### Additional information

Pruning proc-macro crates during graph construction is closer to how the edge-based filters work (`[no-]build` etc.), so even though `no-proc-macro` isn't technically filtering on edges, it's following a well-established code path.
2023-04-27 21:04:25 +00:00
Jordan Rose a0576d1767 cargo-tree: Handle -e no-proc-macro when building the graph
This is closer to how the edge-based filters work ([no-]build etc.),
and results in a more useful behavior when combined with -i or -d.
2023-04-27 10:54:51 -07:00
Jordan Rose 747a5924a0 test: Add a test for cargo tree --duplicates with a proc-macro 2023-04-27 10:49:22 -07:00