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: resolve Windows compatibility issues in toolchain build pipeline

esengined1331c0e67ab
diff --git a/build-tools/toolchain/package.js b/build-tools/toolchain/package.js
index 7961aea7b..bbbf5935c 100644
--- a/build-tools/toolchain/package.js
+++ b/build-tools/toolchain/package.js
@@ -10,6 +10,7 @@
import fs from 'fs';
import path from 'path';
import os from 'os';
+import { createWriteStream } from 'fs';
import { mkdir, rm, cp, readdir, stat, chmod } from 'fs/promises';
import { execSync } from 'child_process';
@@ -39,6 +40,49 @@ function formatSize(bytes) {
return `${(bytes / 1024).toFixed(1)} KB`;
}
+async function downloadFile(url, dest) {
+ const https = await import('https');
+ const http = await import('http');
+ return new Promise((resolve, reject) => {
+ const request = (reqUrl, redirectCount = 0) => {
+ if (redirectCount > 10) { reject(new Error('Too many redirects')); return; }
+ const mod = reqUrl.startsWith('https') ? https : http;
+ mod.get(reqUrl, (res) => {
+ if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
+ const loc = res.headers.location;
+ const next = loc.startsWith('http') ? loc : new URL(loc, reqUrl).href;
+ request(next, redirectCount + 1);
+ return;
+ }
+ if (res.statusCode !== 200) {
+ reject(new Error(`Download failed: HTTP ${res.statusCode}`));
+ return;
+ }
+ const ws = createWriteStream(dest);
+ res.pipe(ws);
+ ws.on('finish', () => ws.close(resolve));
+ ws.on('error', reject);
+ }).on('error', reject);
+ };
+ request(url);
+ });
+}
+
+async function extractTarGz(archivePath, destDir) {
+ execSync(`tar xzf "${archivePath}" -C "${destDir}"`, { stdio: 'inherit' });
+}
+
+async function extractZip(archivePath, destDir) {
+ if (os.platform() === 'win32') {
+ execSync(
+ `powershell -NoProfile -Command "Expand-Archive -Path '${archivePath}' -DestinationPath '${destDir}' -Force"`,
+ { stdio: 'inherit' },
+ );
+ } else {
+ execSync(`unzip -q "${archivePath}" -d "${destDir}"`, { stdio: 'inherit' });
+ }
+}
+
function loadManifest() {
if (!fs.existsSync(MANIFEST_PATH)) {
throw new Error(`Manifest not found: ${MANIFEST_PATH}`);
@@ -161,7 +205,7 @@ async function packageCmake(manifest) {
const archivePath = path.join(tmpDir, filename);
try {
- execSync(`curl -sL -o "${archivePath}" "${url}"`, { stdio: 'inherit' });
+ await downloadFile(url, archivePath);
log('Extracting cmake...');
@@ -172,9 +216,9 @@ async function packageCmake(manifest) {
const isZip = filename.endsWith('.zip');
if (isZip) {
- execSync(`unzip -q "${archivePath}" -d "${tmpDir}"`, { stdio: 'inherit' });
+ await extractZip(archivePath, tmpDir);
} else {
- execSync(`tar xzf "${archivePath}" -C "${tmpDir}"`, { stdio: 'inherit' });
+ await extractTarGz(archivePath, tmpDir);
}
const extractedRoot = path.join(tmpDir, stripPrefix);
diff --git a/desktop/src-tauri/src/compiler.rs b/desktop/src-tauri/src/compiler.rs
index e8b6ea282..31bb0a596 100644
--- a/desktop/src-tauri/src/compiler.rs
+++ b/desktop/src-tauri/src/compiler.rs
@@ -594,7 +594,8 @@ pub async fn compile_wasm(
// Configure
emit_progress(&app, "configure", "Configuring CMake...", 0.1);
- let emcmake = emsdk_dir.join("upstream/emscripten/emcmake");
+ let emcmake_name = if cfg!(windows) { "emcmake.bat" } else { "emcmake" };
+ let emcmake = emsdk_dir.join("upstream/emscripten").join(emcmake_name);
let mut cmake_args = vec![cmake_str.clone()];
cmake_args.extend(build_cmake_flags(&options));
cmake_args.push(engine_src.to_string_lossy().to_string());