Skip to content

Commit 7542247

Browse files
committed
fix(coprocessor): fhevm-listener, build contracts in build.rs
1 parent d86f391 commit 7542247

File tree

2 files changed

+51
-5
lines changed

2 files changed

+51
-5
lines changed

.github/workflows/coprocessor-cargo-tests.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,6 @@ jobs:
7272
with:
7373
node-version: 20.x
7474

75-
- run: cp ./host-contracts/.env.example ./host-contracts/.env
76-
- run: npm --prefix ./host-contracts ci --include=optional
77-
- run: "cd host-contracts && npm install && npx hardhat compile"
78-
7975
- name: Run tests
8076
run: |
8177
DATABASE_URL=postgresql://postgres:postgres@localhost:5432/coprocessor cargo test --release -- --test-threads=1

coprocessor/fhevm-engine/fhevm-listener/build.rs

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,60 @@ use foundry_compilers::{
44
Project, ProjectPathsConfig,
55
};
66
use semver::Version;
7-
use std::path::Path;
7+
use std::{env, fs, path::Path, process::Command};
8+
9+
fn build_contracts() {
10+
println!("cargo:rerun-if-changed=../../../host-contracts");
11+
// Step 1: Copy ../../contracts/.env.example to ../../contracts/.env
12+
let env_example = Path::new("../../../host-contracts/.env.example");
13+
let env_dest = Path::new("../../../host-contracts/.env");
14+
if !env_dest.exists() && env_example.exists() {
15+
fs::copy(env_example, env_dest).expect("Failed to copy .env.example to .env");
16+
println!("Copied .env.example to .env");
17+
} else {
18+
panic!("Error: .env.example not found in contracts directory");
19+
}
20+
21+
// Change to the contracts directory for npm commands.
22+
let contracts_dir = Path::new("../../../host-contracts");
23+
if !contracts_dir.exists() {
24+
panic!("Error: contracts directory not found");
25+
}
26+
env::set_current_dir(contracts_dir).expect("Failed to change to contracts directory");
27+
28+
// Step 2: Run `npm ci run `npm ci --include=optional` in ../../contracts
29+
let npm_ci_status = Command::new("npm")
30+
.args(["ci", "--include=optional"])
31+
.status()
32+
.expect("Failed to run npm ci");
33+
if !npm_ci_status.success() {
34+
panic!("Error: npm ci failed");
35+
}
36+
println!("Ran npm ci successfully");
37+
38+
// Step 3: Run `npm install && npx hardhat compile` in ../../contracts
39+
let npm_install_status = Command::new("npm")
40+
.arg("install")
41+
.status()
42+
.expect("Failed to run npm install");
43+
if !npm_install_status.success() {
44+
panic!("Error: npm install failed");
45+
}
46+
println!("Ran npm install successfully");
47+
48+
let hardhat_compile_status = Command::new("npx")
49+
.args(["hardhat", "compile"])
50+
.status()
51+
.expect("Failed to run npx hardhat compile");
52+
if !hardhat_compile_status.success() {
53+
panic!("Error: npx hardhat compile failed");
54+
}
55+
println!("Ran npx hardhat compile successfully");
56+
}
857

958
fn main() {
1059
println!("cargo::warning=build.rs run ...");
60+
build_contracts();
1161
// build tests contracts
1262
let paths =
1363
ProjectPathsConfig::hardhat(Path::new(env!("CARGO_MANIFEST_DIR")))

0 commit comments

Comments
 (0)