Skip to content

Commit

Permalink
Make Scarb smarter when searching for Cargo binary (#1338)
Browse files Browse the repository at this point in the history
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 <marek.kaput@swmansion.com>
  • Loading branch information
mkaput authored Jun 4, 2024
1 parent fc81b05 commit 43f76f4
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ petgraph = "0.6"
predicates = "3"
proc-macro2 = "1"
quote = "1"
ra_ap_toolchain = "0.0.218"
rayon = "1.10"
redb = "2.1.0"
reqwest = { version = "0.11", features = ["gzip", "brotli", "deflate", "json", "stream"], default-features = false }
Expand Down
3 changes: 2 additions & 1 deletion scarb/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ cairo-lang-formatter.workspace = true
cairo-lang-macro = { path = "../plugins/cairo-lang-macro" }
cairo-lang-macro-stable = { path = "../plugins/cairo-lang-macro-stable" }
cairo-lang-semantic.workspace = true
cairo-lang-sierra.workspace = true
cairo-lang-sierra-to-casm.workspace = true
cairo-lang-sierra.workspace = true
cairo-lang-starknet-classes.workspace = true
cairo-lang-starknet.workspace = true
cairo-lang-syntax.workspace = true
Expand All @@ -51,6 +51,7 @@ libloading.workspace = true
once_cell.workspace = true
pathdiff.workspace = true
petgraph.workspace = true
ra_ap_toolchain.workspace = true
redb.workspace = true
reqwest.workspace = true
scarb-build-metadata = { path = "../utils/scarb-build-metadata" }
Expand Down
3 changes: 2 additions & 1 deletion scarb/src/compiler/plugin/proc_macro/compilation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::process::exec_piping;
use anyhow::Result;
use camino::Utf8PathBuf;
use libloading::library_filename;
use ra_ap_toolchain::Tool;
use scarb_ui::{Message, OutputFormat};
use serde::{Serialize, Serializer};
use serde_json::value::RawValue;
Expand Down Expand Up @@ -118,7 +119,7 @@ impl From<OutputFormat> for CargoOutputFormat {

impl From<CargoCommand> for Command {
fn from(args: CargoCommand) -> Self {
let mut cmd = Command::new("cargo");
let mut cmd = Command::new(Tool::Cargo.path());
cmd.current_dir(args.current_dir);
match args.action {
CargoAction::Fetch => cmd.arg("fetch"),
Expand Down

0 comments on commit 43f76f4

Please sign in to comment.