From e99cae0fdb12ceb05075960f168c71e39592f89e Mon Sep 17 00:00:00 2001 From: rymnc <43716372+rymnc@users.noreply.github.com> Date: Tue, 26 Nov 2024 16:11:35 +0530 Subject: [PATCH] fix: build script --- Cargo.lock | 15 ++++++++++++- fuel-zkvm-primitives-test-fixtures/Cargo.toml | 4 ++++ fuel-zkvm-primitives-test-fixtures/build.rs | 21 ++++++++++++++++--- 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2a62058..7233df3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3091,6 +3091,7 @@ dependencies = [ "serde_json", "tempfile", "tokio", + "which 7.0.0", ] [[package]] @@ -3259,7 +3260,7 @@ dependencies = [ "rand", "tempfile", "tokio", - "which", + "which 6.0.3", ] [[package]] @@ -8232,6 +8233,18 @@ dependencies = [ "winsafe", ] +[[package]] +name = "which" +version = "7.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9cad3279ade7346b96e38731a641d7343dd6a53d55083dd54eadfa5a1b38c6b" +dependencies = [ + "either", + "home", + "rustix", + "winsafe", +] + [[package]] name = "widestring" version = "1.1.0" diff --git a/fuel-zkvm-primitives-test-fixtures/Cargo.toml b/fuel-zkvm-primitives-test-fixtures/Cargo.toml index 1ea5e36..775205e 100644 --- a/fuel-zkvm-primitives-test-fixtures/Cargo.toml +++ b/fuel-zkvm-primitives-test-fixtures/Cargo.toml @@ -25,6 +25,10 @@ tempfile = "3.14.0" tokio = { workspace = true } clap = { version = "^4.0", features = ["derive"], optional = true } enum-iterator = { version = "2.1.0", optional = true } +which = "7.0.0" + +[build-dependencies] +which = "7.0.0" [dev-dependencies] paste = "1.0" diff --git a/fuel-zkvm-primitives-test-fixtures/build.rs b/fuel-zkvm-primitives-test-fixtures/build.rs index 9e7bd6c..a6f281c 100644 --- a/fuel-zkvm-primitives-test-fixtures/build.rs +++ b/fuel-zkvm-primitives-test-fixtures/build.rs @@ -1,10 +1,25 @@ +use std::env; +use std::path::Path; use std::process::Command; pub fn main() { - Command::new("forc") + // Check if `forc` is available in the system PATH + let forc_binary = which::which("forc").unwrap_or_else(|_| { + // If `forc` is not found in PATH, check $HOME/.fuelup/bin/forc + let home_dir = env::var("HOME").expect("Failed to get $HOME directory"); + let fallback_path = Path::new(&home_dir).join(".fuelup/bin/forc"); + if fallback_path.exists() { + fallback_path + } else { + panic!("`forc` binary not found in PATH or at $HOME/.fuelup/bin/forc"); + } + }); + + // Use the determined `forc` binary to build the contract + Command::new(forc_binary) .arg("build") .arg("--path") .arg("src/fixtures/counter_contract") .spawn() - .expect("failed to build contract"); -} \ No newline at end of file + .expect("Failed to build contract"); +}