(project_path: &Path, build_debug: bool)
| 32 | } |
| 33 | |
| 34 | pub(crate) fn build_cpp(project_path: &Path, build_debug: bool) -> anyhow::Result<PathBuf> { |
| 35 | // Verify required tools are in PATH |
| 36 | #[cfg(windows)] |
| 37 | let emcc_found = find_executable("emcc.bat").is_some(); |
| 38 | #[cfg(not(windows))] |
| 39 | let emcc_found = find_executable("emcc").is_some(); |
| 40 | |
| 41 | if !emcc_found { |
| 42 | return Err(anyhow!("`emcc` not found in PATH. Activate Emscripten (emsdk_env).")); |
| 43 | } |
| 44 | |
| 45 | #[cfg(windows)] |
| 46 | let cmake_found = find_executable("cmake.exe").is_some(); |
| 47 | #[cfg(not(windows))] |
| 48 | let cmake_found = find_executable("cmake").is_some(); |
| 49 | |
| 50 | if !cmake_found { |
| 51 | return Err(anyhow!("`cmake` not found in PATH.")); |
| 52 | } |
| 53 | |
| 54 | #[cfg(windows)] |
| 55 | let emcmake_found = find_executable("emcmake.bat").is_some(); |
| 56 | #[cfg(not(windows))] |
| 57 | let emcmake_found = find_executable("emcmake").is_some(); |
| 58 | |
| 59 | if !emcmake_found { |
| 60 | return Err(anyhow!("`emcmake` not found in PATH. Is Emscripten env active?")); |
| 61 | } |
| 62 | |
| 63 | let build_type = if build_debug { "Debug" } else { "Release" }; |
| 64 | let build_dir = project_path.join("build"); |
| 65 | |
| 66 | // === Configure (no generator flags; let emcmake/cmake decide or reuse existing) === |
| 67 | // This matches: emcmake cmake -B build . |
| 68 | // We keep -S/-B so `project_path` can be anywhere, and pass CMAKE_BUILD_TYPE (ignored by multi-config). |
| 69 | let cfg_args = [ |
| 70 | "cmake", |
| 71 | "-S", |
| 72 | ".", |
| 73 | "-B", |
| 74 | "build", |
| 75 | &format!("-DCMAKE_BUILD_TYPE={}", build_type), |
| 76 | ]; |
| 77 | run_command("emcmake", &cfg_args, project_path).context("Failed to configure C++ project with emcmake/cmake")?; |
| 78 | |
| 79 | // === Build (matches: cmake --build build) === |
| 80 | // Always pass --config; it's required for multi-config and ignored for single-config. |
| 81 | let build_args = ["--build", "build", "--config", build_type, "--parallel"]; |
| 82 | run_command("cmake", &build_args, project_path).context("Failed to build C++ project")?; |
| 83 | |
| 84 | // Find the most recently modified .wasm under build/ directory |
| 85 | // This ensures we get the latest build output when rebuilding, instead of potentially |
| 86 | // picking up an older cached wasm file from a previous build |
| 87 | let wasm = WalkDir::new(&build_dir) |
| 88 | .into_iter() |
| 89 | .filter_map(Result::ok) |
| 90 | .filter_map(|e| { |
| 91 | let p = e.path(); |
no test coverage detected
searching dependent graphs…