Skip to content

Commit 7d4469d

Browse files
authored
feat: add node init command (#1383)
1 parent 451cd6c commit 7d4469d

51 files changed

Lines changed: 1862 additions & 329 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

Lines changed: 96 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ members = [
4444
"fendermint/actors/eam",
4545
"fendermint/actors/gas_market/eip1559",
4646

47-
"build-rs-utils",
47+
"build-rs-utils", "contracts-artifacts",
4848
]
4949

5050
[workspace.package]

contracts-artifacts/Cargo.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[package]
2+
name = "contracts-artifacts"
3+
version = "0.1.0"
4+
authors.workspace = true
5+
edition.workspace = true
6+
license.workspace = true
7+
license-file.workspace = true
8+
9+
[dependencies]
10+
anyhow = { workspace = true }
11+
tempfile = { workspace = true }
12+
rust-embed = "6.4.0"

contracts-artifacts/build.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
}

contracts-artifacts/src/lib.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2022-2024 Protocol Labs
2+
// SPDX-License-Identifier: MIT
3+
4+
use anyhow::Context;
5+
use rust_embed::RustEmbed;
6+
use std::{fs, path::PathBuf};
7+
use tempfile::TempDir;
8+
9+
#[derive(RustEmbed)]
10+
#[folder = "../contracts/out"]
11+
pub struct Artifacts;
12+
13+
pub fn extract_to_tempdir() -> anyhow::Result<(TempDir, PathBuf)> {
14+
let tmp = TempDir::new().context("failed to create temp dir")?;
15+
let base = tmp.path().to_path_buf();
16+
17+
for file in Artifacts::iter() {
18+
let rel = std::path::Path::new(file.as_ref());
19+
let dst = base.join(rel);
20+
21+
if let Some(parent) = dst.parent() {
22+
fs::create_dir_all(parent)
23+
.with_context(|| format!("failed to create dir {:?}", parent))?;
24+
}
25+
26+
let embedded = Artifacts::get(file.as_ref())
27+
.with_context(|| format!("missing embedded file {}", file.as_ref()))?;
28+
29+
fs::write(&dst, embedded.data.as_ref())
30+
.with_context(|| format!("failed to write {:?}", dst))?;
31+
}
32+
33+
Ok((tmp, base))
34+
}

0 commit comments

Comments
 (0)