forked from OpenZeppelin/openzeppelin-relayer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.rs
More file actions
104 lines (92 loc) · 3.6 KB
/
build.rs
File metadata and controls
104 lines (92 loc) · 3.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
use std::path::Path;
use std::process::Command;
fn main() {
let plugins_dir = Path::new("plugins");
if !plugins_dir.exists() {
println!("cargo:warning=plugins directory not found, skipping plugin setup");
return;
}
let node_modules = plugins_dir.join("node_modules");
let esbuild_bin = node_modules.join(".bin/esbuild");
let pool_executor_ts = plugins_dir.join("lib/pool-executor.ts");
let pool_executor_js = plugins_dir.join("lib/pool-executor.js");
// Tell Cargo when to rerun this script
println!("cargo:rerun-if-changed=plugins/lib/pool-executor.ts");
println!("cargo:rerun-if-changed=plugins/package.json");
// Check if pnpm is available
let pnpm_check = Command::new("pnpm").arg("--version").output();
if pnpm_check.is_err() {
println!("cargo:warning=pnpm not found in PATH, skipping plugin setup");
println!("cargo:warning=Run 'pnpm install && pnpm run build' in plugins/ manually");
return;
}
// Check if node_modules or esbuild is missing - need to install dependencies
let needs_install = !node_modules.exists() || !esbuild_bin.exists();
if needs_install {
if node_modules.exists() && !esbuild_bin.exists() {
println!(
"cargo:warning=esbuild not found in node_modules, reinstalling dependencies..."
);
} else {
println!("Installing plugin dependencies...");
}
let output = Command::new("pnpm")
.arg("install")
.arg("--ignore-scripts") // Skip postinstall, we'll build explicitly below
.current_dir(plugins_dir)
.output();
match output {
Ok(output) if output.status.success() => {
println!("✓ pnpm install completed");
}
Ok(output) => {
let stderr = String::from_utf8_lossy(&output.stderr);
println!("cargo:warning=pnpm install failed: {stderr}");
return;
}
Err(e) => {
println!("cargo:warning=Failed to execute pnpm install: {e}");
return;
}
}
// Verify esbuild is now available after install
if !esbuild_bin.exists() {
println!("cargo:warning=esbuild still not found after pnpm install");
println!("cargo:warning=Try running 'pnpm install' manually in plugins/ directory");
return;
}
}
// Build pool-executor if source is newer than output (or output missing)
let needs_build = if !pool_executor_js.exists() {
true
} else {
// Compare modification times
match (
pool_executor_ts.metadata().and_then(|m| m.modified()),
pool_executor_js.metadata().and_then(|m| m.modified()),
) {
(Ok(src_time), Ok(out_time)) => src_time > out_time,
_ => true, // Rebuild if we can't determine
}
};
if needs_build {
println!("Building executor...");
let output = Command::new("pnpm")
.arg("run")
.arg("build")
.current_dir(plugins_dir)
.output();
match output {
Ok(output) if output.status.success() => {
println!("✓ executor built successfully");
}
Ok(output) => {
let stderr = String::from_utf8_lossy(&output.stderr);
println!("cargo:warning=executor build failed: {stderr}");
}
Err(e) => {
println!("cargo:warning=Failed to build executor: {e}");
}
}
}
}