Commit graph

3358 commits

Author SHA1 Message Date
Weihang Lo 03556056d4
feat: prepare for the next lockfile bump
The `-Znext-lockfile-bump` is added, so we can prepare for all
lockfile format changes and then stabilize then all at once.

`-Znext-lockfile-bump` is not intended for using outside our test
suite and development. Hence it's hidden.
2023-06-17 10:24:53 +01:00
Ed Page 5ed07925cc fix(embedded): Ensure we don't auto-discover any targets 2023-06-16 21:08:48 -05:00
Ed Page 575b9ac934 fix(embedded): Don't create an intermediate manifest
To parse the manifest, we have to write it out so our regular manifest
loading code could handle it.  This updates the manifest parsing code to
handle it.

This doesn't mean this will work everywhere in all cases though.  For
example, ephemeral workspaces parses a manifest from the SourceId and
these won't have valid SourceIds.

As a consequence, `Cargo.lock` and `CARGO_TARGET_DIR` are changing from being next to
the temp manifest to being next to the script.  This still isn't the
desired behavior but stepping stones.

This also exposes the fact that we didn't disable `autobins` like the
documentation says we should.
2023-06-16 21:08:47 -05:00
Ed Page 2c70983e8d test(embedded): Verify no autobin behavior is running 2023-06-16 21:06:01 -05:00
Ed Page b116864d79 fix(embedded): Be consistent with existing style when sanitizing 2023-06-15 19:09:28 -05:00
Ed Page 56b2812a85 fix(embedded): Don't append hash to bin names
Background: the hash existed for sharing a target directory.  That code isn't
implemented yet and a per-user build cache might remove the need for it,
so let's remove it for now and more carefully weigh adding it back in.

Immediate: This reduces the chance of hitting file length issues on Windows.

Generally: This is a bit hacky and for an official solution, we should
probably try to find a better way.  This could become more important as
single-file packages are allowed in workspaces.
2023-06-14 12:25:59 -05:00
Ed Page 33c9d8e2fd feat(cli): Pull in cargo-script-mvs core logic
This is no where near the implementation we want but I think we should
develop incrementally on top of what we already have.

See https://github.com/epage/cargo-script-mvs/tree/main
2023-06-09 22:03:18 -05:00
Ed Page 3c15d24960 fix(cli): Warn on stable for precedence changes
This will give us a window to collect feedback on if this affects
anyone.
2023-06-09 22:02:54 -05:00
Ed Page b2b4d9771f test(cli): Verify precedence over external subcommands 2023-06-09 13:16:12 -05:00
Ed Page 21736eda0c feat(cli): Interpret some subcommands as manifest-commands 2023-06-08 20:17:03 -05:00
christian 56318e0b6c remove escapes and leading whitespace from string matches 2023-06-08 17:09:21 +00:00
christian 71b37f2fd1 add test case 2023-06-08 15:27:23 +00:00
Weihang Lo 51ebba2fc1
test: loose overly matches for git cli output
The output format should be stable I believe, but it turns out not.
This is how `git fetch` man page says [1]:

```
<flag> <summary> <from> -> <to> [<reason>]
```

In Git 2.41 they've changed the fetch output a bit [2].

I think let's just loose it to prevent future breakages.

[1]: https://git-scm.com/docs/git-fetch#_output
[2]: https://github.blog/2023-06-01-highlights-from-git-2-41/
2023-06-07 22:55:17 +01:00
MarcusGrass 03675ef6a4
Add additional info on a new line 2023-06-05 11:27:31 +02:00
MarcusGrass 073a32b61f
Add message on reusing previous temporary path on failed cargo installs 2023-06-04 18:31:06 +02:00
bors b0fa79679e Auto merge of #12226 - danilhendrasr:feat/emit-error-on-toolchain-add-and-install, r=weihanglo
Emit error when users try to use a toolchain via the `add` or `install` command

Running `cargo install +nightly` or `cargo add +nightly` does not actually use the nightly toolchain, but the user won't know until the compilation fails. With this PR, an error is emitted if the `install` and `add` command is given a crate name
that starts with a `+` as we assume the user's intention was to use a certain toolchain instead of installing/adding a crate.

Example:
<img width="758" alt="image" src="https://github.com/rust-lang/cargo/assets/45989466/16e59436-32ee-49ee-9933-8b68b176c09d">

Fixes #10362
2023-06-03 14:19:48 +00:00
Danil Hendra Suryawan 58b7bce63e feat(cli): emit error when install is given a toolchain name instead of crate name 2023-06-03 20:51:14 +07:00
Danil Hendra Suryawan a9c47cc3ab feat(cli): emit error when add is given a toolchain name instead of a crate name 2023-06-03 20:50:24 +07:00
Charalampos Mitrodimas a777b82d5f Support "default" option for build.jobs
This commit adds support for passing the keyword "default"
to either the CLI "--jobs" argument on the "[build.jobs]"
section of ".cargo/config".

This is dony by:
  1. Changing the "jobs" config type to an enum that holds
     a String or an Integer(i.e. i32).
  2. Matching the enum & casting it to an integer

Signed-off-by: Charalampos Mitrodimas <charmitro@gmail.com>
2023-06-03 15:24:41 +03:00
Weihang Lo d4067e4881
fix: should assert against stderr instead
This was an overlook in #12205
2023-05-31 20:46:11 +01:00
Weihang Lo 64a1f204f3
refactor: only when -C debuginfo > 0 will spilt-debuginfo be passed
It was unnecessary to pass `spilt-debuginfo` if there is no debuginfo.
Tests are touched here only for matching rustflags invocation stderr
in the original test suite.
2023-05-31 20:43:57 +01:00
jyn e2eacc6414 Don't distinguish Debuginfo::None and Debuginfo::Explicit(None)
Previously, `Debuginfo::None` meant "don't pass -C debuginfo" and `Explicit(None)` meant
"-C debuginfo=0", which occasionally led to caching bugs where cargo would sometimes pass
`-C debuginfo=0` and sometimes not. There are no such bugs currently that we know of, but
representing them the same within cargo avoids the possibility of the bug popping up again in the
future.

I tested the `with_stderr_does_not_contain_tests` with this diff to ensure they did not pass:
```diff
diff --git a/src/cargo/core/compiler/mod.rs b/src/cargo/core/compiler/mod.rs
index 55ec17182..c186dd00a 100644
--- a/src/cargo/core/compiler/mod.rs
+++ b/src/cargo/core/compiler/mod.rs
@@ -1073,9 +1073,7 @@ fn build_base_args(

     let debuginfo = debuginfo.into_inner();
     // Shorten the number of arguments if possible.
-    if debuginfo != TomlDebugInfo::None {
         cmd.arg("-C").arg(format!("debuginfo={}", debuginfo));
-    }

     cmd.args(unit.pkg.manifest().lint_rustflags());
     if !rustflags.is_empty() {
```
2023-05-30 17:06:50 -05:00
Eric Huss 16ac6fae11 Re-enable code_generation test on Windows 2023-05-29 12:01:02 -07:00
bors 8f49b5556b Auto merge of #12191 - epage:mut, r=weihanglo
fix(add): Reduce the chance we re-format the user's `[features]` table

### What does this PR try to resolve?

#11743 pointed out that we re-format the users `[features]` table when running `cargo add`  which was a bug introduced in #11099.

This reduces the chance people will run into this problem
- Reducing the scope of the `fmt` call
- Preserving formatting in a simple case

Actually removing the `fmt` case can make some common formatting cases more complex to do "right", so I'm punting on that for now.

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

Look at the individual commits as I show how each change improves the behavior of `cargo add`.
2023-05-27 10:33:39 +00:00
Ed Page 0da6997ccc test(add): Remove expensive test
This is a carry-over from cargo-edit where we had to worry about the UX
of all of the behavior while now we are just relying on built-in cargo
behavior and don't need to test it specifically for `cargo add`.

On my machine, this test takes 11s.
2023-05-26 19:24:13 -05:00
bors c412aa4fac Auto merge of #12189 - epage:add, r=weihanglo
refactor(tests): Reduce cargo-add setup load

This just gets rid of irrelevant packages in the registry.  Looking into which versions aren't needed would require a deeper pass, so I held off on that for now.

Before, the tests were in the 300-500ms range and now they take 100-300ms.

This did call to my attention that `unrelated` is misspelled as `unrelateed` but holding off on fixing that to reduce conflicts.
2023-05-26 22:15:09 +00:00
Ed Page dbf9134d57 fix(add): Preserve formatting 2023-05-26 16:49:59 -05:00
Ed Page 6d8f35f729 fix(add): Reduce the chance of breaking the user's formatting 2023-05-26 16:49:59 -05:00
Ed Page b903527f28 test(add): Show features table fmt bug 2023-05-26 16:49:14 -05:00
bors d08c587469 Auto merge of #10910 - Nemo157:lint-different-resolver-10112, r=epage
Warn when an edition 2021 crate is in a virtual workspace with default resolver

Edition 2021 updates the default resolver to version "2", but developers using virtual workspaces commonly don't get this update because the virtual workspace defaults to version "1". Warn when this situation occurs so those developers can explicitly configure their workspace and will be more likely to know that they will need to update it in the future.

Fixes #10112
2023-05-26 19:57:28 +00:00
Wim Looman 3dec6f234d
Remove unnecessary warning line 2023-05-26 20:27:34 +02:00
Wim Looman 49cc60b1aa
Add notes on how to configure the virtual workspace's resolver 2023-05-26 20:20:56 +02:00
Wim Looman 7067d0df58
Improve warning message grammar 2023-05-26 20:09:27 +02:00
Wim Looman c31877def5
Update cargo new workspace inheritance tests to specify resolver 2023-05-26 17:14:34 +02:00
Wim Looman 620f66fa92
Mention workspace root's manifest explicitly 2023-05-26 16:41:04 +02:00
Ed Page 29dc47fa9a refactor(tests): Reduce cargo-add setup load
This just gets rid of irrelevant packages in the registry.  Looking into
which versions aren't needed would require a deeper pass, so I held off
on that for now.

Before, the tests were in the 300-500ms range and now they take
100-300ms.

This did call to my attention that `unrelated` is misspelled as
`unrelateed` but holding off on fixing that to reduce conflicts.
2023-05-26 09:24:45 -05:00
Wim Looman 2e2b3c1f1e
Warn when an edition 2021 crate is in a virtual workspace with default resolver
Edition 2021 updates the default resolver to version "2", but developers
using virtual workspaces commonly don't get this update because the
virtual workspace defaults to version "1". Warn when this situation
occurs so those developers can explicitly configure their workspace and
will be more likely to know that they will need to update it in the
future.
2023-05-26 16:11:09 +02:00
bors b9b5a45e3c Auto merge of #12184 - epage:rm, r=weihanglo
refactor(tests): Reduce cargo-remove setup load

This reduces the number of packages published in tests.  This is an artifact of when I changed `cargo-edit` from relying on crates.io to test-generated published packages.  I took the fastest path to making that conversion and took the shortcut of creating everything for every test.  I had assumed the cost was low but `@Muscraft` noticed that this takes up a lot of space which we run out of on CI occasionally and I expect a lot of small files are slowing down windows.

This only updates `cargo-remove`.  I'll be doing a follow up for `cargo-add`.
2023-05-26 13:53:32 +00:00
Ed Page ad9a44ddde refactor(tests): Reduce cargo-remove setup load
Benefits
- Clarifies a tests needs
- Speeds up testing, especially on Windows
- Reduces disk space issues within CI
2023-05-25 13:43:16 -05:00
bors fc905782cf Auto merge of #12174 - hi-rustin:rustin-patch-lints, r=epage
Automatically inherit workspace lints when running cargo new/init
2023-05-24 13:46:51 +00:00
bors 092db788d1 Auto merge of #12022 - jyn514:debuginfo-tests, r=weihanglo
Test that the new `debuginfo` options match between cargo and rustc

As requested in https://github.com/rust-lang/cargo/pull/11958#issuecomment-1518684469.

r? `@ehuss`
2023-05-24 06:59:49 +00:00
jyn e319c2c039 Test that the new debuginfo options match between cargo and rustc 2023-05-23 22:00:17 -05:00
hi-rustin 6573701227 Add inherit_workspace_lints test
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-05-24 10:36:06 +08:00
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