Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions crates/project-model/src/build_dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,9 +459,7 @@ impl WorkspaceBuildScripts {
cmd.arg(target_dir.as_ref());
}

if let Some(target) = &config.target {
cmd.args(["--target", target]);
}
toolchain::cargo_use_targets(&mut cmd, config.target.as_slice());
let mut lockfile_copy = None;
if let Some(toolchain) = toolchain {
let lockfile_path =
Expand Down
4 changes: 1 addition & 3 deletions crates/project-model/src/toolchain_info/target_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ pub fn get(
let mut cmd = sysroot.tool(Tool::Cargo, cargo_toml.parent(), extra_env);
cmd.env("RUSTC_BOOTSTRAP", "1");
cmd.args(["rustc", "-Z", "unstable-options"]).args(RUSTC_ARGS);
if let Some(target) = target {
cmd.args(["--target", target]);
}
toolchain::cargo_use_targets(&mut cmd, target.as_slice());
cmd.args(["--", "-Z", "unstable-options"]);
match utf8_stdout(&mut cmd) {
Ok(output) => return process(output),
Expand Down
4 changes: 1 addition & 3 deletions crates/rust-analyzer/src/flycheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ pub(crate) enum Target {

impl CargoOptions {
pub(crate) fn apply_on_command(&self, cmd: &mut Command, ws_target_dir: Option<&Utf8Path>) {
for target in &self.target_tuples {
cmd.args(["--target", target.as_str()]);
}
toolchain::cargo_use_targets(cmd, &self.target_tuples);
if self.all_targets {
if self.set_test {
cmd.arg("--all-targets");
Expand Down
13 changes: 13 additions & 0 deletions crates/toolchain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,16 @@ pub fn probe_for_binary(path: Utf8PathBuf) -> Option<Utf8PathBuf> {
};
iter::once(path).chain(with_extension).find(|it| it.is_file())
}

/// Uses targets in a Cargo process.
pub fn cargo_use_targets(cmd: &mut Command, targets: impl IntoIterator<Item = impl AsRef<str>>) {
let mut has_target_json = false;
for target in targets {
let target = target.as_ref();
cmd.args(["--target", target]);
has_target_json |= target.ends_with(".json");
}
if has_target_json {
cmd.arg("-Zjson-target-spec");
}
}
Loading