10103 Commits

Author SHA1 Message Date
brian m. carlson
e46ca84b6c
package: canonicalize tar headers for crate packages
Currently, when reading a file from disk, we include several pieces of
data from the on-disk file, including the user and group names and IDs,
the device major and minor, the mode, and the timestamp.  This means
that our archives differ between systems, sometimes in unhelpful ways.

In addition, most users probably did not intend to share information
about their user and group settings, operating system and disk type, and
umask.  While these aren't huge privacy leaks, cargo doesn't use them
when extracting archives, so there's no value to including them.

Since using consistent data means that our archives are reproducible and
don't leak user data, both of which are desirable features, let's
canonicalize the header to strip out identifying information.

We set the user and group information to 0 and root, since that's the
only user that's typically consistent among Unix systems.  Setting
these values doesn't create a security risk since tar can't change the
ownership of files when it's running as a normal unprivileged user.

Similarly, we set the device major and minor to 0.  There is no useful
value here that's portable across systems, and it does not affect
extraction in any way.

We also set the timestamp to the same one that we use for generated
files.  This is probably the biggest loss of relevant data, but
considering that cargo doesn't otherwise use it and honoring it makes
the archives unreproducible, we canonicalize it as well.

Finally, we canonicalize the mode of an item we're storing by looking at
the executable bit and using mode 755 if it's set and mode 644 if it's
not.  We already use 644 as the default for generated files, and this is
the same algorithm that Git uses to determine whether a file should be
considered executable.  The tests don't test this case because there's
no portable way to create executable files on Windows.
2020-11-16 01:46:10 +00:00
brian m. carlson
436b9eb85d
package: honor SOURCE_DATE_EPOCH
For projects supporting reproducible builds, it's possible to set the
timestamp used in artifacts by setting SOURCE_DATE_EPOCH to a decimal
Unix timestamp.  This is helpful because it allows users to produce the
exact same artifact, regardless of when the project was built, and it
also means that services which generate crates from source can generate
a consistent crate without having store previously built artifacts.

For all these reasons, let's honor the SOURCE_DATE_EPOCH environment
variable if it's set and use the current timestamp if it's not.
2020-11-15 22:11:59 +00:00
brian m. carlson
9cc7ac618b
package: use a consistent timestamp
For each entry in the tar archive, we generate a new timestamp.
Normally cargo will be fast enough that we get a consistent timestamp,
but that need not be the case.  There's very little reason to produce
different timestamps for different files and it's slightly more
efficient not to need to make multiple queries, so let's instead
generate a single timestamp for all entries that we generate.
2020-11-15 22:11:59 +00:00
bors
2af662e221 Auto merge of #8853 - ehuss:fix-namespaced-publish, r=Eh2406
Fix publishing with optional dependencies.

In #8799, I neglected to update the `publish` code to use the correct features when generating the JSON to upload to the registry. The `Cargo.toml` file was correctly updated, but the JSON was not.  This caused Cargo to send the implicit `dep:` feature syntax in the JSON blob, which crates.io rejects.  The solution here is to use the original feature map before the implicit features have been added.
2020-11-12 19:04:56 +00:00
Eric Huss
2a07061b38 Fix publishing with optional dependencies. 2020-11-12 10:44:10 -08:00
bors
770f403590 Auto merge of #8851 - lfrancke:patch-1, r=ehuss
Minor typo in features.md

Just a very minor typo

(that said: these docs don't actually explain what a Feature group is before using the term, but that's for another issue)
2020-11-12 14:15:47 +00:00
Lars Francke
f3519d7964
Update features.md
Just a very minor typo

(that said: these docs don't actually explain what a Feature group is before using the term, but that's for another issue)
2020-11-12 12:22:01 +01:00
bors
8662ab427a Auto merge of #8834 - Gankra:rust-src-vendor, r=ehuss
Check if rust-src contains a vendor dir, and patch it in

This is the cargo side of https://github.com/rust-lang/wg-cargo-std-aware/issues/23

Note that this design naively assumes there is only one version of each package. It does not robustly verify this, and will presumably just cryptically fail to resolve dependencies.

See https://github.com/rust-lang/rust/pull/78790 for the other half of this change.
2020-11-12 03:47:53 +00:00
Eric Huss
85b5b180f4 Add error context for reading vendor dir. 2020-11-11 19:35:20 -08:00
bors
af212d5a22 Auto merge of #8837 - bjorn3:improve_perf, r=alexcrichton
Improve performance of almost fresh builds

This currently saves about 15ms out of the 170ms Cargo overhead when compiling Bevy.

part of https://github.com/rust-lang/cargo/issues/8833

<details><summary>Benchmark results as of <a href="602a1bd7f5"><code>602a1bd</code></a></summary>

Completely fresh:

```
$ RUSTC=$(rustup which rustc) hyperfine --warmup 10 --runs 100 "../../cargo/cargo_master build --release --example breakout" "../../cargo/cargo_improve_perf build --release --example breakout"
Benchmark #1: ../../cargo/cargo_master build --release --example breakout
  Time (mean ± σ):     613.8 ms ± 509.1 ms    [User: 147.6 ms, System: 38.4 ms]
  Range (min … max):   170.8 ms … 1199.2 ms    100 runs

  Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet PC without any interferences from other programs. It might help to use the '--warmup' or '--prepare' options.

Benchmark #2: ../../cargo/cargo_improve_perf build --release --example breakout
  Time (mean ± σ):     164.2 ms ±   0.8 ms    [User: 137.0 ms, System: 27.1 ms]
  Range (min … max):   162.8 ms … 169.6 ms    100 runs

Summary
  '../../cargo/cargo_improve_perf build --release --example breakout' ran
    3.74 ± 3.10 times faster than '../../cargo/cargo_master build --release --example breakout'
```

(statistical outliers are consistently reproducible and don't happen for any other benchmarks)

```
$ RUSTC=$(rustup which rustc) perf stat -r10 ../../cargo/cargo_master build --release --example breakout
    Finished release [optimized] target(s) in 0.16s
[...]
    Finished release [optimized] target(s) in 0.16s

 Performance counter stats for '../../cargo/cargo_master build --release --example breakout' (10 runs):

            192,95 msec task-clock:u              #    0,242 CPUs utilized            ( +-  0,69% )
                 0      context-switches:u        #    0,000 K/sec
                 0      cpu-migrations:u          #    0,000 K/sec
              4926      page-faults:u             #    0,026 M/sec                    ( +-  0,11% )
         387516813      cycles:u                  #    2,008 GHz                      ( +-  0,69% )
         685141858      instructions:u            #    1,77  insn per cycle           ( +-  0,04% )
         124443483      branches:u                #  644,958 M/sec                    ( +-  0,05% )
           2726944      branch-misses:u           #    2,19% of all branches          ( +-  0,10% )

             0,796 +- 0,168 seconds time elapsed  ( +- 21,06% )
$ RUSTC=$(rustup which rustc) perf stat -r10 ../../cargo/cargo_improve_perf build --release --example breakout
    Finished release [optimized] target(s) in 0.14s
[...]
    Finished release [optimized] target(s) in 0.15s

 Performance counter stats for '../../cargo/cargo_improve_perf build --release --example breakout' (10 runs):

            168,78 msec task-clock:u              #    0,997 CPUs utilized            ( +-  0,56% )
                 0      context-switches:u        #    0,000 K/sec
                 0      cpu-migrations:u          #    0,000 K/sec
              4075      page-faults:u             #    0,024 M/sec                    ( +-  0,16% )
         372565970      cycles:u                  #    2,207 GHz                      ( +-  0,61% )
         667356921      instructions:u            #    1,79  insn per cycle           ( +-  0,03% )
         120170432      branches:u                #  712,010 M/sec                    ( +-  0,04% )
           2642670      branch-misses:u           #    2,20% of all branches          ( +-  0,12% )

          0,169294 +- 0,000933 seconds time elapsed  ( +-  0,55% )
```

Need to recompile single executable:

```
$ RUSTC=$(rustup which rustc) hyperfine --warmup 10 --runs 100 "touch examples/game/breakout.rs && ../../cargo/cargo_master build --release --example breakout" "touch examples/game/breakout.rs && ../../cargo/cargo_improve_perf build --release --example breakout"
Benchmark #1: touch examples/game/breakout.rs && ../../cargo/cargo_master build --release --example breakout
  Time (mean ± σ):     658.9 ms ±   1.8 ms    [User: 538.6 ms, System: 181.1 ms]
  Range (min … max):   655.5 ms … 668.8 ms    100 runs

Benchmark #2: touch examples/game/breakout.rs && ../../cargo/cargo_improve_perf build --release --example breakout
  Time (mean ± σ):     648.6 ms ±   2.1 ms    [User: 534.7 ms, System: 162.6 ms]
  Range (min … max):   645.2 ms … 659.5 ms    100 runs

Summary
  'touch examples/game/breakout.rs && ../../cargo/cargo_improve_perf build --release --example breakout' ran
    1.02 ± 0.00 times faster than 'touch examples/game/breakout.rs && ../../cargo/cargo_master build --release --example breakout'
```

```
$ RUSTC=$(rustup which rustc) perf stat -r10 --no-inherit --pre "touch examples/game/breakout.rs" ../../cargo/cargo_master build --release --example breakout
   Compiling bevy v0.3.0 (/home/bjorn/Documenten/cg_clif3/bevy)
    Finished release [optimized] target(s) in 0.67s
[...]
   Compiling bevy v0.3.0 (/home/bjorn/Documenten/cg_clif3/bevy)
    Finished release [optimized] target(s) in 0.66s

 Performance counter stats for '../../cargo/cargo_master build --release --example breakout' (10 runs):

            183,65 msec task-clock:u              #    0,265 CPUs utilized            ( +-  1,08% )
                 0      context-switches:u        #    0,000 K/sec
                 0      cpu-migrations:u          #    0,000 K/sec
              6603      page-faults:u             #    0,036 M/sec                    ( +-  0,11% )
         382629371      cycles:u                  #    2,083 GHz                      ( +-  0,79% )
         673192095      instructions:u            #    1,76  insn per cycle           ( +-  0,03% )
         121518254      branches:u                #  661,688 M/sec                    ( +-  0,04% )
           2698503      branch-misses:u           #    2,22% of all branches          ( +-  0,18% )

           0,69376 +- 0,00274 seconds time elapsed  ( +-  0,39% )
$ RUSTC=$(rustup which rustc) perf stat -r10 --no-inherit --pre "touch examples/game/breakout.rs" ../../cargo/cargo_improve_perf build --release --example breakout
   Compiling bevy v0.3.0 (/home/bjorn/Documenten/cg_clif3/bevy)
    Finished release [optimized] target(s) in 0.66s
[...]
   Compiling bevy v0.3.0 (/home/bjorn/Documenten/cg_clif3/bevy)
    Finished release [optimized] target(s) in 0.76s

 Performance counter stats for '../../cargo/cargo_improve_perf build --release --example breakout' (10 runs):

            177,03 msec task-clock:u              #    0,256 CPUs utilized            ( +-  1,70% )
                 0      context-switches:u        #    0,000 K/sec
                 0      cpu-migrations:u          #    0,000 K/sec
              5774      page-faults:u             #    0,033 M/sec                    ( +-  0,14% )
         381121369      cycles:u                  #    2,153 GHz                      ( +-  1,29% )
         672129390      instructions:u            #    1,76  insn per cycle           ( +-  0,03% )
         121248111      branches:u                #  684,900 M/sec                    ( +-  0,04% )
           2672832      branch-misses:u           #    2,20% of all branches          ( +-  0,34% )

            0,6924 +- 0,0148 seconds time elapsed  ( +-  2,13% )
```

</details>

<details><summary>Benchmark results as of <a href="ba49b13e65"><code>ba49b13</code></a></summary>

Completely fresh:

```
$ RUSTC=$(rustup which rustc) hyperfine --warmup 10 --runs 100 "../../cargo/cargo_master build --release --example breakout" "../../cargo/cargo_improve_perf2 build --release --example breakout"
Benchmark #1: ../../cargo/cargo_master build --release --example breakout
  Time (mean ± σ):     635.4 ms ± 511.6 ms    [User: 146.2 ms, System: 41.1 ms]
  Range (min … max):   172.0 ms … 1208.7 ms    100 runs

  Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet PC without any interferences from other programs. It might help to use the '--warmup' or '--prepare' options.

Benchmark #2: ../../cargo/cargo_improve_perf2 build --release --example breakout
  Time (mean ± σ):     165.3 ms ±   1.2 ms    [User: 137.2 ms, System: 28.0 ms]
  Range (min … max):   163.7 ms … 171.0 ms    100 runs

Summary
  '../../cargo/cargo_improve_perf2 build --release --example breakout' ran
    3.84 ± 3.09 times faster than '../../cargo/cargo_master build --release --example breakout'
```

(statistical outliers are consistently reproducible and don't happen for any other benchmarks)

```
$ RUSTC=$(rustup which rustc) perf stat -r10 ../../cargo/cargo_master build --release --example breakout
    Finished release [optimized] target(s) in 0.16s
[...]
    Finished release [optimized] target(s) in 0.16s

 Performance counter stats for '../../cargo/cargo_master build --release --example breakout' (10 runs):

            197,21 msec task-clock:u              #    0,220 CPUs utilized            ( +-  0,79% )
                 0      context-switches:u        #    0,000 K/sec
                 0      cpu-migrations:u          #    0,000 K/sec
              4918      page-faults:u             #    0,025 M/sec                    ( +-  0,09% )
         395214529      cycles:u                  #    2,004 GHz                      ( +-  0,71% )
         685707083      instructions:u            #    1,74  insn per cycle           ( +-  0,04% )
         124571038      branches:u                #  631,667 M/sec                    ( +-  0,05% )
           2748386      branch-misses:u           #    2,21% of all branches          ( +-  0,35% )

             0,897 +- 0,155 seconds time elapsed  ( +- 17,32% )
$ RUSTC=$(rustup which rustc) perf stat -r10 ../../cargo/cargo_improve_perf2 build --release --example breakout
    Finished release [optimized] target(s) in 0.14s
[...]
    Finished release [optimized] target(s) in 0.15s

 Performance counter stats for '../../cargo/cargo_improve_perf2 build --release --example breakout' (10 runs):

            168,28 msec task-clock:u              #    0,621 CPUs utilized            ( +-  0,51% )
                 0      context-switches:u        #    0,000 K/sec
                 0      cpu-migrations:u          #    0,000 K/sec
              4086      page-faults:u             #    0,024 M/sec                    ( +-  0,15% )
         371029906      cycles:u                  #    2,205 GHz                      ( +-  0,48% )
         667493108      instructions:u            #    1,80  insn per cycle           ( +-  0,02% )
         120202436      branches:u                #  714,308 M/sec                    ( +-  0,03% )
           2659209      branch-misses:u           #    2,21% of all branches          ( +-  0,13% )

             0,271 +- 0,103 seconds time elapsed  ( +- 37,82% )
```

Need to recompile single executable:

```
$ RUSTC=$(rustup which rustc) hyperfine --warmup 10 --runs 100 "touch examples/game/breakout.rs && ../../cargo/cargo_master build --release --example breakout" "touch examples/game/breakout.rs && ../../cargo/cargo_improve_perf2 build --release --example breakout"
Benchmark #1: touch examples/game/breakout.rs && ../../cargo/cargo_master build --release --example breakout
  Time (mean ± σ):     660.7 ms ±   2.9 ms    [User: 545.6 ms, System: 175.2 ms]
  Range (min … max):   656.2 ms … 675.1 ms    100 runs

Benchmark #2: touch examples/game/breakout.rs && ../../cargo/cargo_improve_perf2 build --release --example breakout
  Time (mean ± σ):     650.2 ms ±   5.3 ms    [User: 542.9 ms, System: 156.0 ms]
  Range (min … max):   645.9 ms … 687.7 ms    100 runs

  Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet PC without any interferences from other programs. It might help to use the '--warmup' or '--prepare' options.

Summary
  'touch examples/game/breakout.rs && ../../cargo/cargo_improve_perf2 build --release --example breakout' ran
    1.02 ± 0.01 times faster than 'touch examples/game/breakout.rs && ../../cargo/cargo_master build --release --example breakout'
```

```
$ RUSTC=$(rustup which rustc) perf stat -r10 --no-inherit --pre "touch examples/game/breakout.rs" ../../cargo/cargo_master build --release --example breakout
   Compiling bevy v0.3.0 (/home/bjorn/Documenten/cg_clif3/bevy)
    Finished release [optimized] target(s) in 0.65s
[...]
   Compiling bevy v0.3.0 (/home/bjorn/Documenten/cg_clif3/bevy)
    Finished release [optimized] target(s) in 0.66s

 Performance counter stats for '../../cargo/cargo_master build --release --example breakout' (10 runs):

            181,52 msec task-clock:u              #    0,264 CPUs utilized            ( +-  0,29% )
                 0      context-switches:u        #    0,000 K/sec
                 0      cpu-migrations:u          #    0,000 K/sec
              6618      page-faults:u             #    0,036 M/sec                    ( +-  0,09% )
         381324766      cycles:u                  #    2,101 GHz                      ( +-  0,21% )
         673170130      instructions:u            #    1,77  insn per cycle           ( +-  0,03% )
         121511051      branches:u                #  669,422 M/sec                    ( +-  0,04% )
           2700116      branch-misses:u           #    2,22% of all branches          ( +-  0,17% )

           0,68766 +- 0,00293 seconds time elapsed  ( +-  0,43% )
$ RUSTC=$(rustup which rustc) perf stat -r10 --no-inherit --pre "touch examples/game/breakout.rs" ../../cargo/cargo_improve_perf2 build --release --example breakout
   Compiling bevy v0.3.0 (/home/bjorn/Documenten/cg_clif3/bevy)
    Finished release [optimized] target(s) in 0.64s
[...]
   Compiling bevy v0.3.0 (/home/bjorn/Documenten/cg_clif3/bevy)
    Finished release [optimized] target(s) in 0.64s

 Performance counter stats for '../../cargo/cargo_improve_perf2 build --release --example breakout' (10 runs):

            173,78 msec task-clock:u              #    0,257 CPUs utilized            ( +-  0,65% )
                 0      context-switches:u        #    0,000 K/sec
                 0      cpu-migrations:u          #    0,000 K/sec
              5772      page-faults:u             #    0,033 M/sec                    ( +-  0,17% )
         378994346      cycles:u                  #    2,181 GHz                      ( +-  0,62% )
         672499584      instructions:u            #    1,77  insn per cycle           ( +-  0,04% )
         121341331      branches:u                #  698,266 M/sec                    ( +-  0,05% )
           2691563      branch-misses:u           #    2,22% of all branches          ( +-  0,17% )

           0,67554 +- 0,00641 seconds time elapsed  ( +-  0,95% )
```

</summary>
2020-11-11 22:11:34 +00:00
Alexis Beingessner
eadb4fc86c Check if rust-src contains a vendor dir, and patch it in
This is the cargo side of https://github.com/rust-lang/wg-cargo-std-aware/issues/23
2020-11-10 11:47:32 -05:00
bjorn3
50c0221ca3 Add some comments 2020-11-10 10:35:59 +01:00
bjorn3
0583081d2a Immediately print job output for fresh jobs
This prevents a deadlock where the message queue is filled with output
messages but not emptied as the job producing the messages runs on the
same thread as the message processing.
2020-11-10 10:35:34 +01:00
bjorn3
49b63b7caa [HACK] Fix deadlock by avoiding backpressure for fresh jobs 2020-11-10 10:33:37 +01:00
bjorn3
3836dfb32d Split Job::new into Job::new_fresh and Job::new_dirty 2020-11-10 10:33:37 +01:00
bjorn3
0c5f6f012e Don't spawn a new thread for fresh jobs
The overhead in doing so is often much higher than the actual time it
takes to execute the job
2020-11-10 10:33:37 +01:00
bors
1fc37008e1 Auto merge of #8847 - Xanewok:from-le-bytes, r=alexcrichton
Use u32/64::to/from_le_bytes instead of bit fiddling

What it says on the tin; it's just something I've spotted when browsing through the code and decided to search for other occurrences of casting to/from bytes.
2020-11-09 22:35:34 +00:00
Igor Matuszewski
aab416f6e6 Use u32/64::to/from_le_bytes instead of bit fiddling 2020-11-09 23:32:39 +01:00
bors
cc1291935f Auto merge of #8844 - bjorn3:no_backtrace_capture, r=alexcrichton
Avoid constructing an anyhow::Error when not necessary

`anyhow::Error` always captures a backtrace when created, which is expensive.

Split out of #8837
2020-11-09 16:57:03 +00:00
bjorn3
e643df0985 Simplify using unwrap_or_else 2020-11-09 17:38:31 +01:00
bjorn3
5af00d0e61 Always send message through FinishOnDrop 2020-11-09 17:21:18 +01:00
bors
03976afdd6 Auto merge of #8835 - steven-joruk:ignore-lock-files-in-packages, r=alexcrichton
Skip extracting .cargo-ok files from packages

This is for #8816

I'll look into adding a unit test tomorrow, I'm still familiarising myself with the project.
2020-11-09 15:19:50 +00:00
Steven Joruk
05a8127c10 Skip extracting .cargo-ok files from packages
This fixes the case where a package contained an empty .cargo-ok file
and was mounted in a read only file system. This lead to attempting to
download the package again, which failed due to write permissions.
2020-11-07 17:01:21 +00:00
bjorn3
821d8eaec3 Avoid constructing an anyhow::Error when not necessary
anyhow::Error always captures a backtrace when created, which is expensive
2020-11-07 13:48:31 +01:00
bors
d5556aeb84 Auto merge of #8818 - ehuss:weak-dep-features, r=alexcrichton
Implement weak dependency features.

This adds the feature syntax `dep_name?/feat_name` with a `?` to only enable `feat_name` if the optional dependency `dep_name` is enabled through some other means. See `unstable.md` for documentation.

This only works with the new feature resolver. I don't think I understand the dependency resolver well enough to implement it there. It would require teaching it to defer activating a feature, but due to the backtracking nature, I don't really know how to accomplish that. I don't think it matters, the main drawback is that the dependency resolver will be slightly more constrained, but in practice I doubt it will ever matter.

Closes #3494

**Question**
* An alternate syntax I considered was `dep_name?feat_name` (without the slash), what do people think?  For some reason the `?/` seems kinda awkward to me.
2020-11-04 22:20:36 +00:00
Eric Huss
9ffcf69093 Implement weak dependency features. 2020-11-04 14:19:27 -08:00
Eric Huss
28af36face Change for_host argument order for functions.
This consistently puts for_host next to PackageId, since the pair
PackageId/for_host is used everywhere together. Somehow it seems better
to me to consistently keep them close together.
2020-11-03 07:54:44 -08:00
bors
862df61799 Auto merge of #8823 - ehuss:minimal-download, r=alexcrichton
Avoid some extra downloads with new feature resolver.

There are some edge cases with the new feature resolver where it can erroneously trigger a download of a package that is not needed. This is due to the call `is_proc_macro` which has to downloaded the manifest to check if it is a proc-macro. The main change here is to defer calling `is_proc_macro` until after dependencies have been filtered. It also avoids calling `is_proc_macro` if the new feature resolver is enabled, but `decouple_host_deps` and `ignore_inactive_targets` are disabled (such as with `-Z weak-dep-features`), in which case it doesn't matter if it is a proc-macro or not.

Fixes #8776
2020-11-03 15:05:18 +00:00
bors
eaab752637 Auto merge of #8828 - awamwang:patch-1, r=ehuss
fix: remove install command `$`, for copying friendly
2020-11-03 14:19:16 +00:00
Awam M Wang
b122ee7b2c
fix: remove install command $, for copying friendly 2020-11-03 20:34:16 +08:00
bors
0cd5ab7ac6 Auto merge of #8826 - Aaron1011:anyhow-bump, r=alexcrichton
Bump `anyhow` dependency to `1.0.34` in `crates-io` crate

This will keep `crates-io` compiling if https://github.com/rust-lang/rust/issues/33953
is fixed. See https://github.com/dtolnay/anyhow/pull/120
2020-11-02 23:52:08 +00:00
Aaron Hill
939b5ff766
Bump anyhow dependency to 1.0.34 in crates-io crate
This will keep `crates-io` compiling if https://github.com/rust-lang/rust/issues/33953
is fixed. See https://github.com/dtolnay/anyhow/pull/120
2020-11-02 18:45:18 -05:00
bors
c46c06a161 Auto merge of #8824 - ehuss:normalize-source-master, r=alexcrichton
Normalize SourceID in `cargo metadata`.

The SourceID in `cargo metadata` can have different values, but they can be equivalent in Cargo. This results in different serialized forms, which prevents comparing the ID strings. In this particular case, `SourceKind::Git(GitReference::Branch("master"))` is equivalent to `SourceKind::Git(GitReference::DefaultBranch)`, but they serialize differently.

The reason these end up differently is because the `SourceId` for a `Package` is created from the `Dependency` declaration. But the `SourceId` in `Cargo.lock` comes from the deserialized file. If you have an explicit `branch = "master"` in the dependency, then versions prior to 1.47 would *not* include `?branch=master` in `Cargo.lock`. However, since 1.47, internally Cargo will use `GitReference::Branch("master")`.

Conversely, if you have a new `Cargo.lock` (with `?branch=master`), and then *remove* the explicit `branch="master"` from `Cargo.toml`, you'll end up with another mismatch in `cargo metadata`.

The solution here is to use the variant from the `Package` when serializing the resolver in `cargo metadata`. I chose this since the `Package` variant is displayed on other JSON messages (like artifact messages), and I think this is the only place that the resolver variants are exposed (other than `Cargo.lock` itself).

I'm not convinced that this was entirely intended, since there is [code to avoid this](6a38927551/src/cargo/core/resolver/encode.rs (L688-L695)), and at the time #8522 landed, I did not realize this would change the V2 lock format. However, it's probably too late to try to reverse that, and I don't think there are any other problems other than this `cargo metadata` inconsistency.

Fixes #8756
2020-11-02 14:55:51 +00:00
Eric Huss
d88ed1cb6c Normalize SourceID in cargo metadata. 2020-11-01 10:48:21 -08:00
Eric Huss
3d5a908393 Avoid some extra downloads with new feature resolver. 2020-10-31 16:49:22 -07:00
bors
03137edb0d Auto merge of #8822 - skrap:master, r=ehuss
vendor: correct the path to cargo config

When running `cargo vendor`, users are prompted to add the configuration to their cargo config.  Unfortunately, the path named is not correct, as it's lacking the correct suffix.
2020-10-30 15:29:57 +00:00
Jonah Petri
936acbc496
vendor: correct the path to cargo config
When running `cargo vendor`, users are prompted to add the configuration to their cargo config.  Unfortunately, the path named is not correct, as it's lacking the correct suffix.
2020-10-29 21:01:33 -04:00
bors
7197c66b36 Auto merge of #8819 - EmbarkStudios:target-root-path, r=ehuss
Make host_root return host.root(), not host.dest()

Also create host_dest function to let other callsites retain their old functionality. Fixes #8817, verified it works on the original problem reported in the `rust-gpu` repo.

I did two things here:

1) Rename `host_root` (which returns `self.host.dest()`) to be `host_dest`. This has three callsites. I did this to make it more clear that it returns dest, not root.
2) For the callsite that's relevant in #8817, I created a "new" `host_root` function (that returns `self.host.root()`). This means that the callsite that this PR is actually fixing doesn't show up in this diff :/ - but I thought it was more clear this way.

(Also copied the example path docs over from `layout.rs` to hopefully avoid this mistake again in the future)

I tried to look into if the other two callsites should actually be calling `host.root()` instead of `dest`, because I imagine the same mistake could have been made again, but it quickly grew out of my understanding (this is my first time in the cargo codebase). Feel free to let me know if they should also call `host.root()` too, and I can update them.

Thanks! (oh gosh I have no idea what I'm doing, I hope this is right)

r? `@alexcrichton`
2020-10-29 02:30:19 +00:00
khyperia
628f701dd9 Fix test path on windows 2020-10-28 20:45:50 +01:00
khyperia
29b0817b87 Add test for dep within target having right path 2020-10-28 20:22:41 +01:00
khyperia
6ca27ffc85 Make host_root return host.root(), not host.dest()
Also create host_dest function to let other callsites retain their old
functionality
2020-10-28 18:10:34 +01:00
bors
becb4c282b Auto merge of #8808 - weihanglo:fix/8591, r=ehuss
List available packages if providing `--package` with an empty value

May resolves #8591

## How

First we need to take the responsibility of check command line arguments from claps. I've examine all 10 build commands and all of them call [`ArgMatchesExt::compile_options`](2f115a76e5/src/cargo/util/command_prelude.rs (L389-L395)) directly or indirectly. And `compile_options` [calls `check_optional_opts`](2f115a76e5/src/cargo/util/command_prelude.rs (L499-L501)) to check if target selection options given an empty value. So we can do the same logic there.

I've also add a error message for an edge case though that one would never trigger at this moment.
2020-10-28 16:41:55 +00:00
bors
358ee548c7 Auto merge of #8814 - ehuss:warn-feature-syntax, r=alexcrichton
Add a future-compatibility warning on allowed feature name characters.

This adds a restriction on the valid syntax of a feature name. An warning is issued if a feature does not match the new validation, with the intent that it will be an error in the future.

The new restriction is:

* The first character must be a [Unicode XID start character](https://unicode.org/reports/tr31/) (most letters), a digit, or `_`.
* Subsequent characters must be a [Unicode XID continue character](https://unicode.org/reports/tr31/) (a digit, `_`, or most letters), `-`, or `+`.

The changes around passing in `config` to `Summary` can mostly be reverted when this is changed to an error.

I'm a little concerned that we don't have a mechanism to silence the warning. Should we add one?
2020-10-28 04:12:37 +00:00
Weihang Lo
4b9c503dfb
fix: remove unnecessary arg value existence check 2020-10-28 09:40:09 +08:00
Eric Huss
b731190daa Add a future-compatibility warning on allowed feature name characters. 2020-10-27 14:23:35 -07:00
bors
963bfe4dd9 Auto merge of #8799 - ehuss:new-namespaced, r=alexcrichton
New namespaced features implementation.

This is a new implementation for namespaced features (#5565). See the `unstable.md` docs for a description of the new behavior. This is intended to fix several issues with the existing design, and to make it backwards compatible so that it does not require an opt-in flag.

This also includes tangentially-related changes to the new feature resolver. The changes are:

* `crate_name/feat_name` syntax will now always enable the feature `crate_name`, even if it is an inactive optional dependency (such as a dependency for another platform). The intent here is to have a certain amount of consistency whereby "features" are always activated, but individual crates will still not be activated.
* `--all-features` will now enable features for inactive optional dependencies. This is more consistent with `--features foo` enabling the `foo` feature, even when the `foo` dep is not activated.

I'm still very conflicted on how that should work, but I think it is better from a simplicity/consistency perspective. I still think it may be confusing if someone has a `cfg(some_dep)` in their code, and `some_dep` isn't built, it will error. The intent is that `cfg(accessible(some_dep))` will be the preferred method in the future, or using platform `cfg` expression like `cfg(windows)` to match whatever is in Cargo.toml.

Closes #8044
Closes #8046
Closes #8047
Closes #8316

## Questions
- For various reasons, I changed the way dependency conflict errors are collected. One slightly negative consequence is that it will raise an error for the first problem it detects (like a "missing feature"). Previously it would collect a list of all missing features and display all of them in the error message. Let me know if I should retain the old behavior. I think it will make the code more complicated and brittle, but it shouldn't be too hard (essentially `Requirements` will need to collect a list of errors, and then `resolve_features` would need to check if the list is non-empty, and then aggregate the errors).

- Should `cargo metadata` show the implicit features in the "features" table? Currently it does not, and I think that is probably best (it mirrors what is in `Cargo.toml`), but I could potentially see an argument to show how cargo sees the implicit features.
2020-10-27 19:58:34 +00:00
Weihang Lo
b9554f37ab
rustfmt 2020-10-28 02:57:22 +08:00
Weihang Lo
9d9c321c27
test: check cargo uninstall package opt with empty value 2020-10-28 02:46:20 +08:00
Weihang Lo
cc6b43753b
feat: check cargo uninstall package opt with empty value 2020-10-28 02:46:20 +08:00
Weihang Lo
c347745613
test: list availables for clean,tree,update 2020-10-28 02:46:20 +08:00