mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-08-04 18:58:41 +00:00
Do not append --compile-time-deps
to overwritten build script commands
This commit is contained in:
parent
6d465579f9
commit
f055cbce1a
3 changed files with 49 additions and 48 deletions
|
@ -109,13 +109,11 @@ fn main() {
|
|||
|
||||
let mut artifact_path = None;
|
||||
for message in Message::parse_stream(output.stdout.as_slice()) {
|
||||
if let Message::CompilerArtifact(artifact) = message.unwrap() {
|
||||
if artifact.target.kind.contains(&cargo_metadata::TargetKind::ProcMacro)
|
||||
&& (artifact.package_id.repr.starts_with(&repr)
|
||||
|| artifact.package_id.repr == pkgid)
|
||||
{
|
||||
artifact_path = Some(PathBuf::from(&artifact.filenames[0]));
|
||||
}
|
||||
if let Message::CompilerArtifact(artifact) = message.unwrap()
|
||||
&& artifact.target.kind.contains(&cargo_metadata::TargetKind::ProcMacro)
|
||||
&& (artifact.package_id.repr.starts_with(&repr) || artifact.package_id.repr == pkgid)
|
||||
{
|
||||
artifact_path = Some(PathBuf::from(&artifact.filenames[0]));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,9 +20,7 @@ use toolchain::Tool;
|
|||
|
||||
use crate::{
|
||||
CargoConfig, CargoFeatures, CargoWorkspace, InvocationStrategy, ManifestPath, Package, Sysroot,
|
||||
TargetKind,
|
||||
toolchain_info::{QueryConfig, version},
|
||||
utf8_stdout,
|
||||
TargetKind, utf8_stdout,
|
||||
};
|
||||
|
||||
/// Output of the build script and proc-macro building steps for a workspace.
|
||||
|
@ -64,6 +62,7 @@ impl WorkspaceBuildScripts {
|
|||
workspace: &CargoWorkspace,
|
||||
progress: &dyn Fn(String),
|
||||
sysroot: &Sysroot,
|
||||
toolchain: Option<&semver::Version>,
|
||||
) -> io::Result<WorkspaceBuildScripts> {
|
||||
let current_dir = workspace.workspace_root();
|
||||
|
||||
|
@ -74,6 +73,7 @@ impl WorkspaceBuildScripts {
|
|||
workspace.manifest_path(),
|
||||
current_dir,
|
||||
sysroot,
|
||||
toolchain,
|
||||
)?;
|
||||
Self::run_per_ws(cmd, workspace, progress)
|
||||
}
|
||||
|
@ -95,6 +95,7 @@ impl WorkspaceBuildScripts {
|
|||
&ManifestPath::try_from(working_directory.clone()).unwrap(),
|
||||
working_directory,
|
||||
&Sysroot::empty(),
|
||||
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
|
||||
|
@ -387,12 +388,13 @@ impl WorkspaceBuildScripts {
|
|||
manifest_path: &ManifestPath,
|
||||
current_dir: &AbsPath,
|
||||
sysroot: &Sysroot,
|
||||
toolchain: Option<&semver::Version>,
|
||||
) -> io::Result<Command> {
|
||||
let mut cmd = match config.run_build_script_command.as_deref() {
|
||||
match config.run_build_script_command.as_deref() {
|
||||
Some([program, args @ ..]) => {
|
||||
let mut cmd = toolchain::command(program, current_dir, &config.extra_env);
|
||||
cmd.args(args);
|
||||
cmd
|
||||
Ok(cmd)
|
||||
}
|
||||
_ => {
|
||||
let mut cmd = sysroot.tool(Tool::Cargo, current_dir, &config.extra_env);
|
||||
|
@ -444,40 +446,35 @@ impl WorkspaceBuildScripts {
|
|||
|
||||
cmd.arg("--keep-going");
|
||||
|
||||
cmd
|
||||
// If [`--compile-time-deps` flag](https://github.com/rust-lang/cargo/issues/14434) is
|
||||
// available in current toolchain's cargo, use it to build compile time deps only.
|
||||
const COMP_TIME_DEPS_MIN_TOOLCHAIN_VERSION: semver::Version = semver::Version {
|
||||
major: 1,
|
||||
minor: 89,
|
||||
patch: 0,
|
||||
pre: semver::Prerelease::EMPTY,
|
||||
build: semver::BuildMetadata::EMPTY,
|
||||
};
|
||||
|
||||
let cargo_comp_time_deps_available =
|
||||
toolchain.is_some_and(|v| *v >= COMP_TIME_DEPS_MIN_TOOLCHAIN_VERSION);
|
||||
|
||||
if cargo_comp_time_deps_available {
|
||||
cmd.env("__CARGO_TEST_CHANNEL_OVERRIDE_DO_NOT_USE_THIS", "nightly");
|
||||
cmd.arg("-Zunstable-options");
|
||||
cmd.arg("--compile-time-deps");
|
||||
} else if config.wrap_rustc_in_build_scripts {
|
||||
// Setup RUSTC_WRAPPER to point to `rust-analyzer` binary itself. We use
|
||||
// that to compile only proc macros and build scripts during the initial
|
||||
// `cargo check`.
|
||||
// We don't need this if we are using `--compile-time-deps` flag.
|
||||
let myself = std::env::current_exe()?;
|
||||
cmd.env("RUSTC_WRAPPER", myself);
|
||||
cmd.env("RA_RUSTC_WRAPPER", "1");
|
||||
}
|
||||
Ok(cmd)
|
||||
}
|
||||
};
|
||||
|
||||
// If [`--compile-time-deps` flag](https://github.com/rust-lang/cargo/issues/14434) is
|
||||
// available in current toolchain's cargo, use it to build compile time deps only.
|
||||
const COMP_TIME_DEPS_MIN_TOOLCHAIN_VERSION: semver::Version = semver::Version {
|
||||
major: 1,
|
||||
minor: 89,
|
||||
patch: 0,
|
||||
pre: semver::Prerelease::EMPTY,
|
||||
build: semver::BuildMetadata::EMPTY,
|
||||
};
|
||||
|
||||
let query_config = QueryConfig::Cargo(sysroot, manifest_path);
|
||||
let toolchain = version::get(query_config, &config.extra_env).ok().flatten();
|
||||
let cargo_comp_time_deps_available =
|
||||
toolchain.is_some_and(|v| v >= COMP_TIME_DEPS_MIN_TOOLCHAIN_VERSION);
|
||||
|
||||
if cargo_comp_time_deps_available {
|
||||
cmd.env("__CARGO_TEST_CHANNEL_OVERRIDE_DO_NOT_USE_THIS", "nightly");
|
||||
cmd.arg("-Zunstable-options");
|
||||
cmd.arg("--compile-time-deps");
|
||||
} else if config.wrap_rustc_in_build_scripts {
|
||||
// Setup RUSTC_WRAPPER to point to `rust-analyzer` binary itself. We use
|
||||
// that to compile only proc macros and build scripts during the initial
|
||||
// `cargo check`.
|
||||
// We don't need this if we are using `--compile-time-deps` flag.
|
||||
let myself = std::env::current_exe()?;
|
||||
cmd.env("RUSTC_WRAPPER", myself);
|
||||
cmd.env("RA_RUSTC_WRAPPER", "1");
|
||||
}
|
||||
|
||||
Ok(cmd)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -636,10 +636,16 @@ impl ProjectWorkspace {
|
|||
match &self.kind {
|
||||
ProjectWorkspaceKind::DetachedFile { cargo: Some((cargo, _, None)), .. }
|
||||
| ProjectWorkspaceKind::Cargo { cargo, error: None, .. } => {
|
||||
WorkspaceBuildScripts::run_for_workspace(config, cargo, progress, &self.sysroot)
|
||||
.with_context(|| {
|
||||
format!("Failed to run build scripts for {}", cargo.workspace_root())
|
||||
})
|
||||
WorkspaceBuildScripts::run_for_workspace(
|
||||
config,
|
||||
cargo,
|
||||
progress,
|
||||
&self.sysroot,
|
||||
self.toolchain.as_ref(),
|
||||
)
|
||||
.with_context(|| {
|
||||
format!("Failed to run build scripts for {}", cargo.workspace_root())
|
||||
})
|
||||
}
|
||||
_ => Ok(WorkspaceBuildScripts::default()),
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue