|
| 1 | +// Copyright 2022-2024 Protocol Labs |
| 2 | +// SPDX-License-Identifier: MIT |
| 3 | +// contracts-artifacts/build.rs |
| 4 | + |
| 5 | +use std::{env, fs, path::PathBuf, process::Command}; |
| 6 | + |
| 7 | +fn main() { |
| 8 | + let manifest_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()); |
| 9 | + let contracts_dir = manifest_dir.join("../contracts"); |
| 10 | + let out_dir = contracts_dir.join("out"); |
| 11 | + |
| 12 | + println!("cargo:warning=📦 contracts_dir = {:?}", contracts_dir); |
| 13 | + println!("cargo:warning=📦 out_dir = {:?}", out_dir); |
| 14 | + |
| 15 | + if let Err(e) = fs::create_dir_all(&out_dir) { |
| 16 | + println!("cargo:warning=❌ failed to mkdir {:?}: {}", out_dir, e); |
| 17 | + } |
| 18 | + |
| 19 | + let status = Command::new("make") |
| 20 | + .arg("build") |
| 21 | + .current_dir(&contracts_dir) |
| 22 | + .status() |
| 23 | + .expect("failed to run `make build` in contracts-artifacts"); |
| 24 | + if !status.success() { |
| 25 | + panic!("`make build` failed"); |
| 26 | + } |
| 27 | + |
| 28 | + match fs::read_dir(&out_dir) { |
| 29 | + Ok(rd) => { |
| 30 | + for entry in rd.flatten() { |
| 31 | + println!("cargo:warning=📄 found entry: {:?}", entry.path()); |
| 32 | + // if it's a directory, list one level deeper: |
| 33 | + if entry.path().is_dir() { |
| 34 | + if let Ok(rd2) = fs::read_dir(entry.path()) { |
| 35 | + for e2 in rd2.flatten() { |
| 36 | + println!("cargo:warning= └── {:?}", e2.path()); |
| 37 | + } |
| 38 | + } |
| 39 | + } |
| 40 | + } |
| 41 | + } |
| 42 | + Err(e) => println!("cargo:warning=❌ read_dir failed on {:?}: {}", out_dir, e), |
| 43 | + } |
| 44 | + |
| 45 | + println!( |
| 46 | + "cargo:rerun-if-changed={}/Makefile", |
| 47 | + contracts_dir.display() |
| 48 | + ); |
| 49 | + println!( |
| 50 | + "cargo:rerun-if-changed={}/contracts/**/*.sol", |
| 51 | + contracts_dir.display() |
| 52 | + ); |
| 53 | + println!("cargo:rerun-if-changed={}", out_dir.display()); |
| 54 | +} |
0 commit comments