From 67e0af504972d3d1dfd35d602c665bf1d3a2ec60 Mon Sep 17 00:00:00 2001 From: Nicolas Luck Date: Thu, 21 Mar 2024 22:13:20 +0100 Subject: [PATCH] Build dapp from build.rs before coping over --- rust-executor/build.rs | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/rust-executor/build.rs b/rust-executor/build.rs index f5967b3fb..2dc9b54d4 100644 --- a/rust-executor/build.rs +++ b/rust-executor/build.rs @@ -2,6 +2,34 @@ use std::fs; use std::path::Path; use std::process::Command; +fn build_dapp() -> std::io::Result<()> { + let dapp_dir = Path::new("../dapp"); + + // Navigate to the dapp directory + std::env::set_current_dir(&dapp_dir)?; + + // Run `pnpm install` + let status = Command::new("pnpm") + .arg("install") + .status()?; + if !status.success() { + return Err(std::io::Error::new(std::io::ErrorKind::Other, "pnpm install failed")); + } + + // Run `pnpm build` + let status = Command::new("pnpm") + .arg("build") + .status()?; + if !status.success() { + return Err(std::io::Error::new(std::io::ErrorKind::Other, "pnpm build failed")); + } + + // Navigate back to the original directory + std::env::set_current_dir(env!("CARGO_MANIFEST_DIR"))?; + + Ok(()) +} + fn copy_dir_recursive(source: &Path, target: &Path) -> std::io::Result<()> { if source.is_dir() { fs::create_dir_all(target)?; @@ -46,9 +74,15 @@ fn build_js_executor() -> std::io::Result<()> { fn main() { println!("cargo:rerun-if-changed=build.rs"); // Ensure the build script is re-run if it is changed + println!("cargo:rerun-if-changed=../dapp"); // Re-run if the dapp directory changes println!("cargo:rerun-if-changed=../dapp/public"); // Re-run if the dapp directory changes println!("cargo:rerun-if-changed=../executor"); // Re-run if the dapp directory changes + if let Err(err) = build_dapp() { + eprintln!("Error building dapp: {}", err); + std::process::exit(1); + } + let source_dir = "../dapp/public"; let target_dir = concat!(env!("CARGO_MANIFEST_DIR"), "/dapp"); @@ -61,7 +95,7 @@ fn main() { } if let Err(err) = build_js_executor() { - eprintln!("Error running pnpm commands: {}", err); + eprintln!("Error building JS executor: {}", err); std::process::exit(1); } } \ No newline at end of file