Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

fix: generate .emscripten config after emsdk install and check cache file existence

esengineb597cd3003ac
diff --git a/desktop/src-tauri/src/compiler.rs b/desktop/src-tauri/src/compiler.rs
index 8a4288f41..9957ce346 100644
--- a/desktop/src-tauri/src/compiler.rs
+++ b/desktop/src-tauri/src/compiler.rs
@@ -520,6 +520,10 @@ pub async fn install_emsdk(app: AppHandle) -> Result<ToolchainStatus, String> {
.await
.map_err(|e| format!("Extract task failed: {}", e))??;
+ // Generate .emscripten config
+ emit_progress(&app, "configure", "Configuring emscripten...", 0.9);
+ generate_emscripten_config(&install_dir)?;
+
emit_progress(&app, "complete", "Toolchain installed!", 1.0);
// Save path
@@ -565,6 +569,52 @@ async fn download_with_progress(app: &AppHandle, url: &str) -> Result<Vec<u8>, S
Ok(data)
}
+fn generate_emscripten_config(emsdk_dir: &Path) -> Result<(), String> {
+ let upstream = emsdk_dir.join("upstream");
+ let emscripten = upstream.join("emscripten");
+ let node_dir = emsdk_dir.join("node");
+
+ let node_bin = if cfg!(windows) {
+ find_first_subdir(&node_dir)
+ .map(|d| d.join("bin").join("node.exe"))
+ .unwrap_or_else(|| node_dir.join("bin").join("node.exe"))
+ } else {
+ find_first_subdir(&node_dir)
+ .map(|d| d.join("bin").join("node"))
+ .unwrap_or_else(|| node_dir.join("bin").join("node"))
+ };
+
+ let to_python_path = |p: &Path| -> String {
+ let s = p.to_string_lossy().replace('\\', "/");
+ format!("'{}'", s)
+ };
+
+ let config = format!(
+ "import os\nEMSCRIPTEN_ROOT = {}\nLLVM_ROOT = {}\nBINARYEN_ROOT = {}\nNODE_JS = {}\n",
+ to_python_path(&emscripten),
+ to_python_path(&upstream.join("bin")),
+ to_python_path(&upstream),
+ to_python_path(&node_bin),
+ );
+
+ let config_path = emsdk_dir.join(".emscripten");
+ std::fs::write(&config_path, config)
+ .map_err(|e| format!("Failed to write .emscripten config: {}", e))?;
+
+ Ok(())
+}
+
+fn find_first_subdir(dir: &Path) -> Option<std::path::PathBuf> {
+ if !dir.exists() {
+ return None;
+ }
+ std::fs::read_dir(dir)
+ .ok()?
+ .filter_map(|e| e.ok())
+ .find(|e| e.file_type().map(|t| t.is_dir()).unwrap_or(false))
+ .map(|e| e.path())
+}
+
fn extract_zip(data: &[u8], target: &Path) -> Result<(), String> {
let cursor = std::io::Cursor::new(data);
let mut archive = zip::ZipArchive::new(cursor).map_err(|e| format!("Invalid zip: {}", e))?;
diff --git a/editor/src/builder/BuildCache.ts b/editor/src/builder/BuildCache.ts
index 27315a7af..44466b947 100644
--- a/editor/src/builder/BuildCache.ts
+++ b/editor/src/builder/BuildCache.ts
@@ -147,6 +147,9 @@ export class BuildCache {
const cachePath = this.getCachePath(configId);
try {
+ const exists = await this.fs_.exists(cachePath);
+ if (!exists) return null;
+
const content = await this.fs_.readFile(cachePath);
if (!content) return null;