Skip to content

Commit 419ad27

Browse files
authored
Merge pull request #458 from EspressoSystems/tw/contracts-build-rs
Less noisy build.rs and selective formatting.
2 parents f843f66 + f056f8c commit 419ad27

File tree

3 files changed

+17
-26
lines changed

3 files changed

+17
-26
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@ __pycache__/
3535

3636
# Rust bindings for smart contracts
3737
timeboost-contract/src/bindings
38+
foundry.lock

justfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ check-individually:
3636
cargo check -p $pkg || exit 1; \
3737
done
3838

39-
fmt:
40-
cargo +nightly fmt --all
39+
fmt *ARGS='--all':
40+
cargo +nightly fmt {{ARGS}}
4141

4242
fmt_check:
4343
cargo +nightly fmt --check

timeboost-contract/build.rs

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@ fn main() {
99

1010
if !contracts_out.exists() {
1111
match std::process::Command::new("forge").arg("build").output() {
12-
Ok(res) if res.status.success() => {
13-
println!("cargo::warning=Successfully built contracts")
14-
}
1512
Ok(res) => {
16-
println!("cargo::error=Building contracts failed: {res:?}");
17-
return;
13+
if !res.status.success() {
14+
println!("cargo::error=Building contracts failed: {res:?}");
15+
return;
16+
}
1817
}
1918
Err(e) => {
2019
println!("cargo::error=Failed to run `forge build` command: {e}");
@@ -36,11 +35,6 @@ fn main() {
3635
return;
3736
}
3837

39-
println!(
40-
"cargo::warning=Found {} contract artifacts",
41-
contract_artifacts.len()
42-
);
43-
4438
// Generate bindings for each contract
4539
for (contract_name, json_path) in &contract_artifacts {
4640
generate_contract_binding(contract_name, json_path, bindings_dir);
@@ -50,15 +44,17 @@ fn main() {
5044
generate_bindings_module(&contract_artifacts, bindings_dir);
5145

5246
// Format the generated bindings
53-
match std::process::Command::new("just").arg("fmt").output() {
54-
Ok(result) if result.status.success() => {
55-
println!("cargo::warning=Successfully formatted generated bindings");
56-
}
47+
match std::process::Command::new("just")
48+
.args(["fmt", "-p", env!("CARGO_PKG_NAME")])
49+
.output()
50+
{
5751
Ok(result) => {
58-
println!(
59-
"cargo::error=Format command failed with exit code: {:?}",
60-
result.status.code()
61-
);
52+
if !result.status.success() {
53+
println!(
54+
"cargo::error=Format command failed with exit code: {:?}",
55+
result.status.code()
56+
);
57+
}
6258
}
6359
Err(e) => {
6460
println!("cargo::error=Failed to run format command: {e}");
@@ -117,8 +113,6 @@ fn walk_directory(dir: &Path, callback: &mut dyn FnMut(&Path)) {
117113
}
118114

119115
fn generate_contract_binding(contract_name: &str, json_path: &Path, bindings_dir: &Path) {
120-
println!("cargo::warning=Generating bindings for {contract_name} from JSON artifact");
121-
122116
// Create the relative path from the binding file to the JSON artifact
123117
let json_path_str = json_path.display().to_string().replace('\\', "/");
124118

@@ -129,8 +123,6 @@ fn generate_contract_binding(contract_name: &str, json_path: &Path, bindings_dir
129123
let output_path = bindings_dir.join(format!("{}.rs", contract_name.to_lowercase()));
130124
fs::write(&output_path, bindings)
131125
.unwrap_or_else(|_| panic!("Failed to write {contract_name} bindings"));
132-
133-
println!("cargo::warning={contract_name} bindings written to {output_path:?}");
134126
}
135127

136128
fn generate_bindings_module(contract_artifacts: &[(String, PathBuf)], bindings_dir: &Path) {
@@ -151,6 +143,4 @@ fn generate_bindings_module(contract_artifacts: &[(String, PathBuf)], bindings_d
151143

152144
let bindings_module_path = bindings_dir.join("mod.rs");
153145
fs::write(&bindings_module_path, module_content).expect("Failed to write bindings module");
154-
155-
println!("cargo::warning=Bindings module written to {bindings_module_path:?}");
156146
}

0 commit comments

Comments
 (0)