Skip to content

Commit 43f76f4

Browse files
authored
Make Scarb smarter when searching for Cargo binary (#1338)
This commit borrows the logic for looking for Cargo from Rust Analyzer, via its published `ra_ap_toolchain` crate. This change makes Scarb aware of: 1. The `CARGO` environment variable 2. The relatively well-known `$CARGO_HOME` directory This should make Scarb succeed to run `cargo fetch`/`build` when being run outside the interactive shell (i.e. without environment set by `rustup`). This includes running Scarb from CairoLS that is being run from a desktop application (like VSCode launched from macOS Dock). Signed-off-by: Marek Kaput <[email protected]>
1 parent fc81b05 commit 43f76f4

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

Cargo.lock

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ petgraph = "0.6"
9292
predicates = "3"
9393
proc-macro2 = "1"
9494
quote = "1"
95+
ra_ap_toolchain = "0.0.218"
9596
rayon = "1.10"
9697
redb = "2.1.0"
9798
reqwest = { version = "0.11", features = ["gzip", "brotli", "deflate", "json", "stream"], default-features = false }

scarb/Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ cairo-lang-formatter.workspace = true
2424
cairo-lang-macro = { path = "../plugins/cairo-lang-macro" }
2525
cairo-lang-macro-stable = { path = "../plugins/cairo-lang-macro-stable" }
2626
cairo-lang-semantic.workspace = true
27-
cairo-lang-sierra.workspace = true
2827
cairo-lang-sierra-to-casm.workspace = true
28+
cairo-lang-sierra.workspace = true
2929
cairo-lang-starknet-classes.workspace = true
3030
cairo-lang-starknet.workspace = true
3131
cairo-lang-syntax.workspace = true
@@ -51,6 +51,7 @@ libloading.workspace = true
5151
once_cell.workspace = true
5252
pathdiff.workspace = true
5353
petgraph.workspace = true
54+
ra_ap_toolchain.workspace = true
5455
redb.workspace = true
5556
reqwest.workspace = true
5657
scarb-build-metadata = { path = "../utils/scarb-build-metadata" }

scarb/src/compiler/plugin/proc_macro/compilation.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::process::exec_piping;
55
use anyhow::Result;
66
use camino::Utf8PathBuf;
77
use libloading::library_filename;
8+
use ra_ap_toolchain::Tool;
89
use scarb_ui::{Message, OutputFormat};
910
use serde::{Serialize, Serializer};
1011
use serde_json::value::RawValue;
@@ -118,7 +119,7 @@ impl From<OutputFormat> for CargoOutputFormat {
118119

119120
impl From<CargoCommand> for Command {
120121
fn from(args: CargoCommand) -> Self {
121-
let mut cmd = Command::new("cargo");
122+
let mut cmd = Command::new(Tool::Cargo.path());
122123
cmd.current_dir(args.current_dir);
123124
match args.action {
124125
CargoAction::Fetch => cmd.arg("fetch"),

0 commit comments

Comments
 (0)