Skip to content

Commit 5e37f21

Browse files
committed
fix: hide console windows and strip UNC prefix on Windows builds
- Add CREATE_NO_WINDOW flag to all subprocess spawns (emcc, cmake, python version checks and WASM compilation) to prevent black console windows flashing on Windows - Strip \?\ extended-length path prefix from Tauri resource_dir() before passing to CMake, fixing file(GLOB_RECURSE) failures that caused "No SOURCES given to target" for spine-cpp and yogacore
1 parent d6d35da commit 5e37f21

1 file changed

Lines changed: 32 additions & 8 deletions

File tree

desktop/src-tauri/src/compiler.rs

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ use tauri::{AppHandle, Emitter, Manager};
88
use tokio::io::{AsyncBufReadExt, BufReader};
99
use tokio::process::Command;
1010

11+
#[cfg(windows)]
12+
use std::os::windows::process::CommandExt;
13+
14+
#[cfg(windows)]
15+
const CREATE_NO_WINDOW: u32 = 0x08000000;
16+
1117
// =============================================================================
1218
// Types
1319
// =============================================================================
@@ -197,7 +203,7 @@ fn validate_emsdk(emsdk_path: &Path) -> bool {
197203

198204
fn get_emcc_version(emsdk_path: &Path) -> Option<String> {
199205
let emcc = find_emcc_in_emsdk(emsdk_path)?;
200-
let output = std::process::Command::new(&emcc)
206+
let output = silent_command(&emcc)
201207
.arg("--version")
202208
.env("EMSDK", emsdk_path)
203209
.env(
@@ -222,7 +228,7 @@ fn find_bundled_cmake(app: &AppHandle) -> Option<PathBuf> {
222228

223229
// Bundled in resources
224230
if let Ok(resource_dir) = app.path().resource_dir() {
225-
let bundled = resource_dir.join("toolchain/cmake/bin").join(cmake_name);
231+
let bundled = strip_unc_prefix(resource_dir.join("toolchain/cmake/bin").join(cmake_name));
226232
if bundled.exists() {
227233
return Some(bundled);
228234
}
@@ -242,7 +248,7 @@ fn find_bundled_cmake(app: &AppHandle) -> Option<PathBuf> {
242248
fn find_cmake(app: &AppHandle) -> Option<(PathBuf, String)> {
243249
// Prefer bundled cmake
244250
if let Some(bundled) = find_bundled_cmake(app) {
245-
let output = std::process::Command::new(&bundled)
251+
let output = silent_command(&bundled)
246252
.arg("--version")
247253
.output()
248254
.ok()?;
@@ -253,7 +259,7 @@ fn find_cmake(app: &AppHandle) -> Option<(PathBuf, String)> {
253259

254260
// Fall back to system cmake
255261
let cmake = if cfg!(windows) { "cmake.exe" } else { "cmake" };
256-
let output = std::process::Command::new(cmake)
262+
let output = silent_command(cmake)
257263
.arg("--version")
258264
.output()
259265
.ok()?;
@@ -271,7 +277,7 @@ fn find_cmake(app: &AppHandle) -> Option<(PathBuf, String)> {
271277

272278
fn find_python() -> Option<(PathBuf, String)> {
273279
for bin in &["python3", "python"] {
274-
let output = std::process::Command::new(bin)
280+
let output = silent_command(bin)
275281
.arg("--version")
276282
.output()
277283
.ok();
@@ -309,7 +315,7 @@ fn find_emsdk_python(emsdk_path: &Path) -> Option<(PathBuf, String)> {
309315
entry.path().join("bin").join("python3")
310316
};
311317
if python_bin.exists() {
312-
let output = std::process::Command::new(&python_bin)
318+
let output = silent_command(&python_bin)
313319
.arg("--version")
314320
.output()
315321
.ok()?;
@@ -327,7 +333,7 @@ fn find_emsdk_python(emsdk_path: &Path) -> Option<(PathBuf, String)> {
327333

328334
fn which_sync(bin: &str) -> Option<PathBuf> {
329335
let cmd = if cfg!(windows) { "where" } else { "which" };
330-
let output = std::process::Command::new(cmd)
336+
let output = silent_command(cmd)
331337
.arg(bin)
332338
.output()
333339
.ok()?;
@@ -340,14 +346,30 @@ fn which_sync(bin: &str) -> Option<PathBuf> {
340346
}
341347
}
342348

349+
fn silent_command(program: &(impl AsRef<std::ffi::OsStr> + ?Sized)) -> std::process::Command {
350+
let mut cmd = std::process::Command::new(program);
351+
#[cfg(windows)]
352+
cmd.creation_flags(CREATE_NO_WINDOW);
353+
cmd
354+
}
355+
356+
fn strip_unc_prefix(p: PathBuf) -> PathBuf {
357+
let s = p.to_string_lossy();
358+
if s.starts_with(r"\\?\") {
359+
PathBuf::from(&s[4..])
360+
} else {
361+
p
362+
}
363+
}
364+
343365
fn resolve_engine_src(app: &AppHandle) -> Result<PathBuf, String> {
344366
// Bundled engine source in resources (release builds)
345367
let resource_dir = app
346368
.path()
347369
.resource_dir()
348370
.map_err(|e| format!("Failed to resolve resource dir: {}", e))?;
349371

350-
let engine_src = resource_dir.join("toolchain/engine-src");
372+
let engine_src = strip_unc_prefix(resource_dir.join("toolchain/engine-src"));
351373
if engine_src.exists() {
352374
return Ok(engine_src);
353375
}
@@ -1222,6 +1244,8 @@ async fn run_command_streamed(
12221244
let (program, full_args) = build_command_for_platform(cmd, args);
12231245
let mut command = Command::new(&program);
12241246
command.args(&full_args);
1247+
#[cfg(windows)]
1248+
command.creation_flags(CREATE_NO_WINDOW);
12251249
command
12261250
.current_dir(cwd)
12271251
.envs(env)

0 commit comments

Comments
 (0)