Skip to content

Commit

Permalink
Build dapp from build.rs before coping over
Browse files Browse the repository at this point in the history
  • Loading branch information
lucksus committed Mar 21, 2024
1 parent ff01fa5 commit 67e0af5
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion rust-executor/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down Expand Up @@ -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");

Expand All @@ -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);
}
}

0 comments on commit 67e0af5

Please sign in to comment.