Skip to content

DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.

fix(build): 修复 macOS / Linux 构建因悬垂符号链接失败 (#290)

Mao Mr8dfc2e2fc11b
diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml
new file mode 100644
index 00000000..c3679424
--- /dev/null
+++ b/.github/workflows/build-test.yml
@@ -0,0 +1,160 @@
+name: Build Test (unsigned)
+
+on:
+ # 仅手动触发:用于快速验证「能否在当前平台产物上完成一次完整 tauri build」,
+ # 不发布、不打签名(TPM 签名密钥 / Apple 证书 / 公证强制可省),不写 GitHub Release。
+ # 触发后可在此 run 的 Actions 页面核对三平台的打包产物是否生成。
+ workflow_dispatch:
+ inputs:
+ platform:
+ description: 只想验证的平台(默认全部)
+ required: false
+ default: all
+ type: choice
+ options:
+ - all
+ - macos
+ - linux
+ - windows
+
+permissions:
+ contents: read
+
+# 同一分支的手动构建排队执行,避免并发挤占 runner。
+concurrency:
+ group: build-test-${{ github.ref }}
+ cancel-in-progress: true
+
+jobs:
+ # macOS 用 Apple Silicon runner(macos-latest)交叉编译 x64,
+ # 与 release 的可复用构建(build-macos.yml 的矩阵)保持一致。
+ macos:
+ name: Build (macos-${{ matrix.id }})
+ if: ${{ inputs.platform == 'all' || inputs.platform == 'macos' }}
+ strategy:
+ fail-fast: false
+ matrix:
+ include:
+ - id: aarch64
+ target: aarch64-apple-darwin
+ - id: x86_64
+ target: x86_64-apple-darwin
+ runs-on: macos-latest
+ timeout-minutes: 60
+ steps:
+ - name: Checkout repository
+ uses: actions/checkout@v7
+ with:
+ persist-credentials: false
+
+ - name: Setup Node.js and pnpm
+ uses: ./.github/actions/setup-node-pnpm
+
+ - name: Install Rust stable
+ uses: dtolnay/rust-toolchain@stable
+ with:
+ toolchain: stable
+ targets: ${{ matrix.target }}
+
+ - name: Install frontend dependencies
+ run: pnpm install --frozen-lockfile
+
+ # 不注入任何签名/公证 secrets,产出未签名(unsigned/no-notarized)bundle,
+ # 依然完整走一遍 beforeBuildCommand(build:plugins + 前端)+ cargo release 构建。
+ - name: Build package
+ run: pnpm tauri build --target ${{ matrix.target }}
+
+ - name: Upload build outputs
+ uses: actions/upload-artifact@v6
+ with:
+ name: build-test-macos-${{ matrix.id }}
+ path: src-tauri/target/${{ matrix.target }}/release/bundle/dmg/*.dmg
+ if-no-files-found: error
+ retention-days: 7
+
+ linux:
+ name: Build (linux)
+ if: ${{ inputs.platform == 'all' || inputs.platform == 'linux' }}
+ # 与 release 的可复用构建一致:22.04 的 glibc/WebKitGTK 产物兼容性最好。
+ runs-on: ubuntu-22.04
+ timeout-minutes: 60
+ steps:
+ - name: Checkout repository
+ uses: actions/checkout@v7
+ with:
+ persist-credentials: false
+
+ - name: Setup Node.js and pnpm
+ uses: ./.github/actions/setup-node-pnpm
+
+ - name: Install Rust stable
+ uses: dtolnay/rust-toolchain@stable
+ with:
+ toolchain: stable
+
+ - name: Install system dependencies
+ shell: bash
+ run: |
+ sudo apt-get update
+ sudo apt-get install -y libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf
+
+ - name: Install frontend dependencies
+ run: pnpm install --frozen-lockfile
+
+ - name: Build packages
+ run: pnpm tauri build --bundles appimage
+
+ - name: Upload build outputs
+ uses: actions/upload-artifact@v6
+ with:
+ name: build-test-linux
+ path: src-tauri/target/release/bundle/appimage/*.AppImage
+ if-no-files-found: error
+ retention-days: 7
+
+ windows:
+ name: Build (windows)
+ if: ${{ inputs.platform == 'all' || inputs.platform == 'windows' }}
+ runs-on: windows-latest
+ timeout-minutes: 60
+ steps:
+ - name: Checkout repository
+ uses: actions/checkout@v7
+ with:
+ persist-credentials: false
+
+ - name: Setup Node.js and pnpm
+ uses: ./.github/actions/setup-node-pnpm
+
+ - name: Install Rust stable
+ uses: dtolnay/rust-toolchain@stable
+ with:
+ toolchain: stable
+
+ - name: Install frontend dependencies
+ run: pnpm install --frozen-lockfile
+
+ # WiX 只接受纯数字版本;NSIS 仍使用完整 SemVer。
+ - name: Prepare MSI version override
+ shell: bash
+ run: |
+ node -e "
+ const fs = require('fs');
+ const rawVer = require('./src-tauri/tauri.conf.json').version;
+ const cleanVer = rawVer.replace(/[-+].*\$/, '');
+ fs.writeFileSync('release-msi-version.tmp.json', JSON.stringify({ bundle: { windows: { wix: { version: cleanVer } } } }));
+ console.log('MSI version override ->', cleanVer);
+ "
+
+ - name: Build packages
+ run: pnpm tauri build --config release-msi-version.tmp.json
+
+ - name: Upload build outputs
+ uses: actions/upload-artifact@v6
+ with:
+ name: build-test-windows
+ path: |
+ src-tauri/target/release/bundle/nsis/*.exe
+ src-tauri/target/release/bundle/msi/*.msi
+ if-no-files-found: error
+ retention-days: 7
diff --git a/scripts/build-plugins.ts b/scripts/build-plugins.ts
index b59050fa..60fb9801 100644
--- a/scripts/build-plugins.ts
+++ b/scripts/build-plugins.ts
@@ -1,5 +1,5 @@
import { spawnSync } from 'node:child_process'
-import { cpSync, existsSync, readFileSync, rmSync } from 'node:fs'
+import { copyFileSync, existsSync, mkdirSync, readdirSync, readFileSync, realpathSync, rmSync, statSync } from 'node:fs'
import { join, resolve } from 'node:path'
import process from 'node:process'
@@ -58,6 +58,55 @@ function verifyDeployedPackages(names: readonly string[], nodeModulesRoot: strin
}
}
+/**
+ * 把 `pnpm deploy` 产物解引用复制到目标目录:pnpm 虚拟仓库(`.pnpm` 下的依赖入口)
+ * 全是符号链接,必须逐条按「链接目标」的真实类型落成实体目录/文件。
+ *
+ * 为什么不用 `fs.cpSync(..., { dereference: true })`:Node 22.17 起该选项失效
+ * (regression nodejs/node#59168),符号链接会被原样重建成指向**源目录**的绝对链接。
+ * 本脚本的源目录是随后即删的临时目录 `.build-plugins-tmp`,于是产物里留下一堆悬垂
+ * 链接;`tauri build` 展开 `bundle.resources` 通配时逐条登记资源,命中悬垂链接即以
+ * `resource path ... doesn't exist` 失败(macOS / Linux 复现;Windows 因链接形态不同
+ * 未触发,故只挂了两个平台)。
+ *
+ * `chain` 为当前递归路径上已展开目录的 realpath 集合,用于挡住链接成环的无限递归。
+ */
+function materializeTree(source: string, target: string, chain: ReadonlySet<string> = new Set()): void {
+ const sourceReal = realpathSync(source)
+ if (chain.has(sourceReal)) {
+ throw new Error(`PLUGIN_DEPLOY_SYMLINK_CYCLE: ${source} -> ${sourceReal}`)
+ }
+ const nested = new Set(chain).add(sourceReal)
+ mkdirSync(target, { recursive: true })
+ for (const entry of readdirSync(source, { withFileTypes: true })) {
+ const from = join(source, entry.name)
+ const to = join(target, entry.name)
+ // statSync 跟随符号链接:按链接目标的类型决定复制方式,源里是不是链接无关紧要。
+ const stats = statSync(from)
+ if (stats.isDirectory()) {
+ materializeTree(from, to, nested)
+ continue
+ }
+ if (!stats.isFile()) {
+ throw new Error(`PLUGIN_DEPLOY_UNSUPPORTED_ENTRY: ${from}`)
+ }
+ // copyFileSync 读取链接目标的内容,并保留源文件权限位(可执行脚本仍可执行)。
+ copyFileSync(from, to)
+ }
+}
+
+/**
+ * 校验产物中不再残留任何符号链接。Tauri 打包会把资源通配展开成逐条路径,悬垂链接
+ * 要到 cargo 构建脚本阶段才报错,离根因很远;宁可在这里带 `PLUGIN_DEPLOY_` 前缀早失败。
+ */
+function verifyMaterialized(root: string): void {
+ for (const entry of readdirSync(root, { withFileTypes: true, recursive: true })) {
+ if (entry.isSymbolicLink()) {
+ throw new Error(`PLUGIN_DEPLOY_SYMLINK_LEFTOVER: ${join(entry.parentPath, entry.name)}`)
+ }
+ }
+}
+
function main(): void {
const names = bundledPackageNames()
// 先生成最新 dist,再打包 production 闭包。部署到独立临时目录并校验通过后,
@@ -98,7 +147,8 @@ function main(): void {
if (!existsSync(deployed)) {
throw new Error(`PLUGIN_DEPLOY_EMPTY: pnpm deploy did not produce node_modules at ${deployed}`)
}
- cpSync(deployed, DEPLOYED_NODE_MODULES, { recursive: true, dereference: true })
+ materializeTree(deployed, DEPLOYED_NODE_MODULES)
+ verifyMaterialized(DEPLOYED_NODE_MODULES)
verifyDeployedPackages(names, DEPLOYED_NODE_MODULES)
console.log(`[build:plugins] deployed ${names.length} plugins to ${RESOURCE_ROOT}`)
}