Skip to content

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

fix(ci): select supported Xcode for macOS packaging (#827)

Mao Mr862a86450291
diff --git a/.github/actions/setup-xcode/action.yml b/.github/actions/setup-xcode/action.yml
new file mode 100644
index 00000000..54c1804e
--- /dev/null
+++ b/.github/actions/setup-xcode/action.yml
@@ -0,0 +1,24 @@
+name: Setup Xcode
+# 通知插件需要 Swift 6,而 macos-latest 已移除 Xcode 16;按能力选择稳定工具链。
+description: Select the latest stable Xcode with Swift 6 and configure its runtime libraries
+
+runs:
+ using: composite
+ steps:
+ - name: Select latest stable Xcode
+ uses: maxim-lobanov/setup-xcode@ed7a3b1fda3918c0306d1b724322adc0b8cc0a90
+ with:
+ xcode-version: latest-stable
+
+ - name: Verify Swift toolchain
+ shell: bash
+ run: |
+ set -euo pipefail
+ swift_version="$(xcrun swift --version)"
+ echo "$swift_version"
+ if [[ ! "$swift_version" =~ Swift\ version\ ([0-9]+)\. ]] || (( BASH_REMATCH[1] < 6 )); then
+ echo "::error::The notification plugin requires Swift 6 or newer"
+ exit 1
+ fi
+ developer_dir="$(xcode-select -p)"
+ echo "DYLD_FALLBACK_LIBRARY_PATH=$developer_dir/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx:/usr/lib/swift" >> "$GITHUB_ENV"
diff --git a/.github/workflows/build-bundle-macos.yml b/.github/workflows/build-bundle-macos.yml
index af5ab5a1..91edc7fb 100644
--- a/.github/workflows/build-bundle-macos.yml
+++ b/.github/workflows/build-bundle-macos.yml
@@ -68,13 +68,9 @@ jobs:
ref: ${{ inputs.source_ref }}
persist-credentials: false
- # tauri-plugin-notifications 的 macOS 后端需要 Swift 6(typed throws),切到 Xcode 16。
- - name: Select Xcode 16
+ - name: Setup Xcode
if: steps.check.outputs.should_run == 'true'
- run: |
- XCODE_APP="$(ls -d /Applications/Xcode_16*.app | sort -V | tail -1)"
- sudo xcode-select -s "$XCODE_APP"
- swift --version
+ uses: $/.github/actions/setup-xcode
- name: Setup Node.js and pnpm
if: steps.check.outputs.should_run == 'true'
diff --git a/.github/workflows/build-macos.yml b/.github/workflows/build-macos.yml
index d79f7855..e6571046 100644
--- a/.github/workflows/build-macos.yml
+++ b/.github/workflows/build-macos.yml
@@ -63,18 +63,9 @@ jobs:
ref: ${{ inputs.source_ref }}
persist-credentials: false
- # tauri-plugin-notifications 的 macOS 后端需要 Swift 6(typed throws),切到 Xcode 16。
- # 镜像里没有 Xcode 16 时不能让整个 job 挂掉:`xcode-select -s ""` 会直接失败。
- - name: Select Xcode 16
+ - name: Setup Xcode
if: steps.check.outputs.should_run == 'true'
- run: |
- XCODE_APP="$(ls -d /Applications/Xcode_16*.app 2>/dev/null | sort -V | tail -1)"
- if [ -n "$XCODE_APP" ]; then
- sudo xcode-select -s "$XCODE_APP"
- else
- echo "::warning::镜像里没有 Xcode 16,沿用默认 Xcode;Swift 6 构建可能失败"
- fi
- swift --version
+ uses: $/.github/actions/setup-xcode
- name: Setup Node.js and pnpm
if: steps.check.outputs.should_run == 'true'
diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml
index cf732531..ecbf9931 100644
--- a/.github/workflows/build-test.yml
+++ b/.github/workflows/build-test.yml
@@ -47,17 +47,8 @@ jobs:
with:
persist-credentials: false
- # tauri-plugin-notifications 的 macOS 后端需要 Swift 6(typed throws),切到 Xcode 16。
- # 镜像里没有 Xcode 16 时不能让整个 job 挂掉:`xcode-select -s ""` 会直接失败。
- - name: Select Xcode 16
- run: |
- XCODE_APP="$(ls -d /Applications/Xcode_16*.app 2>/dev/null | sort -V | tail -1)"
- if [ -n "$XCODE_APP" ]; then
- sudo xcode-select -s "$XCODE_APP"
- else
- echo "::warning::镜像里没有 Xcode 16,沿用默认 Xcode;Swift 6 构建可能失败"
- fi
- swift --version
+ - name: Setup Xcode
+ uses: ./.github/actions/setup-xcode
- name: Setup Node.js and pnpm
uses: ./.github/actions/setup-node-pnpm
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 743bc40c..a3257e59 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -233,25 +233,9 @@ jobs:
with:
toolchain: stable
- # tauri-plugin-notifications 的 macOS 后端用 Swift 6 的 typed throws
- # (`throws(FFIResult)`),macos-14 镜像默认的 Xcode 15 / Swift 5.10 解析不了,
- # 构建前必须切到镜像里自带的 Xcode 16;镜像里没有 Xcode 16 时只告警,不让 job 直接挂掉
- # (`xcode-select -s ""` 会失败)。
- - name: Select Xcode 16
+ - name: Setup Xcode
if: runner.os == 'macOS'
- run: |
- XCODE_APP="$(ls -d /Applications/Xcode_16*.app 2>/dev/null | sort -V | tail -1)"
- if [ -z "$XCODE_APP" ]; then
- echo "::warning::镜像里没有 Xcode 16,沿用默认 Xcode;Swift 6 构建可能失败"
- swift --version
- exit 0
- fi
- sudo xcode-select -s "$XCODE_APP"
- swift --version
- # 该插件的 macOS 后端经 swift-build 产出 dylib,测试二进制运行时按 @rpath 找 Swift 并发
- # 运行库;dyld 默认只搜 target/、$HOME/lib、/usr/local/lib、/usr/lib,工具链里的
- # libswift_Concurrency.dylib 不在其中,实测报 `Library not loaded: @rpath/libswift_Concurrency.dylib`。
- echo "DYLD_FALLBACK_LIBRARY_PATH=$XCODE_APP/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx:/usr/lib/swift" >> "$GITHUB_ENV"
+ uses: ./.github/actions/setup-xcode
- name: Cache Rust build
uses: Swatinem/rust-cache@v2
diff --git a/test/macos-build-toolchain.test.ts b/test/macos-build-toolchain.test.ts
new file mode 100644
index 00000000..708bf430
--- /dev/null
+++ b/test/macos-build-toolchain.test.ts
@@ -0,0 +1,74 @@
+import { spawnSync } from 'node:child_process'
+import { mkdirSync, mkdtempSync, readFileSync, rmSync } from 'node:fs'
+import { join, resolve } from 'node:path'
+import { fileURLToPath } from 'node:url'
+import { describe, expect, it } from 'vitest'
+import { readSource } from './setup/read-source'
+
+const WORKFLOWS = [
+ ['.github/workflows/build-bundle-macos.yml', 'steps.check.outputs.should_run == \'true\'', '$/.github/actions/setup-xcode'],
+ ['.github/workflows/build-macos.yml', 'steps.check.outputs.should_run == \'true\'', '$/.github/actions/setup-xcode'],
+ ['.github/workflows/build-test.yml', undefined, './.github/actions/setup-xcode'],
+ ['.github/workflows/ci.yml', 'runner.os == \'macOS\'', './.github/actions/setup-xcode'],
+] as const
+
+const ACTION = readSource('.github/actions/setup-xcode/action.yml')
+const verification = ACTION.split(' run: |\n')[1]?.replace(/^ {8}/gm, '')
+const scratchRoot = fileURLToPath(new URL('../.temp/', import.meta.url))
+
+function verifyToolchain(version: string, developerExit = 0): { status: number | null, exported: string } {
+ mkdirSync(scratchRoot, { recursive: true })
+ const root = mkdtempSync(join(scratchRoot, 'xcode-test-'))
+ const envFile = join(root, 'env')
+ try {
+ const result = spawnSync('bash', ['-c', `
+ xcrun() { printf '%s\\n' "$TEST_SWIFT_VERSION"; }
+ xcode-select() { printf '%s\\n' '/Applications/Xcode_26.0.app/Contents/Developer'; return "$TEST_DEVELOPER_EXIT"; }
+ ${verification}
+ `], {
+ stdio: 'ignore',
+ timeout: 10000,
+ env: { ...process.env, TEST_SWIFT_VERSION: version, TEST_DEVELOPER_EXIT: String(developerExit), GITHUB_ENV: envFile.replace(/\\/g, '/') },
+ })
+ expect(result.error).toBeUndefined()
+ return { status: result.status, exported: result.status === 0 ? readFileSync(envFile, 'utf8') : '' }
+ }
+ finally {
+ expect(resolve(root).startsWith(resolve(scratchRoot) + (process.platform === 'win32' ? '\\' : '/'))).toBe(true)
+ rmSync(root, { recursive: true, force: true })
+ }
+}
+
+describe('macOS packaging toolchain selection', () => {
+ it('selects a stable Xcode without constraining its major version', () => {
+ expect(ACTION).toContain('uses: maxim-lobanov/setup-xcode@ed7a3b1fda3918c0306d1b724322adc0b8cc0a90')
+ expect(ACTION).toContain('xcode-version: latest-stable')
+ expect(verification).toBeTypeOf('string')
+ })
+
+ it.each(['Apple Swift version 6.0 (swiftlang-6.0)', 'Apple Swift version 6.2.3 (swiftlang-6.2.3)', 'Swift version 7.0-dev'])('accepts %s and exports the selected toolchain runtime', (version) => {
+ expect(verifyToolchain(version)).toEqual({
+ status: 0,
+ exported: 'DYLD_FALLBACK_LIBRARY_PATH=/Applications/Xcode_26.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx:/usr/lib/swift\n',
+ })
+ })
+
+ it.each(['Apple Swift version 5.10', 'unexpected compiler output', ''])('rejects unsupported or unrecognized Swift output: %s', (version) => {
+ expect(verifyToolchain(version)).toEqual({ status: 1, exported: '' })
+ })
+
+ it('fails when the selected developer directory cannot be read', () => {
+ expect(verifyToolchain('Apple Swift version 6.2', 2)).toEqual({ status: 2, exported: '' })
+ })
+
+ it.each(WORKFLOWS)('%s selects the shared toolchain from the correct commit with its original platform gate', (path, condition, action) => {
+ const source = readSource(path)
+ const step = source.match(/ {6}- name: Setup Xcode\n([\s\S]*?)(?=\n {6}- |$)/)?.[1]
+ expect(step, path).toBeTypeOf('string')
+ expect(step, path).toContain(`uses: ${action}`)
+ if (condition)
+ expect(step, path).toContain(`if: ${condition}`)
+ expect(source, path).not.toContain('/Applications/Xcode_16')
+ expect(source, path).not.toContain('xcode-select -s')
+ })
+})