Allow rust files to be used linkedProjects

This commit is contained in:
Lukas Wirth 2024-04-21 14:40:10 +02:00
parent 55d9a533b3
commit a2ed6837bc
21 changed files with 203 additions and 180 deletions

View file

@ -24,7 +24,7 @@ use toolchain::Tool;
use crate::{
cfg::CfgFlag, utf8_stdout, CargoConfig, CargoFeatures, CargoWorkspace, InvocationLocation,
InvocationStrategy, Package, Sysroot, TargetKind,
InvocationStrategy, ManifestPath, Package, Sysroot, TargetKind,
};
/// Output of the build script and proc-macro building steps for a workspace.
@ -63,7 +63,7 @@ impl WorkspaceBuildScripts {
fn build_command(
config: &CargoConfig,
allowed_features: &FxHashSet<String>,
workspace_root: &AbsPathBuf,
manifest_path: &ManifestPath,
sysroot: Option<&Sysroot>,
) -> io::Result<Command> {
let mut cmd = match config.run_build_script_command.as_deref() {
@ -79,7 +79,7 @@ impl WorkspaceBuildScripts {
cmd.args(&config.extra_args);
cmd.arg("--manifest-path");
cmd.arg(workspace_root.join("Cargo.toml"));
cmd.arg(manifest_path.as_ref());
if let Some(target_dir) = &config.target_dir {
cmd.arg("--target-dir").arg(target_dir);
@ -116,6 +116,10 @@ impl WorkspaceBuildScripts {
}
}
if manifest_path.extension().map_or(false, |ext| ext == "rs") {
cmd.arg("-Zscript");
}
cmd
}
};
@ -152,37 +156,12 @@ impl WorkspaceBuildScripts {
.as_ref();
let allowed_features = workspace.workspace_features();
match Self::run_per_ws(
Self::build_command(
config,
&allowed_features,
&workspace.workspace_root().to_path_buf(),
sysroot,
)?,
workspace,
current_dir,
progress,
) {
Ok(WorkspaceBuildScripts { error: Some(error), .. })
if toolchain.as_ref().map_or(false, |it| *it >= RUST_1_75) =>
{
// building build scripts failed, attempt to build with --keep-going so
// that we potentially get more build data
let mut cmd = Self::build_command(
config,
&allowed_features,
&workspace.workspace_root().to_path_buf(),
sysroot,
)?;
cmd.args(["--keep-going"]);
let mut res = Self::run_per_ws(cmd, workspace, current_dir, progress)?;
res.error = Some(error);
Ok(res)
}
res => res,
let mut cmd =
Self::build_command(config, &allowed_features, workspace.manifest_path(), sysroot)?;
if toolchain.as_ref().map_or(false, |it| *it >= RUST_1_75) {
cmd.args(["--keep-going"]);
}
Self::run_per_ws(cmd, workspace, current_dir, progress)
}
/// Runs the build scripts by invoking the configured command *once*.
@ -204,7 +183,13 @@ impl WorkspaceBuildScripts {
))
}
};
let cmd = Self::build_command(config, &Default::default(), workspace_root, None)?;
let cmd = Self::build_command(
config,
&Default::default(),
// This is not gonna be used anyways, so just construct a dummy here
&ManifestPath::try_from(workspace_root.clone()).unwrap(),
None,
)?;
// NB: Cargo.toml could have been modified between `cargo metadata` and
// `cargo check`. We shouldn't assume that package ids we see here are
// exactly those from `config`.