-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #9992 - Byron:rfc-3028, r=ehuss
Implement "artifact dependencies" (RFC-3028) Tracking issue: #9096 #### Tasks * [x] -Z unstable option called `bindeps` * ✅ **(config)** allow parsing of newly introduced 'artifact' fields * [x] into `TomlManifest` * [x] into `Manifest` - [x] ~~abort~~ warn if artifacts are used on stable * ✅ **resolver** : assure artifact dependencies are part of the resolution process and unified into the dependency tree * 🔬**compiler**: make it understand 'artifact' dependencies and pass new environment variables to the crate being build * [x] `lib=false` should not be considered a rust library for the dependent, in unit and possibly resolve graph * [x] assure profile settings are applied correctly * [x] target overrides work * [x] `target = "target"` in build deps * [x] other targets on build deps * [x] other targets on non-build deps * [x] 'no-cross doc tests' seems like a constraint we should apply as well maybe * [x] more confidence with `resolver = "2"` * [x] assure artifact placement is correct (bin and various forms of lib) * ✅ **serialization**: rewriting manifests (i.e. for publishing) does not discard artifact information * [x] publishing keeps `artifact` and `lib` values * **Other cargo subcommands** * [x] `cargo metadata` * leave unchanged * [x] artifacts work with `cargo check` * [x] artifacts work with rustdoc, such that it doesn't document them unless `lib=true` * [x] `cargo tree` maybe? * [x] `cargo clean` should clean artifacts - even though it's more complex, ultimately it deletes the `target` directory. * [x] artifacts work with `cargo test` (and dev-dependencies) * [x] doctests * [x] try `reproducible` repository as well. * 🧪 **tests** for more subtle RFC constraints - [x] build scripts cannot access artifact environment variables at compile time, only at runtime) - [x] assure 'examples' which also support crate-type fields like [[lib]] won't become artifacts themselves. - [x] assure `--out-dir` does not leak artifacts - tested manually, it seemed to niche to add a test. - [x] try `target="foo"` in artifact and assure it sees a decent error message - [x] Assure RFC 3176 _doesn't_ work * 🧹cleanup and finalization - [x] assure no `TODO(ST)` markers are left in code - [x] assure no tests are ignored - [x] use `resolver = "1"` once to assert everything also works with the previous resolver, but leave it on "2". #### Implementation and review notes - artifacts and unstable options are only checked when transforming them from `TomlManifest` to `Manifest`, discarding artifact information if the unstable flag is not set. Nowhere else in code will the CLI options be checked again. - `If no binaries are specified, all the binaries in the package will be built and made available.` - this should only refer to `[[bin]]` targets, not examples for instance. - artifact binaries won't be uplifted, hence won't be present outside of their output directory - ❗️We don't know how [package links](https://github.com/rust-lang/cargo/blob/00e925f61fbd9f2d956046aea5af6b7636ab2931/src/cargo/core/compiler/unit_dependencies.rs#L380) will affect artifacts for build dependencies. Should probably be thought through. - ❗️The location of artifacts is only tested roughly to avoid having to deal with different output names on the four platforms that seem to matter (gnu, macos, windows msvc, windows gnu). - `cargo tree` doesn't handle artifacts specifically, and it might be interesting to make clear if an artifact is only an artifact, or both artifact and dependency. - Most error and warning messages can probably be more cargo-matic. #### Questions * Does `cargo` without the feature enabled have to complain about the "artifact" field in a dependency, like it does right now? It doesn't look like machinery for that exists in `do_read_manifest()`. - ✔️It warns now * Should parsing of artifact values, like "bin" be case sensitive? - ✔️ It's case sensitive now, which should help with serde roundtripping. #### Review Progress * [x] address Josh's review notes one by one * [x] introduce `IsArtifact` (see [this answer](#9992 (comment))) (76cd48a2d62d74e043a1a482199c5bb920f50311) * [x] prefer uplifting artifact deps that were written into the `deps` directory, but prefer to do that in [this PR instead](#9992) * [x] add extra-tests as described in Josh's comment: " features get unified between a Rust library and a binary, and one that confirms features don't get unified between a Rust library and a binary for a different target?" * [x] Make target-based artifact splitting work by porting parts of RFC-3176 * [x] test-support/cross-compile * [x] namespace separation * [x] re-create RFC-3176 what's not in RFC-3028, namely multidep support and all related tests * [x] Address Eh2406 's review comments * [x] Address Eric's comments * [x] Unstable features need to be documented in unstable.md. * [x] sort out [`target_data`](#9992 (comment)) * [x] figure out [cargo metadata](#9992 (comment)) * [x] See if target-data can work without an [index format update](#9992 (comment)). * [x] truncate comments at 80-90 lines and remove unused methods, remove -Z unstable-options, use `cfg!(target_env = "msvc")` * [x] add missing doc comments to newly added methods and funtions * [x] simplify method parameters and inline some functions * [x] add test and extend test to show additional issues * [x] assure current set of tests works consistently, also on windows Sponsored by [Profian](https://www.profian.com)
- Loading branch information
Showing
36 changed files
with
4,330 additions
and
411 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/// Generate artifact information from unit dependencies for configuring the compiler environment. | ||
use crate::core::compiler::unit_graph::UnitDep; | ||
use crate::core::compiler::{Context, CrateType, FileFlavor, Unit}; | ||
use crate::core::TargetKind; | ||
use crate::CargoResult; | ||
use std::collections::HashMap; | ||
use std::ffi::OsString; | ||
|
||
/// Return all environment variables for the given unit-dependencies | ||
/// if artifacts are present. | ||
pub fn get_env( | ||
cx: &Context<'_, '_>, | ||
dependencies: &[UnitDep], | ||
) -> CargoResult<HashMap<String, OsString>> { | ||
let mut env = HashMap::new(); | ||
for unit_dep in dependencies.iter().filter(|d| d.unit.artifact.is_true()) { | ||
for artifact_path in cx | ||
.outputs(&unit_dep.unit)? | ||
.iter() | ||
.filter_map(|f| (f.flavor == FileFlavor::Normal).then(|| &f.path)) | ||
{ | ||
let artifact_type_upper = unit_artifact_type_name_upper(&unit_dep.unit); | ||
let dep_name = unit_dep.dep_name.unwrap_or(unit_dep.unit.pkg.name()); | ||
let dep_name_upper = dep_name.to_uppercase().replace("-", "_"); | ||
|
||
let var = format!("CARGO_{}_DIR_{}", artifact_type_upper, dep_name_upper); | ||
let path = artifact_path.parent().expect("parent dir for artifacts"); | ||
env.insert(var, path.to_owned().into()); | ||
|
||
let var = format!( | ||
"CARGO_{}_FILE_{}_{}", | ||
artifact_type_upper, | ||
dep_name_upper, | ||
unit_dep.unit.target.name() | ||
); | ||
env.insert(var, artifact_path.to_owned().into()); | ||
|
||
if unit_dep.unit.target.name() == dep_name.as_str() { | ||
let var = format!("CARGO_{}_FILE_{}", artifact_type_upper, dep_name_upper,); | ||
env.insert(var, artifact_path.to_owned().into()); | ||
} | ||
} | ||
} | ||
Ok(env) | ||
} | ||
|
||
fn unit_artifact_type_name_upper(unit: &Unit) -> &'static str { | ||
match unit.target.kind() { | ||
TargetKind::Lib(kinds) => match kinds.as_slice() { | ||
&[CrateType::Cdylib] => "CDYLIB", | ||
&[CrateType::Staticlib] => "STATICLIB", | ||
invalid => unreachable!("BUG: artifacts cannot be of type {:?}", invalid), | ||
}, | ||
TargetKind::Bin => "BIN", | ||
invalid => unreachable!("BUG: artifacts cannot be of type {:?}", invalid), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.