2008 Commits

Author SHA1 Message Date
Eric Huss
bb7ec2fcee Fix hang on broken stderr. 2021-02-23 18:15:44 -08:00
bors
8eb0e9a855 Auto merge of #9184 - ehuss:fix-next-edition, r=alexcrichton
Updates to edition handling.

This introduces some updates for edition handling (split into commits for review).  In short:

* `cargo-features = ["edition2021"]` can be used to opt-in to 2021 support without needing to pass around `-Z unstable-options`. I tried to emphasize in the docs that this is only for testing and experimentation.
* Make `"2"` the default resolver for 2021 edition.
* Make `cargo fix --edition` mean the "next" edition from the present one, and support 2021. Also, if already at the latest edition, generate a warning instead an error.
* I decided to allow `cargo fix --edition` from 2018 to 2021 on the nightly channel without an explicit opt-in. It's tricky to implement with an opt-in (see comment in diff).

Partial for #9048.
Fixes #9047.
2021-02-23 21:35:42 +00:00
bors
4ae4aadcb8 Auto merge of #9002 - volks73:feature-rustc-cfg-argument, r=alexcrichton
Add --cfg and --rustc-cfg flags to output compiler configuration

This PR is my attempt to address #8923.

I have added the `--cfg` flag to the `cargo rustc` subcommand and the `--rustc-cfg` flag to the `cargo build`, `cargo check`, `cargo test`, and `cargo bench` subcommands, respectively. Both versions of the flag, `--cfg` and `--rustc-cfg`, do the same thing, but I thought it looked weird for the `cargo rustc` subcommand to be `cargo rustc --rustc-cfg`. The following example invocations are possible, once stabilized:

- `cargo rustc --cfg`
- `cargo build --rustc-cfg`
- `cargo check --rustc-cfg`
- `cargo test --rustc-cfg`
- `cargo bench --rustc-cfg`

In each case, compilation is aborted and only compiler configuration is emitted. All of the context creation and configuration is still executed, but execution of the compilation job is aborted. Similar to the `--unit-graph` implementation, the `--cfg/--rustc-cfg` flag is hidden, marked as a "unstable", and requires the `-Z unstable-options` flag at the moment. A complete example invocation with this PR would be:

```bash
$ cargo +nightly rustc -Z unstable-options --cfg
```

I am open to alternatives for the flag name. I have thought of `--compiler-cfg`, `--compile-cfg`, and `--target-cfg`, but I went with `--rustc-cfg` because it is the Rust compiler (rustc) configuration (cfg). The `--target-cfg` could be confusing because there are Cargo targets and Compiler targets. A lone `--cfg` for the build, check, test, and bench subcommands would also be ambiguous and configuration that is being displayed.

Originally, I was only going to add the `--cfg` flag to the `cargo rustc` subcommand, but build, check, test, and bench all have the `--unit-graph` flag, and I used that flag's implementation and existence as a template for this implementation. I am not opposed to having just the `--cfg` flag for the `cargo rustc` subcommand as originally proposed in #8923.

I discovered during my initial investigation to implement the feature and familiarization with the Cargo codebase, that as part of the build context creation and compilation process, Cargo internally calls the `rustc --print cfg` command for all targets and stores the output in the `RustcTargetData` type. It does this for the host and any explicitly defined targets for cross-compilation. Compilation features, such as `+crt-static`, added to the compilation process through Cargo environment variables or TOML configuration directives are added to the internal `rustc --print cfg` command call. So, the `--cfg/--rustc-cfg` just emits the contents of the `RustcTagetData` type as JSON. There is no need to call the `rustc --print cfg` command again. The implementation then becomes nearly identical to the `--unit-graph` implementation.

The output is only in JSON, similar to the `--unit-graph` feature, instead of the key-value and name style of the `rustc --print cfg` output because it easily resolves issues related to multi-targets, explicit target (`--target <TRIPLE>`) versus host configurations, and cross compilation. Subcommands and other projects can parse the JSON to recreate the key-value and name style if desired based on a specific target or the host. Here is an example of the JSON output (formatted for humans, the actual output is condensed), which is also available as a comment in the `cargo::core::compiler::rustc_cfg` module:

```javascript
{
     "version": 1,
     "host": {
         "names": ["windows", "debug_assertions"],
         "arch":"x86_64",
         "endian":"little",
         "env":"msvc",
         "family":"windows",
         "features":["fxsr","sse","sse2"],
         "os":"windows",
         "pointer_width":"64",
         "vendor":"pc"
     },
     "targets": {
         "x86_64-unknown-linux-gnu": {
             "names": ["debug_assertions", "unix"],
             "arch":"x86_64",
             "endian":"little",
             "env":"gnu",
             "family":"unix",
             "features": ["fxsr","sse","sse2"],
             "os":"linux",
             "pointer_width":"64",
             "vendor":"unknown"
         },
         "i686-pc-windows-msvc": {
             "names": ["windows", "debug_assertions"],
             "arch":"x86",
             "endian":"little",
             "env":"msvc",
             "family":"windows",
             "features":["fxsr","sse","sse2"],
             "os":"windows",
             "pointer_width":"32",
             "vendor":"pc"
         }
     }
 }
```

I decided to remove the "target_" prefix from the relevant configurations to reduce "noise" in the output. Again, I am open to alternatives or suggestions on the JSON format.
2021-02-23 17:20:26 +00:00
bors
6243e8edcb Auto merge of #9105 - Swatinem:rustdoc-run-cwd, r=alexcrichton
Run rustdoc doctests relative to the workspace

By doing so, rustdoc will also emit workspace-relative filenames for the doctests.

This was first landed in #8954 but later backed out in #8996 because it changed the CWD of rustdoc test invocations.

The second try relies on the new `--test-run-directory` rustdoc option which was added in https://github.com/rust-lang/rust/pull/81264 to explicitly control the rustdoc test cwd.

fixes #8993
2021-02-23 16:39:45 +00:00
bors
4742e82957 Auto merge of #9175 - wickerwaka:env-section, r=alexcrichton
Add support for [env] section in .cargo/config.toml

This adds support for an `[env]` section in the config.toml files. Environment variables set in this section will be applied to the environment of any processes executed by cargo.

This is implemented to follow the recommendations in https://github.com/rust-lang/cargo/pull/8839#issuecomment-725678657

Variables have optional `force` and `relative` flags. `force` means the variable can override an existing environment variable. `relative` means the variable represents a path relative to the location of the directory that contains the `.cargo/` directory that contains the `config.toml` file. A relative variable will have an absolute path prepended to it before setting it in the environment.

```
[env]
FOOBAR = "Apple"
PATH_TO_SOME_TOOL = { value = "bin/tool", relative = true }
USERNAME = { value = "test_user", force = true }
```

Fixes #4121
2021-02-23 15:22:59 +00:00
Arpad Borsos
b4c4028f76
Run rustdoc doctests relative to the workspace
By doing so, rustdoc will also emit workspace-relative filenames for the doctests.

This was first landed in #8954 but later backed out in #8996 because it changed the CWD of rustdoc test invocations.

The second try relies on the new `--test-run-directory` rustdoc option which was added in https://github.com/rust-lang/rust/pull/81264 to explicitly control the rustdoc test cwd.

fixes #8993
2021-02-22 20:33:31 +01:00
bors
7442c14be8 Auto merge of #9161 - ehuss:index-v-features2, r=alexcrichton
Add schema field and `features2` to the index.

This adds a `v` field to the index which indicates a format version for an index entry. If Cargo encounters a version newer than it understands, it will ignore those entries. This makes it safer to make changes to the index entries (such as adding new things), and not need to worry about how older cargos will react to it. In particular, this will make it safer to run `cargo update` on older versions if we ever decide to add new things to the index.

Currently this is not written anywhere, and is intended as a safety guard for the future. For now I will leave it undocumented until we actually decide to start using it.

This also moves the new syntax for namespaced features and weak dependency features into a new field ("features2") in the index. This is necessary to avoid breaking Cargo versions older than 1.19, which fail to parse the index even if there is a Cargo.lock file.

It is intended that only crates.io will bother with creating this field. Other registries don't need to bother, since they generally don't support Cargo older than 1.19.

I'm uncertain exactly when we should try to update crates.io to start accepting this, as that is a somewhat permanent decision.
2021-02-22 15:48:02 +00:00
Chris Field
2a5355f9b3 Fix usage of assert methods
The `with_stdout_contains` was mis-used. Since some lines may or may not
appear for some compiler targets and environments (nightly, beta,
stable, etc.) the tests would fail because the output was not identical.
Instead of a using raw strings, each line with the arch, endian, env,
family, vendor, pointer_width, etc. that are known to always be
present (at least of the CI builds) are included. This should work for
the CI environments and my local environment.
2021-02-21 22:58:31 -05:00
Chris Field
9b02dd41e4 Fix tests for CI environment
The `panic="unwind"` appears in the output for the CI tests, but not in
my local tests. I need to investigate the origin of this configuration
but it causes the CI builds to fail.
2021-02-21 21:45:55 -05:00
Chris Field
70a423ebf8 Fix formatting 2021-02-21 20:00:28 -05:00
Chris Field
1f057303b8 Add test with cargo configuration file
A `.cargo/config.toml` file is used to add the "crt-static" target
feature and test printing the compiler target configuration contains the
`target_feature="crt-static"` line.
2021-02-21 19:58:19 -05:00
Chris Field
c7038b22ca Add test using RUSTFLAGS env var
The `RUSTFLAGS` environment variable is used to add the "crt-static"
target feature and test printing the target compiler configuration
contains the `target_feature="crt-static"` line.
2021-02-21 19:54:08 -05:00
Chris Field
8b80e52ca8 Add multitarget test
Using the multitarget feature to print the configuration of multiple
compiler target configurations, a test is created.
2021-02-21 19:50:21 -05:00
Chris Field
de340a2ef6 Add first test
Not sure how to handle running the test on different hosts, so the first
test is explicit about the compile target to print the configuration.
2021-02-21 19:35:33 -05:00
Martin Donlon
05acf73604 Change env section parsing
`untagged` enum variants are not recognised by serde if the variant contains a `Value<T>` type.
This change uses an transparent "inner" enum `Value<T>` member, which is handled correctly by serde.
2021-02-20 13:49:08 -08:00
Eric Huss
c303213748 cargo fix: Remove --prepare-for option.
This was deprecated, never officially part of the stable release.
2021-02-19 14:29:45 -08:00
Eric Huss
aa61976c5f Make edition transitions easier.
This attempts to centralize all the edition stuff in one place (the
`Edition` enum) so that adding a new edition or stabilizing one should
be relatively little work (and more importantly, we don't miss things).

Importantly, this changes `cargo new` to default to the latest stable.
It also changes the `cargo fix --edition-idiom` behavior to only apply
idioms for the *current* edition.
2021-02-19 14:29:44 -08:00
Eric Huss
0d4137f4f5 Include the index version in the index cache.
This is intended to help prevent the following scenario from happening:

1. Old cargo builds an index cache.
2. Old cargo finds an index entry it cannot parse, skipping it,
   and saving the cache without the entry.
3. New cargo loads the cache with the missing entry, and never sees
   the new entries that it understands.

This may result in more cache thrashing, but that seems better than
having new cargos missing entries.
2021-02-19 10:51:38 -08:00
bors
37055199b2 Auto merge of #9185 - horacimacias:master, r=ehuss
Do not exit prematurely if anything failed installing.

https://github.com/rust-lang/cargo/issues/9180
2021-02-19 15:32:24 +00:00
Horaci Macias
dab646eee0 Do not exit prematurely if anything failed installing.
https://github.com/rust-lang/cargo/issues/9180
2021-02-19 09:53:46 +01:00
Eric Huss
28850225a1 Updates to cargo fix --edition.
* `--edition` always means "next" edition.
* `--edition` when on the most recent edition is not an error, just a warning.
* Support fix to 2021 edition.
2021-02-17 22:12:46 -08:00
Eric Huss
37f4ff9a9a Make "2" the default resolver in the 2021 edition. 2021-02-17 22:06:58 -08:00
Eric Huss
2ae72ff747 Add edition2021 cargo feature.
This is intended to help make it easier to test the 2021 edition.
2021-02-17 22:01:42 -08:00
Eric Huss
3f2f7e30ff Add a migrating message for cargo fix --edition.
This helps indicate which edition you are moving from and to.
2021-02-17 21:36:28 -08:00
Eric Huss
820537c706 Change Fixing to Fixed, and add a verbose "Fixing".
What was previously "Fixing" was a message for after the fixes had
been applied. I think it would be clearer if it said "Fixed",
to indicate that the fixes had actually finished.

The new "Fixing" is posted just before it starts. This is verbose-only
since it is a little noisy.
2021-02-17 20:41:38 -08:00
Alex Crichton
1e05dbb5e6 Propagate lto=off harder
This commit fixes an issue with LTO calculation for various units when
`lto=off` is specified in the profile. This ensures now that `lto=off`
is passed to all transitive dependencies as well to disable thin-local
LTO. As an added bonus this also passed `embed-bitcode=no` whenever
`lto=off` is specified since we know we won't be using bitcode anyway.

Closes #9171
2021-02-17 11:40:38 -08:00
Martin Donlon
7990ab53f5 Add -Z configurable-env to gate [env] usage
Added the `-Z configurable-env` option which controls whether the data from the [env] section is used. Updated the tests to pass the flag and to masquerade as the nightly cargo.
2021-02-15 20:21:22 -08:00
Martin Donlon
3aa99422ca Run cargo fmt --all
Fix formatting errors
2021-02-15 15:29:08 -08:00
Martin Donlon
95de3e9fea Add support for [env] section in .cargo/config.toml
This adds support for an `[env]` section in the config.toml files. Environment variables set in this section will be applied to the environment of any processes executed by cargo.

```
[env]
FOOBAR = "Apple"
PATH_TO_SOME_TOOL = { value = "bin/tool", relative = true }
USERNAME = { value = "test_user", force = true }
```
2021-02-15 15:17:00 -08:00
bors
af564b22ca Auto merge of #9169 - Liberatys:emit-warning-on-env-variable-case-mismatch, r=ehuss
Emit warning on env variable case mismatch

When running a command like `cargo --target TRIPPLE` cargo expects to find the environment variable CARGO_TARGET_[TRIPPLE]_* with uppercase and underscores. This check emits a warning if the checked environment variable has a mismatching case and/or contains dashes rather than underscores. The warning contains the given env variable as well as an explanation for the cause of the warning.

The check is skipped on windows as environment variables are treated as case insensitive on the platform.

Fixes #8285
2021-02-14 19:35:20 +00:00
Eric Huss
0564466f45 Combine target env tests. 2021-02-14 11:32:18 -08:00
Nick Flueckiger
4234077bc2 Re-add backticks 2021-02-14 13:15:35 +01:00
Nick Flueckiger
d3aed3585e Update wording and use if let 2021-02-14 13:00:20 +01:00
Nick Flueckiger
86c6e42741 Fix windows test case 2021-02-14 00:20:21 +01:00
Nick Flueckiger
c86310210c Update windows check 2021-02-13 23:20:43 +01:00
bors
8fa0827d27 Auto merge of #8640 - CPerezz:doc_versioning, r=ehuss
Implement Rustdoc versioning checks

Before compiling, we need to make sure that if there were any previous docs already compiled, they were compiled with the same Rustc version that we're currently using. Otherways we must remove the `doc/` folder and compile again.

This is important because as stated in #8461 the .js/.html&.css files that are generated by Rustc don't have any versioning. Therefore, we can fall in weird bugs and behaviours if we mix different compiler versions of these js/.html&.css files.

Closes #8461
2021-02-13 21:57:02 +00:00
Nick Flueckiger
6af31941f3 Adapt implementation with reviewer suggestions and requested changes 2021-02-13 21:17:18 +01:00
Nick Flueckiger
6ea8abc805 Correct target 2021-02-13 12:19:00 +01:00
Nick Flueckiger
dd4b95fb9f Lint 2021-02-13 12:14:24 +01:00
Nick Flueckiger
a7ae6352a3 Exclude test on windows 2021-02-13 11:59:38 +01:00
Nick Flueckiger
11c82a8af8 Implement uppercase env map for key case mismatch 2021-02-13 11:46:13 +01:00
Eric Huss
9cb8f41ec9 Prevent testsuite from loading config out of sandbox. 2021-02-10 17:39:38 -08:00
Eric Huss
be28b58b45 Add features2 to the index. 2021-02-10 11:15:19 -08:00
Eric Huss
196673bb1e Add a schema version to the index. 2021-02-10 10:58:07 -08:00
bors
ab64d1393b Auto merge of #9153 - calavera:strip_options, r=ehuss
Allow `true` and `false` as options for `strip` option

This follows the convention of `lto` and `debug` that allow `true` for
the highest level, and `false` for disabled.

Signed-off-by: David Calavera <david.calavera@gmail.com>
2021-02-10 00:19:10 +00:00
bors
0608fcd99d Allow true and false as options for strip option
This follows the convention of `lto` and `debug` that allow `true` for
the highest level, and `false` for disabled.

Signed-off-by: David Calavera <david.calavera@gmail.com>
2021-02-10 00:19:10 +00:00
bors
46bac2dc44 Auto merge of #9133 - alexcrichton:git-default-branch, r=ehuss
Change git dependencies to use `HEAD` by default

This commit follows through with work started in #8522 to change the
default behavior of `git` dependencies where if not branch/tag/etc is
listed then `HEAD` is used instead of the `master` branch. This involves
also changing the default lock file format, now including a `version`
marker at the top of the file notably as well as changing the encoding
of `branch=master` directives in `Cargo.toml`.

If we did all our work correctly then this will be a seamless change.
First released on stable in 1.47.0 (2020-10-08) Cargo has been emitting
warnings about situations which may break in the future. This means that
if you don't specify `branch = 'master'` but your HEAD branch isn't
`master`, you've been getting a warning. Similarly if your dependency
graph used both `branch = 'master'` as well as specifying nothing, you
were receiving warnings as well. These two situations are broken by this
commit, but it's hoped that by giving enough times with warnings we
don't actually break anyone in practice.
2021-02-09 23:42:27 +00:00
Alex Crichton
9f2ce1ffef Squash warnings on the nightly channel 2021-02-09 07:30:08 -08:00
Alex Crichton
1fefa5de26 Add back in deleted tests 2021-02-09 07:29:01 -08:00
bjorn3
f5a3d55983 Fix warnings of the new non_fmt_panic lint 2021-02-06 19:10:42 +01:00