Skip to content

Commit

Permalink
allow rustc to use artifact dep environment variables, but…
Browse files Browse the repository at this point in the history
…it needs some adjustments to actually setup the unit dependency graph
with artifacts as well.
Right now it will only setup dependencies for artifacts that are libs,
but not the artifacts themselves, completely ignoring them when they
are not libs.
  • Loading branch information
Byron committed Feb 18, 2022
1 parent d288fa9 commit 74a0a80
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
14 changes: 12 additions & 2 deletions src/cargo/core/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ fn prepare_rustc(
base.inherit_jobserver(&cx.jobserver);
}
build_base_args(cx, &mut base, unit, crate_types)?;
build_deps_args(&mut base, cx, unit)?;
build_deps_args(&mut base, cx, unit, ProcessKind::Rustc)?;
Ok(base)
}

Expand Down Expand Up @@ -698,7 +698,7 @@ fn rustdoc(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Work> {
}
}

build_deps_args(&mut rustdoc, cx, unit)?;
build_deps_args(&mut rustdoc, cx, unit, ProcessKind::Rustdoc)?;
rustdoc::add_root_urls(cx, unit, &mut rustdoc)?;

rustdoc.args(bcx.rustdocflags_args(unit));
Expand Down Expand Up @@ -1087,6 +1087,7 @@ fn build_deps_args(
cmd: &mut ProcessBuilder,
cx: &mut Context<'_, '_>,
unit: &Unit,
kind: ProcessKind,
) -> CargoResult<()> {
let bcx = cx.bcx;
cmd.arg("-L").arg(&{
Expand All @@ -1107,6 +1108,10 @@ fn build_deps_args(

let deps = cx.unit_deps(unit);

if let ProcessKind::Rustc = kind {
artifact::set_env(cx, deps, cmd)?;
}

// If there is not one linkable target but should, rustc fails later
// on if there is an `extern crate` for it. This may turn into a hard
// error in the future (see PR #4797).
Expand Down Expand Up @@ -1551,3 +1556,8 @@ fn replay_output_cache(
Ok(())
})
}

enum ProcessKind {
Rustc,
Rustdoc,
}
2 changes: 1 addition & 1 deletion src/cargo/core/compiler/unit_dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ fn match_artifacts_kind_with_targets<'a>(
targets: &'a [Target],
) -> CargoResult<HashSet<&'a Target>> {
let mut out = HashSet::new();
let artifact_requirements = artifact_dep.artifact().expect("artifact preset");
let artifact_requirements = artifact_dep.artifact().expect("artifact present");
for artifact_kind in artifact_requirements.kinds() {
let start = out.len();
match artifact_kind {
Expand Down
6 changes: 6 additions & 0 deletions tests/testsuite/artifact_dep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@ fn build_script_with_selected_dashed_bin_artifact_and_lib_true() {

// TODO(ST): impl this, and add static and cdylib artifacts, too.
#[cargo_test]
#[ignore]
fn lib_with_selected_dashed_bin_artifact_and_lib_true() {
let p = project()
.file(
Expand Down Expand Up @@ -554,6 +555,11 @@ fn allow_artifact_and_no_artifact_dep_to_same_package_within_different_dep_categ
#[ignore]
fn disallow_using_example_binaries_as_artifacts() {}

// I think compiles it, so 'env!()' must work and be set, along with built artifacts.
#[cargo_test]
#[ignore]
fn rustdoc_works_on_libs_with_artifacts() {}

#[cargo_test]
#[ignore]
fn disallow_dep_renames_with_multiple_versions() {
Expand Down

0 comments on commit 74a0a80

Please sign in to comment.