From bfeddf04bb83df288c54343a0d22415d570272f3 Mon Sep 17 00:00:00 2001 From: Hou Xiaoxuan Date: Mon, 15 Jul 2024 00:29:59 +0800 Subject: [PATCH 1/4] fix: lost npm adaptation for windows Signed-off-by: Hou Xiaoxuan --- neptune/build.rs | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/neptune/build.rs b/neptune/build.rs index 2c0d3a37c..af353a4cf 100644 --- a/neptune/build.rs +++ b/neptune/build.rs @@ -20,17 +20,25 @@ fn copy_mega_apps() { } /// use npm to build agent ui in `libs/ztm/agent/gui` -fn build_agent_ui() { +fn npm_build_agent_ui() { let ui = Path::new("libs/ztm/agent/gui"); if cfg!(feature = "agent-ui") { if !ui.exists() { // run npm run build in the libs/ztm/gui + #[cfg(any(target_os = "linux", target_os = "macos"))] let _ = std::process::Command::new("npm") .current_dir("libs/ztm/gui") .arg("run") .arg("build") .output() .expect("failed to run npm run build in ztm/gui"); + #[cfg(target_os = "windows")] + let _ = std::process::Command::new("cmd.exe") + .current_dir("libs/ztm/gui") + .arg("/C") + .arg("npm run build") + .output() + .expect("failed to run npm run build in ztm/gui"); } } else if ui.exists() { std::fs::remove_dir_all(ui).expect("failed to remove agent/gui"); @@ -114,17 +122,31 @@ fn copy_lib_to_target(dst: &Path) { fs::copy(&source, &target).expect("failed to copy lib to target"); } -fn build() -> PathBuf { - build_agent_ui(); - - /* compile ztm & pipy */ - // run npm install in the libs/ztm +// run npm install in the libs/ztm/pipy +fn npm_install_pipy() { + #[cfg(any(target_os = "linux", target_os = "macos"))] let _ = std::process::Command::new("npm") .current_dir("libs/ztm/pipy") .arg("install") .output() .expect("failed to run npm install in ztm/pipy"); + #[cfg(target_os = "windows")] + let _ = std::process::Command::new("cmd.exe") + .current_dir("libs/ztm/pipy") + // .arg("install") + .arg("/C") + .arg("npm install") + .output() + .expect("failed to run npm install in ztm/pipy"); +} + +fn build() -> PathBuf { + npm_build_agent_ui(); + + /* compile ztm & pipy */ + npm_install_pipy(); + let mut config = Config::new("libs/ztm/pipy"); // set to use clang/clang++ to compile if not in windows From fe81cf848e35e5870f30c8a2b82a41a0274880d0 Mon Sep 17 00:00:00 2001 From: Hou Xiaoxuan Date: Mon, 15 Jul 2024 01:30:06 +0800 Subject: [PATCH 2/4] build: fix windows'a file path Signed-off-by: Hou Xiaoxuan --- neptune/build.rs | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/neptune/build.rs b/neptune/build.rs index af353a4cf..80f5795fb 100644 --- a/neptune/build.rs +++ b/neptune/build.rs @@ -1,5 +1,6 @@ use core::panic; use std::{ + env::current_dir, fs, path::{Path, PathBuf}, }; @@ -8,15 +9,14 @@ use cmake::Config; /// copy `mega-app/` to `libs/ztm/agent/apps/mega` fn copy_mega_apps() { - let src = Path::new("mega_app"); + let src = Path::new("mega"); let dst = Path::new("libs/ztm/agent/apps/mega"); - if src.exists() { - if dst.exists() { - fs::remove_dir_all(dst).expect("failed to remove origin agent/apps"); - } - // std::fs::copy(src, dst).expect("failed to copy mega to agent/apps"); - copy_dir_all(src, dst).expect("failed to copy mega to agent/apps"); + assert!(src.exists(), "neptune/mega not exists"); + if dst.exists() { + fs::remove_dir_all(dst).expect("failed to remove origin agent/apps"); } + // std::fs::copy(src, dst).expect("failed to copy mega to agent/apps"); + copy_dir_all(src, dst).expect("failed to copy mega to agent/apps"); } /// use npm to build agent ui in `libs/ztm/agent/gui` @@ -98,9 +98,9 @@ fn copy_lib_to_target(dst: &Path) { _source.join("libpipy.so") } else if cfg!(target_os = "windows") { if cfg!(debug_assertions) { - _source.join("pipyd.dll") + _source.join("Debug").join("pipyd.dll") } else { - _source.join("pipy.dll") + _source.join("Release").join("pipy.dll") } } else { panic!("unsupported target os"); @@ -109,10 +109,13 @@ fn copy_lib_to_target(dst: &Path) { // !hack, only work directory is `$workspace/neptune` let target = { + let mut _target = current_dir().unwrap(); + assert!(_target.ends_with("neptune")); + _target.pop(); let _target = if cfg!(debug_assertions) { - Path::new("../target/debug") + _target.join("target").join("debug") } else { - Path::new("../target/release") + _target.join("target").join("release") }; _target.join(source.file_name().unwrap()) }; @@ -197,4 +200,4 @@ fn copy_dir_all(src: impl AsRef, dst: impl AsRef) -> std::io::Result } } Ok(()) -} \ No newline at end of file +} From 5dbfeb200db525d9eb2a2e4b996502143d5490de Mon Sep 17 00:00:00 2001 From: Hou Xiaoxuan Date: Mon, 15 Jul 2024 02:39:32 +0800 Subject: [PATCH 3/4] build: use `msbuild` on windows Signed-off-by: Hou Xiaoxuan --- neptune/build.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/neptune/build.rs b/neptune/build.rs index 80f5795fb..4221ca29f 100644 --- a/neptune/build.rs +++ b/neptune/build.rs @@ -158,6 +158,11 @@ fn build() -> PathBuf { config.define("CMAKE_C_COMPILER", "clang"); config.define("CMAKE_CXX_COMPILER", "clang++"); } + #[cfg(target_os = "windows")] + { + // TODO: compile pass, but when run, it blocked when load the pipy.dll + config.generator("Visual Studio 17 2022"); + } // compile ztm in pipy config.define("PIPY_SHARED", "ON"); config.define("PIPY_GUI", "OFF"); @@ -167,8 +172,6 @@ fn build() -> PathBuf { "ztm/agent:../agent,ztm/hub:../hub,ztm/ca:../ca", ); - config.no_build_target(true); - // build, with half of the cpu let cups = num_cpus::get() - num_cpus::get() / 2; std::env::set_var("CMAKE_BUILD_PARALLEL_LEVEL", cups.to_string()); From fbd08fd93873e91ba480fa1f026bd4a6aa2573c1 Mon Sep 17 00:00:00 2001 From: Hou Xiaoxuan Date: Mon, 15 Jul 2024 03:21:22 +0800 Subject: [PATCH 4/4] fix windows running Signed-off-by: Hou Xiaoxuan --- neptune/build.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/neptune/build.rs b/neptune/build.rs index 4221ca29f..5a8da1351 100644 --- a/neptune/build.rs +++ b/neptune/build.rs @@ -160,8 +160,9 @@ fn build() -> PathBuf { } #[cfg(target_os = "windows")] { - // TODO: compile pass, but when run, it blocked when load the pipy.dll config.generator("Visual Studio 17 2022"); + config.define("CMAKE_MT", "CMAKE_MT-NOTFOUND"); // XXX enumerate possible parameters found + config.define("CMAKE_CXX_FLAGS", "/DWIN32 /D_WINDOWS /W3 /GR /EHsc"); // XXX enumerate possible parameters found } // compile ztm in pipy config.define("PIPY_SHARED", "ON");