Add a make_run_crates function and use it Rustc and Std

This fixes the panic from the previous commit.
This commit is contained in:
jyn 2023-05-25 13:37:24 -05:00
parent 564e3adfdf
commit 20372f1817
2 changed files with 17 additions and 10 deletions

View file

@ -2,7 +2,9 @@
use crate::builder::{crate_description, Builder, Kind, RunConfig, ShouldRun, Step};
use crate::cache::Interned;
use crate::compile::{add_to_sysroot, run_cargo, rustc_cargo, rustc_cargo_env, std_cargo};
use crate::compile::{
add_to_sysroot, make_run_crates, run_cargo, rustc_cargo, rustc_cargo_env, std_cargo,
};
use crate::config::TargetSelection;
use crate::tool::{prepare_tool_cargo, SourceType};
use crate::INTERNER;
@ -88,7 +90,7 @@ impl Step for Std {
}
fn make_run(run: RunConfig<'_>) {
let crates = run.cargo_crates_in_set();
let crates = make_run_crates(&run, "library");
run.builder.ensure(Std { target: run.target, crates });
}
@ -218,7 +220,7 @@ impl Step for Rustc {
}
fn make_run(run: RunConfig<'_>) {
let crates = run.cargo_crates_in_set();
let crates = make_run_crates(&run, "compiler");
run.builder.ensure(Rustc { target: run.target, crates });
}

View file

@ -48,6 +48,17 @@ impl Std {
}
}
/// Given an `alias` selected by the `Step` and the paths passed on the command line,
/// return a list of the crates that should be built.
///
/// Normally, people will pass *just* `library` if they pass it.
/// But it's possible (although strange) to pass something like `library std core`.
/// Build all crates anyway, as if they hadn't passed the other args.
pub(crate) fn make_run_crates(run: &RunConfig<'_>, alias: &str) -> Interned<Vec<String>> {
let has_alias = run.paths.iter().any(|set| set.assert_single_path().path.ends_with(alias));
if has_alias { Default::default() } else { run.cargo_crates_in_set() }
}
impl Step for Std {
type Output = ();
const DEFAULT: bool = true;
@ -62,16 +73,10 @@ impl Step for Std {
}
fn make_run(run: RunConfig<'_>) {
// Normally, people will pass *just* library if they pass it.
// But it's possible (although strange) to pass something like `library std core`.
// Build all crates anyway, as if they hadn't passed the other args.
let has_library =
run.paths.iter().any(|set| set.assert_single_path().path.ends_with("library"));
let crates = if has_library { Default::default() } else { run.cargo_crates_in_set() };
run.builder.ensure(Std {
compiler: run.builder.compiler(run.builder.top_stage, run.build_triple()),
target: run.target,
crates,
crates: make_run_crates(&run, "library"),
});
}