Skip to content

Commit

Permalink
refacto build.rs script
Browse files Browse the repository at this point in the history
  • Loading branch information
ametel01 committed Sep 13, 2024
1 parent 45c77b7 commit ea9eb12
Showing 1 changed file with 34 additions and 6 deletions.
40 changes: 34 additions & 6 deletions rust/build.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
use std::{collections::HashMap, env::current_dir, path::PathBuf};

use std::{collections::HashMap, env::current_dir, path::{PathBuf, Path}, fs};
use ethers::prelude::Abigen;

fn check_path_exists(path: &Path) {
if !path.exists() {
panic!("Path does not exist: {:?}", path);
}
}

fn generate_eth_bind(name: &str, abi_file: &str, bind_out: PathBuf) {
// Check if the ABI file exists
let abi_file_path = Path::new(abi_file);
check_path_exists(abi_file_path);

// Remove output file if it exists
if bind_out.exists() {
std::fs::remove_file(&bind_out).unwrap();
fs::remove_file(&bind_out).unwrap();
}

// Generate Ethereum bindings
Abigen::new(name, abi_file)
.unwrap()
.generate()
Expand All @@ -16,8 +27,13 @@ fn generate_eth_bind(name: &str, abi_file: &str, bind_out: PathBuf) {
}

fn generate_strk_bind(name: &str, abi_file: &str, bind_out: PathBuf) {
// Check if the ABI file exists
let abi_file_path = Path::new(abi_file);
check_path_exists(abi_file_path);

// Remove output file if it exists
if bind_out.exists() {
std::fs::remove_file(&bind_out).unwrap();
fs::remove_file(&bind_out).unwrap();
}

let mut aliases = HashMap::new();
Expand Down Expand Up @@ -50,6 +66,11 @@ fn main() {
.unwrap()
.join("tests")
.join("contracts/eth/bind");

// Check if the Ethereum ABI directory exists
check_path_exists(&eth_abi_base);
check_path_exists(&eth_bind_base);

let eth_deployments = [
("Mailbox", "mailbox"),
("FastHypERC20", "fast_hyp_erc20"),
Expand All @@ -73,13 +94,20 @@ fn main() {
// Generate Starknet bindings
let strk_abi_base = current_dir()
.unwrap()
.parent()
.parent() // Move one directory up to source directory
.unwrap()
.join("contracts/target/dev");
.join("cairo")
.join("target")
.join("dev");
let strk_bind_base = current_dir()
.unwrap()
.join("tests")
.join("contracts/strk/bind");

// Check if the Starknet ABI directory exists
check_path_exists(&strk_abi_base);
check_path_exists(&strk_bind_base);

let strk_deployments = [
("mailbox", "mailbox"),
("domain_routing_ism", "routing"),
Expand Down

0 comments on commit ea9eb12

Please sign in to comment.