mirror of
https://gitcode.com/JianFeeeee/ModelRouter.git
synced 2026-11-07 09:47:23 +00:00
改名在桌面打包链上漏了两处,都是"构建能过、产物不可用"的类型: 1. `dist-win-docker.sh` 仍交叉编译到 `bin/llmsproxy.exe` 并构建 `./cmd/llmsproxy`,而 package.json 的 extraResources 已指向 `bin/modelrouter.exe` —— Windows 包装完会缺内嵌核心。 同时把 npmmirror 的 electron / electron-builder-binaries 镜像传进容器: 首次构建需在容器内下载数百 MB,直连会卡满 600s 请求超时(Linux 侧已实测)。 2. `prepare-core.js` 只带 `-trimpath`,内嵌核心保留调试符号(14.4MB)。 补 `-ldflags "-s -w"`,与 `packaging/core-dist.sh` 一致,各平台安装包少约 4MB。
78 lines
2.6 KiB
JavaScript
78 lines
2.6 KiB
JavaScript
#!/usr/bin/env node
|
|
// Build the embedded modelrouter core(s) for the GUI package.
|
|
// node prepare-core.js -> linux (native, luajit) + win (cross, best effort)
|
|
// node prepare-core.js linux -> linux only
|
|
// node prepare-core.js win -> win only
|
|
const { execFileSync } = require("child_process");
|
|
const fs = require("fs");
|
|
const path = require("path");
|
|
|
|
const guiDir = __dirname.replace(/scripts$/, "");
|
|
const binDir = path.join(guiDir, "bin");
|
|
const projectRoot = path.join(guiDir, "..", "..");
|
|
|
|
function buildLinux() {
|
|
const out = path.join(binDir, "modelrouter");
|
|
console.log("[prepare-core] building modelrouter (linux/luajit)...");
|
|
fs.mkdirSync(binDir, { recursive: true });
|
|
execFileSync(
|
|
"go",
|
|
// -s -w: same stripping as packaging/core-dist.sh. Without it the bundled
|
|
// core carries debug info (~14.4 MB vs ~10.3 MB) and every installer pays
|
|
// for it, for a binary the user never debugs.
|
|
["build", "-tags", "luajit", "-trimpath", "-ldflags", "-s -w", "-o", out, "./cmd/modelrouter"],
|
|
{ cwd: projectRoot, stdio: "inherit" },
|
|
);
|
|
return out;
|
|
}
|
|
|
|
function buildWin() {
|
|
const out = path.join(binDir, "modelrouter.exe");
|
|
console.log(
|
|
"[prepare-core] cross-building modelrouter.exe (windows/amd64, luajit)...",
|
|
);
|
|
fs.mkdirSync(binDir, { recursive: true });
|
|
const cc = process.env.MINGW_CC || "x86_64-w64-mingw32-gcc";
|
|
// friendly hint when the mingw cross-compiler is missing
|
|
try {
|
|
execFileSync(cc + " --version", { shell: true, stdio: "ignore" });
|
|
} catch (e) {
|
|
console.error(
|
|
"[prepare-core] MISSING mingw-w64 cross-compiler (" + cc + ").",
|
|
);
|
|
console.error(" Install it: sudo apt install gcc-mingw-w64-x86-64");
|
|
console.error(" Then re-run: npm run core:win (or make gui-win)");
|
|
process.exit(1);
|
|
}
|
|
execFileSync(
|
|
"go",
|
|
["build", "-tags", "luajit", "-trimpath", "-ldflags", "-s -w", "-o", out, "./cmd/modelrouter"],
|
|
{
|
|
cwd: projectRoot,
|
|
stdio: "inherit",
|
|
env: Object.assign({}, process.env, {
|
|
GOOS: "windows",
|
|
GOARCH: "amd64",
|
|
CGO_ENABLED: "1",
|
|
CC: cc,
|
|
}),
|
|
},
|
|
);
|
|
return out;
|
|
}
|
|
|
|
const which = process.argv[2] || "both";
|
|
const results = [];
|
|
try {
|
|
if (which === "linux" || which === "both") results.push(buildLinux());
|
|
} catch (e) {
|
|
console.error("[prepare-core] linux build failed:", e.message);
|
|
}
|
|
try {
|
|
if (which === "win" || which === "both") results.push(buildWin());
|
|
} catch (e) {
|
|
console.error("[prepare-core] win build failed:", e.message);
|
|
}
|
|
if (results.length === 0) process.exit(1);
|
|
results.forEach((p) => console.log("[prepare-core] core ready: " + p));
|