Commit graph

12427 commits

Author SHA1 Message Date
Arlo Siemsen 445db94bfe Make -Z http-registry use index.crates.io by default 2022-06-07 15:30:34 -05:00
bors bc3b99d0ff Auto merge of #10717 - jsitnicki:respect-git-submod-update-none, r=epage
Respect submodule update=none strategy in .gitmodules

Git lets users define the default update/checkout strategy for a submodule
by setting the `submodule.<name>.update` key in `.gitmodules` file.

If the update strategy is `none`, the submodule will be skipped during
update. It will not be fetched and checked out:

1. *foo* is a big git repo

```
/tmp $ git init foo
Initialized empty Git repository in /tmp/foo/.git/
/tmp $ dd if=/dev/zero of=foo/big bs=1000M count=1
1+0 records in
1+0 records out
1048576000 bytes (1.0 GB, 1000 MiB) copied, 0.482087 s, 2.2 GB/s
/tmp $ git -C foo add big
/tmp $ git -C foo commit -m 'I am big'
[main (root-commit) 84fb533] I am big
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 big
```

2. *bar* is a repo with a big submodule with `update=none`

```
/tmp $ git init bar
Initialized empty Git repository in /tmp/bar/.git/
/tmp $ git -C bar submodule add file:///tmp/foo foo
Cloning into '/tmp/bar/foo'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 1 (delta 0), pack-reused 0
Receiving objects: 100% (3/3), 995.50 KiB | 338.00 KiB/s, done.
/tmp $ git -C bar config --file .gitmodules submodule.foo.update none
/tmp $ cat bar/.gitmodules
[submodule "foo"]
        path = foo
        url = file:///tmp/foo
        update = none
/tmp $ git -C bar commit --all -m 'I have a big submodule with update=none'
[main (root-commit) 6c355ea] I have a big submodule not updated by default
 2 files changed, 4 insertions(+)
 create mode 100644 .gitmodules
 create mode 160000 foo
```

3. *baz* is a clone of *bar*, notice *foo* submodule gets skipped

```
/tmp $ git clone --recurse-submodules file:///tmp/bar baz
Cloning into 'baz'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (3/3), done.
Submodule 'foo' (file:///tmp/foo) registered for path 'foo'
Skipping submodule 'foo'
/tmp $ git -C baz submodule update --init
Skipping submodule 'foo'
/tmp $
```

Cargo, on the other hand, ignores the submodule update strategy set in
`.gitmodules` properties when updating dependencies. Such behavior can
be considered against the wish of the crate publisher.

4. *bar* is now a lib with a big submodule with update disabled

```
/tmp $ cargo init --lib bar
     Created library package
/tmp $ git -C bar add .
/tmp $ git -C bar commit -m 'I am a lib with a big submodule but update=none'
[main eb07cf7] I am a lib with a big submodule but update=none
 3 files changed, 18 insertions(+)
 create mode 100644 .gitignore
 create mode 100644 Cargo.toml
 create mode 100644 src/lib.rs
/tmp $
```

5. *qux* depends on *bar*, notice *bar*'s submodules are fetched

```
/tmp $ cargo init qux && cd qux
     Created binary (application) package
/tmp/qux $ echo -e '[dependencies.bar]\ngit = "file:///tmp/bar"' >> Cargo.toml
/tmp/qux $ time cargo update
    Updating git repository `file:///tmp/bar`
    Updating git submodule `file:///tmp/foo`

real    0m22.182s
user    0m20.402s
sys     0m1.714s
/tmp/qux $
```

Fix it by checking if a Git repository submodule should be updated when
cargo processes dependencies.

6. With the change applied, submodules with `update=none` are skipped

```
/tmp/qux $ cargo cache -a > /dev/null
/tmp/qux $ time ~/src/cargo/target/debug/cargo update
    Updating git repository `file:///tmp/bar`
    Skipping git submodule `file:///tmp/foo`

real    0m0.029s
user    0m0.021s
sys     0m0.008s
/tmp/qux $
```

Fixes #4247.
2022-06-07 14:29:02 +00:00
Jakub Sitnicki 26031b9069 Respect submodule update=none strategy in .gitmodules
Git lets users define the default update/checkout strategy for a submodule
by setting the `submodule.<name>.update` key in `.gitmodules` file.

If the update strategy is `none`, the submodule will be skipped during
update. It will not be fetched and checked out:

1. *foo* is a big git repo

```
/tmp $ git init foo
Initialized empty Git repository in /tmp/foo/.git/
/tmp $ dd if=/dev/zero of=foo/big bs=1000M count=1
1+0 records in
1+0 records out
1048576000 bytes (1.0 GB, 1000 MiB) copied, 0.482087 s, 2.2 GB/s
/tmp $ git -C foo add big
/tmp $ git -C foo commit -m 'I am big'
[main (root-commit) 84fb533] I am big
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 big
```

2. *bar* is a repo with a big submodule with `update=none`

```
/tmp $ git init bar
Initialized empty Git repository in /tmp/bar/.git/
/tmp $ git -C bar submodule add file:///tmp/foo foo
Cloning into '/tmp/bar/foo'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 1 (delta 0), pack-reused 0
Receiving objects: 100% (3/3), 995.50 KiB | 338.00 KiB/s, done.
/tmp $ git -C bar config --file .gitmodules submodule.foo.update none
/tmp $ cat bar/.gitmodules
[submodule "foo"]
        path = foo
        url = file:///tmp/foo
        update = none
/tmp $ git -C bar commit --all -m 'I have a big submodule with update=none'
[main (root-commit) 6c355ea] I have a big submodule not updated by default
 2 files changed, 4 insertions(+)
 create mode 100644 .gitmodules
 create mode 160000 foo
```

3. *baz* is a clone of *bar*, notice *foo* submodule gets skipped

```
/tmp $ git clone --recurse-submodules file:///tmp/bar baz
Cloning into 'baz'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (3/3), done.
Submodule 'foo' (file:///tmp/foo) registered for path 'foo'
Skipping submodule 'foo'
/tmp $ git -C baz submodule update --init
Skipping submodule 'foo'
/tmp $
```

Cargo, on the other hand, ignores the submodule update strategy set in
`.gitmodules` properties when updating dependencies. Such behavior can
be considered against the wish of the crate publisher.

4. *bar* is now a lib with a big submodule with update disabled

```
/tmp $ cargo init --lib bar
     Created library package
/tmp $ git -C bar add .
/tmp $ git -C bar commit -m 'I am a lib with a big submodule but update=none'
[main eb07cf7] I am a lib with a big submodule but update=none
 3 files changed, 18 insertions(+)
 create mode 100644 .gitignore
 create mode 100644 Cargo.toml
 create mode 100644 src/lib.rs
/tmp $
```

5. *qux* depends on *bar*, notice *bar*'s submodules are fetched

```
/tmp $ cargo init qux && cd qux
     Created binary (application) package
/tmp/qux $ echo -e '[dependencies.bar]\ngit = "file:///tmp/bar"' >> Cargo.toml
/tmp/qux $ time cargo update
    Updating git repository `file:///tmp/bar`
    Updating git submodule `file:///tmp/foo`

real    0m22.182s
user    0m20.402s
sys     0m1.714s
/tmp/qux $
```

Fix it by checking if a Git repository submodule should be updated when
cargo processes dependencies.

6. With the change applied, submodules with `update=none` are skipped

```
/tmp/qux $ cargo cache -a > /dev/null
/tmp/qux $ time ~/src/cargo/target/debug/cargo update
    Updating git repository `file:///tmp/bar`
    Skipping git submodule `file:///tmp/foo`

real    0m0.029s
user    0m0.021s
sys     0m0.008s
/tmp/qux $
```

Fixes #4247.

Signed-off-by: Jakub Sitnicki <jakub@cloudflare.com>
2022-06-07 14:52:02 +02:00
Jason Orendorff c586652fdf
Update manifest.md
Remove comment from example toml to prose.
2022-06-06 11:55:47 -05:00
bors 7d289b1711 Auto merge of #10713 - flip1995:rust-version-env, r=epage
Expose rust-version through env var

This adds another env var that is exposed by cargo. In Clippy we would like to use that in order to efficiently check if a rust-version is set for the current package: https://github.com/rust-lang/rust-clippy/pull/8774

Currently we either have to parse the `Cargo.toml` file ourselves or use the `cargo_metadata` crate which has a notable performance impact when running `clippy-driver` on single files.
2022-06-06 13:19:38 +00:00
flip1995 0852f5413e
Expose rust-version through env var 2022-06-06 12:04:20 +02:00
bors a9efb069c4 Auto merge of #10676 - djmcgill:origin/master, r=weihanglo
add validation for string "true"/"false" in lto profile

### What does this PR try to resolve?
Adds a special-cased error message for when `lto` is set to the _string_ `"true"`/`"false"` which is surprisingly (I was surprised anyway) not allowed and the error message is ambiguous. The new error message makes it clear what values are accepted.
Fixes https://github.com/rust-lang/cargo/issues/10572

### 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 -->

Uh I've not actually tested yet that's the WIP part. But put
```
[profile.dev]
lto="false"
```
in your TOML and run `cargo build`, check that you get the new error message and that it makes sense and is helpful.

### Additional information

It's worth noting that as per https://github.com/rust-lang/rust/pull/97051 this doesn't fix the _real_ problem here IMO which is that [rust's `opt_parse_bool` cli parsing](491f619f56/compiler/rustc_session/src/options.rs (L456)) doesn't accept true/false which certainly seems an ad-hoc historical choice to me on first glance but also it's a much bigger change to change those semantics than this error message.
2022-06-05 23:03:21 +00:00
David McGillicuddy 0daf70d816 Special case the string true/false error message for LTO profile arg 2022-06-05 23:30:29 +01:00
bors cce487e13d Auto merge of #10726 - weihanglo:test-doc-enhance, r=epage
Enhance documentation of testing
2022-06-05 17:21:25 +00:00
Eric Huss 5d336093e8 Small wording tweak. 2022-06-05 10:20:53 -07:00
Weihang Lo 38aea8e057
doc: don't mention #[test] in cargo-bench doc
This is too details and not for averaged users.
2022-06-04 21:43:58 +08:00
Weihang Lo f691a3865a
doc: add **Note**: to make quote block like a note 2022-06-04 21:28:03 +08:00
Weihang Lo dd8841f6f3
Rephrase wordings in testing docs
- Rephrase doctest exec model as "not guranteed and may change" instead
- Mention `#[bench]` in what cargo-bench automatically runs
- Make it clear for build/rustc when mentioning bin targets auto-built
2022-06-04 08:24:08 +08:00
Jason Orendorff 471c410c3f
Update manifest.md
clearer example
2022-06-03 10:32:03 -05:00
Weihang Lo fc6b3cc3b6
doc: execution model of doctest
NOTE: This is an undocumented implementation details.
2022-06-03 20:50:02 +08:00
Weihang Lo af0fbf4277
doc: mention cargo test runs test targets serially 2022-06-03 20:28:46 +08:00
Weihang Lo 2c9cfd6485
doc: add more link references for tests guide
- Mention that in `src/` Cargo also collect doc tests.
- Remove outdated statement: Cargo no longer tests examples by default.
- Add a link to "Cargo Targets: Tests" to help people learn about it.
2022-06-03 19:50:23 +08:00
Weihang Lo 370a481b43
doc: mention binary auto-built for build,bench,test,rustc 2022-06-03 19:49:15 +08:00
Weihang Lo 7860458149
doc: highlight --doc only applied on lib target 2022-06-03 19:47:23 +08:00
bors 03e22354d0 Auto merge of #10724 - ehuss:ci-disk-space, r=Eh2406
Clear disk space on CI.

Cargo's testsuite uses a considerable amount of disk space. On windows-gnu, the target directory can get over 12GB, and there is only 13GB free.  We're starting to run out of disk space, so this is a stop-gap that clears out the test data before running the smoke test which uses a fair bit of space itself.

We will probably need to think about addressing #9701 somehow, otherwise we will start running out of space as we add more tests. See the linked issues in https://github.com/rust-lang/cargo/pull/9701#issuecomment-881765517 for additional context.
2022-06-03 02:57:12 +00:00
Eric Huss 65cc01075e Clear disk space on CI. 2022-06-02 17:55:45 -07:00
bors af491f39a0 Auto merge of #10720 - JohnTitor:use-latest-tar, r=ehuss
Enforce to use tar v0.4.38

The latest version of `tar` crate includes https://github.com/alexcrichton/tar-rs/pull/262, which uses a bit recent timestamp when archiving.
However, [it seems rust-lang/rust uses v0.4.37](e094492200/Cargo.lock (L5124-L5132)). This PR enforces to use v0.4.38 and it would _fix_ https://github.com/rust-lang/crates.io/issues/3859 eventually.
2022-06-01 13:32:11 +00:00
Yuki Okushi 819f7a5cff
Enforce to use tar v0.4.38 2022-06-01 19:17:15 +09:00
bors 38472bc19f Auto merge of #10701 - danilhendrasr:master, r=weihanglo
Emit warning upon encountering multiple packages with the same name

Fixes: #10669
2022-05-31 02:03:24 +00:00
bors ca4edabb28 Auto merge of #10706 - merelymyself:master, r=epage
Guide new users to add use `super::*;` to `mod test`

### What does this PR try to resolve?

Currently, `cargo init --lib` produces examples for unit tests. However, new users will find that they are unable to use functions they defined above. This should resolve the confusion.

Fixes #10559

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

This PR does not create new features. Test this PR using the already-existing tests.

### Additional information

I didn't think this was a major change, so I did not open a RFC for it. Please let me know if I should have!
2022-05-29 02:13:39 +00:00
Danil Hendra Suryawan e903f7dfc0 Emit warning upon encountering ambiguous deps 2022-05-28 03:32:04 +00:00
merelymyself 754a5bfbaa whitespace 2 2022-05-28 00:17:57 +08:00
merelymyself 684a338693 whitespace 2022-05-28 00:14:30 +08:00
merelymyself 3d21b14323 Guide new users to add use super::*; to mod test 2022-05-27 23:41:37 +08:00
bors e0e1df99f6 Auto merge of #10708 - svenstaro:patch-1, r=weihanglo
Document how to debug change detection events

### What does this PR try to resolve?

I noticed that my build would sometimes seemingly randomly rebuild other crates. I figured this must be the build script detecting a change in some external files. In order to debug this, I figured I'd look at the Cargo sources whether something like this was already being logged. Thankfully, the logging for this was already in place but I didn't find it documented anyway so I thought it might be rather helpful in such scenarios.

I believe it's a common enough scenario that inclusion into the official documentation on this topic should be considered.

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

Build/view documentation.

### Additional information
2022-05-27 12:35:25 +00:00
Sven-Hendrik Haase 16e4c29587
Document how to debug change detection events
This merely links to the FAQ which already explains this
topic very well.
2022-05-27 14:20:03 +02:00
bors e23cf4393f Auto merge of #10677 - likzn:fix_publish_p, r=ehuss
fix(publish): add more check when use `publish -p <SPEC>`

### Main issue
As issue say #10536 , we need add more check when user use `cargo publish -p <SPEC>`

>`@ehuss` point outs:
>From a behavior standpoint, here are some things to check:
> - In the root of a virtual workspace, it should be an error to run without -p.
>- It should be an error to pass -p for a non-workspace member.
>- It should be an error for -p to match multiple packages.
>- When using -p, it should publish that package, not the one in the current directory (which can be different).
2022-05-27 00:43:33 +00:00
bors 8f5500bb5a Auto merge of #10705 - Muscraft:workspace-source-fmt-key, r=epage
fix key formatting when switching to a dotted `WorkspaceSource`

This fell out of #10697 see [this comment](https://github.com/rust-lang/cargo/pull/10697#discussion_r882691624)

There was a small issue where changing the source of a `cargo_add::Dependency` to a `WorkspaceSource` would cause the dotted version to have extra space.

```toml
dep .workspace = true
dep.workspace = true
```

This makes sure the key is formatted as well as adds a unit test to make sure this doesn't come back up in the future.

r? `@epage`
2022-05-26 23:53:56 +00:00
Scott Schafer 706e5b25c9 fix key formatting when switching to a dotted WorkspaceSource 2022-05-26 14:02:00 -05:00
likzn b486ada19f clean err msg 2022-05-26 08:49:06 +08:00
likzn 52165e8c2d update 2022-05-25 18:17:08 +08:00
bors 39ad1039d9 Auto merge of #10600 - tmfink:doc-build-script-link-order, r=ehuss
doc: discuss build script instruction order

### What does this PR try to resolve?

It is currently not documented that the order of build script `cargo:` instructions may be relevant to linking.

This has caused issues such as: https://github.com/rust-lang/rust/issues/96328

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

Build/view documentation.

### Additional information

- Cargo maintainers should fact check my wording.
- We may need to discuss if this should also be documented for `rustc`
- Maintainers should ensure that this change does not prevent a change in what is currently unspecified behavior. Perhaps `cargo` will want to rearrange link arguments itself to resolve issues in the future?
2022-05-25 00:50:02 +00:00
Travis Finkenauer 43ce1e7a98 Test that link argument order is maintained
Patch provided by @ehuss
2022-05-24 12:45:20 -07:00
Travis Finkenauer 10cf701de7 doc: discuss build script instruction order 2022-05-24 12:45:20 -07:00
bors e7c8ba7753 Auto merge of #10698 - arlosi:http-slash, r=Eh2406
Require http-registry URLs to end with a '/'

The `url` crate normalizes URLs with no path component to end in a trailing slash. This causes the current implementation to use urls containing two slashes for registries without a path component (such as `https://index.crates.io//config.json`).

This PR resolves the issue by requiring http registry URLs to end in a slash and generating paths by concatenating. A new error message is emitted for http registry URLs that do not end in a slash.

r? `@Eh2406`
2022-05-24 15:23:47 +00:00
bors bf824127cc Auto merge of #10691 - danilhendrasr:master, r=weihanglo
No printing executable names when running tests and benchmarks with json message format

Fixes: #10684
I added a new test for this, though I'm not sure if it's necessary. Let me know if I should delete it.
2022-05-24 14:42:56 +00:00
Danil Hendra Suryawan e04d7772e4 No printing executable names when running benches with json message format 2022-05-24 20:44:54 +07:00
merelymyself 8401ef16f6 fixed issue with formats_source 2022-05-24 20:42:26 +08:00
merelymyself 73aa070687 Guide new users to add use super::*; 2022-05-24 20:27:58 +08:00
Arlo Siemsen 2622074d43 Require http-registry URLs to end with a '/' 2022-05-23 21:39:23 -05:00
likzn 72d6c5411a cargo fmt 2022-05-24 09:15:44 +08:00
likzn ddd5c83b8c rust fmt 2022-05-24 09:15:02 +08:00
likzn 72457ef462 fix test stderr 2022-05-24 09:09:57 +08:00
bors 11d4599d32 Auto merge of #10683 - jonhoo:fix-10682, r=Eh2406
Restore proper error for crate not in local reg

Fixes #10682.
2022-05-23 17:34:13 +00:00
likzn d8280951eb
Update src/cargo/ops/registry.rs with err msg
Co-authored-by: Eric Huss <eric@huss.org>
2022-05-24 00:58:33 +08:00