-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(blueprint-build-utils): utilities lib for build scripts (#442)
- Loading branch information
Showing
8 changed files
with
88 additions
and
102 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[package] | ||
name = "blueprint-build-utils" | ||
version = "0.1.0" | ||
authors.workspace = true | ||
edition.workspace = true | ||
license.workspace = true | ||
homepage.workspace = true | ||
repository.workspace = true | ||
|
||
[dependencies] | ||
|
||
[lints] | ||
workspace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
use std::env; | ||
use std::path::PathBuf; | ||
use std::process::Command; | ||
|
||
/// Build the Smart contracts at the specified directories, automatically rerunning if changes are | ||
/// detected in this crates Smart Contracts (`./contracts/lib`). | ||
/// | ||
/// # Panics | ||
/// - If the Cargo Manifest directory is not found. | ||
/// - If the `forge` executable is not found. | ||
pub fn build_contracts(contract_dirs: Vec<&str>) { | ||
println!("cargo::rerun-if-changed=contracts/lib/*"); | ||
println!("cargo::rerun-if-changed=contracts/src/*"); | ||
|
||
// Get the project root directory | ||
let root = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()); | ||
|
||
// Try to find the `forge` executable dynamically | ||
let forge_executable = match Command::new("which").arg("forge").output() { | ||
Ok(output) => { | ||
let path = String::from_utf8_lossy(&output.stdout).trim().to_string(); | ||
assert!( | ||
!path.is_empty(), | ||
"Forge executable not found. Make sure Foundry is installed." | ||
); | ||
path | ||
} | ||
Err(e) => panic!("Failed to find `forge` executable: {e}"), | ||
}; | ||
|
||
for dir in contract_dirs { | ||
let full_path = root.join(dir).canonicalize().unwrap_or_else(|_| { | ||
println!( | ||
"Directory not found or inaccessible: {}", | ||
root.join(dir).display() | ||
); | ||
root.join(dir) | ||
}); | ||
|
||
if full_path.exists() { | ||
println!("cargo:rerun-if-changed={}", full_path.display()); | ||
|
||
let status = Command::new(&forge_executable) | ||
.current_dir(&full_path) | ||
.arg("build") | ||
.status() | ||
.expect("Failed to execute Forge build"); | ||
|
||
assert!( | ||
status.success(), | ||
"Forge build failed for directory: {}", | ||
full_path.display() | ||
); | ||
} else { | ||
println!( | ||
"Directory not found or does not exist: {}", | ||
full_path.display() | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,10 @@ | ||
use std::env; | ||
use std::path::PathBuf; | ||
use std::process::Command; | ||
|
||
fn main() { | ||
println!("cargo:rerun-if-changed=src/cli"); | ||
println!("cargo:rerun-if-changed=src/lib.rs"); | ||
println!("cargo:rerun-if-changed=src/main.rs"); | ||
|
||
let contract_dirs: Vec<&str> = vec![ | ||
"./contracts/lib/eigenlayer-middleware/lib/eigenlayer-contracts", | ||
"./contracts/lib/eigenlayer-middleware", | ||
"./contracts/lib/forge-std", | ||
"./contracts", | ||
]; | ||
|
||
// Get the project root directory | ||
let root = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()); | ||
|
||
// Try to find the `forge` executable dynamically | ||
let forge_executable = match Command::new("which").arg("forge").output() { | ||
Ok(output) => { | ||
let path = String::from_utf8_lossy(&output.stdout).trim().to_string(); | ||
if path.is_empty() { | ||
panic!("Forge executable not found. Make sure Foundry is installed."); | ||
} | ||
path | ||
} | ||
Err(_) => panic!("Failed to locate `forge` executable. Make sure Foundry is installed."), | ||
}; | ||
|
||
for dir in contract_dirs { | ||
let full_path = root.join(dir).canonicalize().unwrap_or_else(|_| { | ||
println!( | ||
"Directory not found or inaccessible: {}", | ||
root.join(dir).display() | ||
); | ||
root.join(dir) | ||
}); | ||
|
||
if full_path.exists() { | ||
println!("cargo:rerun-if-changed={}", full_path.display()); | ||
|
||
let status = Command::new(&forge_executable) | ||
.current_dir(&full_path) | ||
.arg("build") | ||
.status() | ||
.expect("Failed to execute Forge build"); | ||
|
||
if !status.success() { | ||
panic!("Forge build failed for directory: {}", full_path.display()); | ||
} | ||
} else { | ||
println!( | ||
"Directory not found or does not exist: {}", | ||
full_path.display() | ||
); | ||
} | ||
} | ||
blueprint_build_utils::build_contracts(contract_dirs); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,9 @@ | ||
use std::env; | ||
use std::path::PathBuf; | ||
use std::process::Command; | ||
|
||
fn main() { | ||
println!("cargo:rerun-if-changed=src/cli"); | ||
println!("cargo:rerun-if-changed=src/lib.rs"); | ||
println!("cargo:rerun-if-changed=src/main.rs"); | ||
|
||
let contract_dirs: Vec<&str> = vec![ | ||
"./contracts/lib/core", | ||
"./contracts/lib/forge-std", | ||
"./contracts", | ||
]; | ||
|
||
// Get the project root directory | ||
let root = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()); | ||
print!("root: {:?}", root); | ||
// Try to find the `forge` executable dynamically | ||
let forge_executable = match Command::new("which").arg("forge").output() { | ||
Ok(output) => { | ||
let path = String::from_utf8_lossy(&output.stdout).trim().to_string(); | ||
if path.is_empty() { | ||
panic!("Forge executable not found. Make sure Foundry is installed."); | ||
} | ||
path | ||
} | ||
Err(_) => panic!("Failed to locate `forge` executable. Make sure Foundry is installed."), | ||
}; | ||
|
||
for dir in contract_dirs { | ||
let full_path = root.join(dir).canonicalize().unwrap_or_else(|_| { | ||
println!( | ||
"Directory not found or inaccessible: {}", | ||
root.join(dir).display() | ||
); | ||
root.join(dir) | ||
}); | ||
|
||
if full_path.exists() { | ||
println!("cargo:rerun-if-changed={}", full_path.display()); | ||
|
||
let status = Command::new(&forge_executable) | ||
.current_dir(&full_path) | ||
.arg("build") | ||
.status() | ||
.expect("Failed to execute Forge build"); | ||
|
||
if !status.success() { | ||
panic!("Forge build failed for directory: {}", full_path.display()); | ||
} | ||
} else { | ||
println!( | ||
"Directory not found or does not exist: {}", | ||
full_path.display() | ||
); | ||
} | ||
} | ||
blueprint_build_utils::build_contracts(contract_dirs); | ||
} |