Commit Graph

95 Commits

Author SHA1 Message Date
Eric Huss 888100352a Move ProcessBuilder to cargo-util. 2021-03-20 15:19:03 -07:00
Eric Huss e58c544f37 Some minor code cleanup. 2021-02-28 19:03:06 -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
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
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
Eric Huss d8673d93d2 Fix env/cfg set for `cargo test` and `cargo run`. 2021-02-01 19:20:54 -08:00
Léo Gaspard 2f14f98fcc Small refactor, adding a list of all kinds to BuildContext
Involved in https://github.com/rust-lang/cargo/pull/9030
2021-01-05 02:35:20 +01:00
Jake Shadle a9a154f783 Fix bug with PathAndArg config values 2020-08-17 19:23:49 +02:00
Bryan Donlan d19ff18347 Expose built cdylib artifacts in the Compilation structure
This change makes it much easier to find these artifacts in a
platform-independent way when writing automation around the cargo API.
2020-06-26 17:23:34 +00:00
Robin Moussu 3b39e3a73d Adding environment variable CARGO_PKG_LICENSE_FILE 2020-06-20 12:01:35 +02:00
bors c8ae267490 Auto merge of #8325 - kerkmann:license-field-as-environment-variable, r=joshtriplett
Adding environment variable CARGO_PKG_LICENSE

Fixes #8024
2020-06-20 03:35:31 +00:00
bors 089cbb80b7 Auto merge of #8359 - ehuss:doctest-xcompile-linker, r=alexcrichton
Support linker with -Zdoctest-xcompile.

This adds support for `-Clinker` with `-Zdoctest-xcompile`.

I'm not entirely sure how `-Zdoctest-xcompile` was supposed to work without setting the linker. I tested this with std on arm-unknown-linux-gnueabihf with qemu. It seems to work (although it was quite slow).

Closes #7529.
2020-06-15 14:38:34 +00:00
Eric Huss b4476d74f3 Support linker with -Zdoctest-xcompile. 2020-06-13 21:19:22 -07:00
Eric Huss 1bf67a0402 Fix doctests not running with --target=HOST. 2020-06-13 20:56:29 -07:00
Daniél Kerkmann 1e800abcab
Merge branch 'master' into license-field-as-environment-variable 2020-06-08 21:24:02 +02:00
Daniél Kerkmann 4a4f5a20fa
Adding environment variable CARGO_PKG_LICENSE
Fixes #8024
2020-06-04 02:51:16 +02:00
ReggaeMuffin 50a537bf93
Add CARGO_BIN_NAME and CARGO_CRATE_NAME to rustc/rustdoc env
CARGO_BIN_NAME is added for binary compilation units, CARGO_CRATE_NAME is added for binary and library units. 

The `crate_env_vars` test was updated to test for this. The test is currently only checking behavior for the binary compile unit.
2020-05-23 16:23:49 +01:00
Eric Huss 7a06be149c Add CrateType to replace LibKind. 2020-05-05 14:32:52 -07:00
Alex Crichton 3fd28143de Support multiple `--target` flags on the CLI
This commit refactors the internals of Cargo to no longer have a
singular `--target` flag (and singular `requested_target` kind throught)
but to instead have a list. The semantics of multiple `--target` flags
is to build the selected targets for each of the input `--target` flag
inputs.

For now this is gated behind `-Zmultitarget` as an unstable features,
since I'm not entirely sure this is the interface we want. In general
it'd be great if we had a way to simply specify `Unit` structures of
what to build on the CLI, but we're in general very far away from that,
so I figured that this is probably sufficient at least for testing for
now.

cc #8156
2020-04-28 15:16:47 -07:00
Alex Crichton 45d49579ae Make `Unit` an owned value 2020-04-19 10:36:26 -07:00
Alex Crichton fbd34a6997 Hide `Rc<Package>` under `Package` 2020-04-19 10:36:26 -07:00
Eric Huss e0bd9e231d bcx reorg 2020-04-19 10:36:26 -07:00
Eric Huss 98b6f8160e Wrap Package/Target in Rc.
This is intended to make it easier to deal with Unit lifetimes.
2020-04-19 10:36:26 -07:00
Jane Lusby b0351e4d87 Close the front door for clippy but open the back 2020-03-12 19:27:48 -07:00
Eric Huss 949eccac3e Move rustc target collection out of bcx.
This allows querying it earlier, and independently of the rest of stuff in BuildContext.
2020-02-20 12:04:28 -08:00
Eric Huss 2296af27ae Fix BuildScriptOutput when a build script is run multiple times. 2020-02-02 13:26:22 -08:00
Johannes Brechtmann f917e169ab Fix wrong directories in host_libdir.
This fixes a regression from #7475 where the sysroot_target_libdir leaks into
the host libdir. This can cause problems when the dynamic linker does
not ignore the target libraries but tries to load them instead. This
happens for example when building on x86_64-musl for aarch64-musl.
2020-01-14 23:02:43 +01:00
Alex Crichton 3a18c89a55 Migrate from the `failure` crate to `anyhow`
The `anyhow` crate interoperates with the `std::error::Error` trait
rather than a custom `Fail` trait, and this is the general trend of
error handling in Rust as well.

Note that this is mostly mechanical (sed) and intended to get the test
suite passing. As usual there's still more idiomatic cleanup that can
happen, but that's left to later commits.
2020-01-07 16:50:09 -08:00
Eric Huss 381251aa1f Config refactoring. 2019-12-19 09:44:01 -08:00
David Tolnay 9aa65c556c Pass --edition after --crate-name
This PR swaps the order of the --edition and --crate-name args in the
rustc invocation.

    Before: rustc --edition=2018 --crate-name cargo ...
    After: rustc --crate-name cargo --edition=2018 ...

The crate name is a lot more relevant when looking at processes in top
for example, and should appear first.
2019-12-13 19:17:39 -08:00
Eric Huss 1c779ac5d4 Switch build-std to use --extern 2019-12-12 08:18:15 -08:00
Eric Huss 8e9c86c6f2 Remove --crate-type test for rustdoc now that it is stable. 2019-11-07 11:14:49 -08:00
Alex Crichton 61188d791a Fix wrong directories in PATH on Windows
This fixes an accidental regression from #7425 where `PATH` was being
augmented on Windows with the wrong search path for target/host
libraries. This commit fixes the issue by simply always calculating the
host/target library paths for `TargetInfo`, and then we explicitly use
the same `TargetInfo` for filling out information in `Compilation`.

Closes #7475
2019-10-04 08:06:17 -07:00
Alex Crichton ef425b77e2 Refactor how compile targets are handled
Rename `Kind` to `CompileKind` to reflect that it's intended for
compilation. Additionally change the `Target` variant to have a newtype
`CompileTarget` instead of just being a raw string. This new
`CompileTarget` type has a fallible constructor and handles custom json
target files internally.

Two accessors are available for `CompileTarget`, one is `rustc_target()`
which goes straight to rustc and everything else uses `short_name()`
which is the raw target or file stem for json files. The `short_name` is
used everywhere in Cargo for all purposes like configuration, env vars,
target directory naming, etc.
2019-09-26 08:23:24 -07:00
Alex Crichton 593a02f2d7 Refactor `Kind` to carry target name in `Target`
This commit is an internal refactoring of Cargo's compilation backend to
eventually support compiling multiple target simultaneously. The
original motivation for this came up in discussion of #7297 and this has
long been something I've intended to update Cargo for. Nothing in the
backend currently exposes the ability to actually build multiple target
simultaneously, but this should have no function change with respect to
all current consumers. Eventually we'll need to refactor APIs of how you
enter the compilation backend to compile for multiple targets.
2019-09-26 08:23:05 -07:00
Eric Huss 581da42ea6 Don't add sysroot lib path to dylib path for build-std. 2019-09-24 13:50:34 -07:00
bors 7ab477866e Auto merge of #7375 - ehuss:extract-platform, r=alexcrichton
Extract Platform to a separate crate.

This moves the `Platform`, `Cfg`, `CfgExpr` types to a new crate named "cargo-platform".  The intent here is to give users of `cargo_metadata` a way of parsing and inspecting cargo's platform values.

Along the way, I rewrote the error handling to remove `failure`, and to slightly improve the output.

I'm having doubts whether or not this is a good idea.  As you can see from the `examples/matches.rs` example, it is nontrivial to use this (which also misses cargo's config values and environment variables).  I don't know if anyone will actually use this.  If this doesn't seem to have value, I would suggest closing it.

I've also included a sample script, `publish.py`, for publishing cargo itself.  I suspect it will need tweaking, but I figure it would be a start and open for feedback.
2019-09-20 18:05:09 +00:00
Dario Gonzalez 8c93de6a82 Added ability to crosscompile doctests 2019-09-18 11:43:24 -07:00
Eric Huss 57c96c194a Extract Platform to a separate crate. 2019-09-17 14:55:22 -07:00
Aaron Hill b68e854285
Compute 'rustdoc --crate-type' support when Compilation is created 2019-09-16 14:10:07 -04:00
Aaron Hill 60afaa7733
Run 'cargo fmt' 2019-09-12 13:47:13 -04:00
Aaron Hill 5d302e5a72
Cache outout of 'rustdoc --crate-type proc-macro --help' 2019-09-11 18:09:54 -04:00
Aaron Hill 511050baef
Run 'cargo fmt' 2019-09-11 18:09:20 -04:00
Aaron Hill 8a0255f9ac
Only pass '--crate-type' if supported by rustdoc 2019-09-11 18:09:20 -04:00
Aaron Hill 752112ce78
Pass --crate-type to rustdoc
This supports the corresponding rustc PR. To enable rustdoc to properly
document macros, we mirror the '--crate-type' flag used by rustc.
Currently, all crate types other than 'proc-macro' are ignored by
rustdoc.
2019-09-11 18:09:19 -04:00
Eric Huss 1f14fa3172 Basic standard library support. 2019-09-03 13:53:59 -07:00
bors f0075c5a2a Auto merge of #7162 - yaahallo:clippyargs, r=ehuss
reimplement arg passthrough for clippy-driver

Prior to this change, the old cargo subcommand version of `cargo clippy`
had a feature to pass trailing args down to clippy-driver but when this
the subcommand was reimplemented inside of cargo this feature was left
out accidentally.

This change readds the feature to to capture all args after a trailing
-- and forward them down to clippy-driver via an env variable.
2019-08-09 22:40:43 +00:00
Eric Huss 16f8cc39c8 Layout docs and cleanup. 2019-08-08 12:33:51 -07:00