From 74a0a80034f798d6ebaf45ac1bdf9d0160db7e6a Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Wed, 3 Nov 2021 18:27:56 +0800 Subject: [PATCH] =?UTF-8?q?allow=20rustc=20to=20use=20artifact=20dep=20env?= =?UTF-8?q?ironment=20variables,=20but=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …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. --- src/cargo/core/compiler/mod.rs | 14 ++++++++++++-- src/cargo/core/compiler/unit_dependencies.rs | 2 +- tests/testsuite/artifact_dep.rs | 6 ++++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/cargo/core/compiler/mod.rs b/src/cargo/core/compiler/mod.rs index 31883e5bb34..53c0cfc8998 100644 --- a/src/cargo/core/compiler/mod.rs +++ b/src/cargo/core/compiler/mod.rs @@ -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) } @@ -698,7 +698,7 @@ fn rustdoc(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult { } } - 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)); @@ -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(&{ @@ -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). @@ -1551,3 +1556,8 @@ fn replay_output_cache( Ok(()) }) } + +enum ProcessKind { + Rustc, + Rustdoc, +} diff --git a/src/cargo/core/compiler/unit_dependencies.rs b/src/cargo/core/compiler/unit_dependencies.rs index 6e8f5191080..3bc52e2adc3 100644 --- a/src/cargo/core/compiler/unit_dependencies.rs +++ b/src/cargo/core/compiler/unit_dependencies.rs @@ -503,7 +503,7 @@ fn match_artifacts_kind_with_targets<'a>( targets: &'a [Target], ) -> CargoResult> { 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 { diff --git a/tests/testsuite/artifact_dep.rs b/tests/testsuite/artifact_dep.rs index 1f0271d243f..a61d1009a65 100644 --- a/tests/testsuite/artifact_dep.rs +++ b/tests/testsuite/artifact_dep.rs @@ -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( @@ -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() {