Skip to content
This repository has been archived by the owner on Oct 31, 2024. It is now read-only.

Commit

Permalink
feat: test build.rs
Browse files Browse the repository at this point in the history
Signed-off-by: Jawad Tariq <[email protected]>
  • Loading branch information
JDawg287 committed Mar 13, 2024
1 parent b469dfe commit ff1c58f
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 0 deletions.
40 changes: 40 additions & 0 deletions crates/topos/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::process::Command;

const CONTRACTS_PATH: &str = "./contracts";
const DEFAULT_VERSION: &str = "detached";

fn main() {
Expand All @@ -20,4 +21,43 @@ fn main() {

println!("cargo:rustc-env=TOPOS_VERSION={topos_version}");
}

compile_contracts();
}

fn compile_contracts() {
if !CONTRACTS_PATH.is_empty() {
if let Err(err) = std::env::set_current_dir(CONTRACTS_PATH) {
eprintln!("Error changing to subdirectory: {}", err);
return;
}
}

let install_result = Command::new("npm")
.arg("ci")
.status();

let compile_result = Command::new("npm")
.arg("run")
.arg("build")
.status();

match compile_result {
Ok(status) => {
if status.success() {
println!("Artifacts compiled successfully in {}!", CONTRACTS_PATH);
} else {
eprintln!("Error compiling artifacts in {}: {:?}", CONTRACTS_PATH, status);
}
}
Err(err) => {
eprintln!("Error executing npx hardhat compile: {}", err);
}
}

if let Err(err) = std::env::set_current_dir("..") {
eprintln!("Error changing back to the original directory: {}", err);
}

println!("cargo:rerun-if-changed={}", CONTRACTS_PATH);
}
69 changes: 69 additions & 0 deletions crates/topos/custom_build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
use std::process::Command;

const CONTRACTS_PATH: &str = "./contracts";

fn main () {
if !CONTRACTS_PATH.is_empty() {
if let Err(err) = std::env::set_current_dir(CONTRACTS_PATH) {
eprintln!("Error changing to subdirectory: {}", err);
return;
}
}

let compile_result = Command::new("npx")
.arg("hardhat")
.arg("compile")
.status();

match compile_result {
Ok(status) => {
if status.success() {
println!("Artifacts compiled successfully in {}!", CONTRACTS_PATH);
} else {
eprintln!("Error compiling artifacts in {}: {:?}", CONTRACTS_PATH, status);
}
}
Err(err) => {
eprintln!("Error executing npx hardhat compile: {}", err);
}
}

if let Err(err) = std::env::set_current_dir("..") {
eprintln!("Error changing back to the original directory: {}", err);
}

println!("cargo:rerun-if-changed={}", CONTRACTS_PATH);
}

fn compile_contracts() {
if !CONTRACTS_PATH.is_empty() {
if let Err(err) = std::env::set_current_dir(CONTRACTS_PATH) {
eprintln!("Error changing to subdirectory: {}", err);
return;
}
}

let compile_result = Command::new("npx")
.arg("hardhat")
.arg("compile")
.status();

match compile_result {
Ok(status) => {
if status.success() {
println!("Artifacts compiled successfully in {}!", CONTRACTS_PATH);
} else {
eprintln!("Error compiling artifacts in {}: {:?}", CONTRACTS_PATH, status);
}
}
Err(err) => {
eprintln!("Error executing npx hardhat compile: {}", err);
}
}

if let Err(err) = std::env::set_current_dir("..") {
eprintln!("Error changing back to the original directory: {}", err);
}

println!("cargo:rerun-if-changed={}", CONTRACTS_PATH);
}

0 comments on commit ff1c58f

Please sign in to comment.