perf(macos): 保留 MLX 原生构建缓存

This commit is contained in:
sim committed 2026-09-25 14:05:26 +08:00
1 parent b268dcf978
commit f89b767fbe
4 files changed
+61

No files matched your search

@@ -0,0 +1,42 @@
name: Cache macOS MLX native build
description: Preserve vendored MLX CMake output before rust-cache removes in-tree path dependencies.
inputs:
profile:
description: Cargo output profile directory (debug or release)
required: true
runs:
using: composite
steps:
- name: Fingerprint MLX native toolchain
id: native
shell: bash
working-directory: openless-all/app
env:
OPENLESS_MLX_PROFILE: ${{ inputs.profile }}
run: |
set -euo pipefail
case "$OPENLESS_MLX_PROFILE" in
debug|release) ;;
*) echo "::error::Unsupported MLX cache profile"; exit 1 ;;
esac
fingerprint=$({
rustc -vV
xcrun clang --version
xcrun --sdk macosx --show-sdk-version
cmake --version
git -C src-tauri/vendor/qwen3-asr-rs rev-parse HEAD
git -C src-tauri/vendor/qwen3-asr-rs/mlx-c rev-parse HEAD
for name in CARGO_PROFILE_DEV_DEBUG CARGO_PROFILE_TEST_DEBUG CARGO_PROFILE_RELEASE_CODEGEN_UNITS CARGO_PROFILE_RELEASE_STRIP RUSTFLAGS CARGO_ENCODED_RUSTFLAGS CC CXX CFLAGS CXXFLAGS SDKROOT DEVELOPER_DIR MACOSX_DEPLOYMENT_TARGET CMAKE_GENERATOR CMAKE_TOOLCHAIN_FILE; do
printf '%s=%s\n' "$name" "${!name-}"
done
} | shasum -a 256 | awk '{print $1}')
echo "fingerprint=$fingerprint" >> "$GITHUB_OUTPUT"
# Call this action AFTER rust-cache: post actions run in reverse order,
# so MLX is saved before rust-cache prunes src-tauri/vendor path packages.
# Cache only CMake output, not Cargo fingerprints: Cargo still reruns the
# build script and CMake validates its native inputs on every clean checkout.
- uses: actions/cache@v4
with:
path: openless-all/app/src-tauri/target/${{ inputs.profile }}/build/qwen3-asr-rs-*/out
key: macos-mlx-v1-${{ runner.arch }}-${{ inputs.profile }}-${{ steps.native.outputs.fingerprint }}-${{ hashFiles('openless-all/app/src-tauri/Cargo.toml', 'openless-all/app/src-tauri/Cargo.lock', 'openless-all/app/src-tauri/tauri*.json', '.cargo/config.toml', '.github/actions/cache-macos-mlx/action.yml') }}
+11
View File
@@ -252,6 +252,12 @@ jobs:
openless-all/app -> target openless-all/app -> target
openless-all/app/src-tauri -> target openless-all/app/src-tauri -> target
- name: Cache macOS MLX native build
if: runner.os == 'macOS' && runner.arch == 'ARM64'
uses: ./.github/actions/cache-macos-mlx
with:
profile: debug
- name: Prepare Windows Sherpa static libraries - name: Prepare Windows Sherpa static libraries
if: runner.os == 'Windows' if: runner.os == 'Windows'
shell: pwsh shell: pwsh
@@ -388,6 +394,11 @@ jobs:
workspaces: | workspaces: |
openless-all/app/src-tauri -> target openless-all/app/src-tauri -> target
openless-all/app/src-tauri/backend-tests -> target openless-all/app/src-tauri/backend-tests -> target
- name: Cache macOS MLX native build
if: runner.arch == 'ARM64'
uses: ./.github/actions/cache-macos-mlx
with:
profile: debug
- run: npm ci - run: npm ci
- run: npm run build - run: npm run build
- name: Check Tauri backend with Rust 1.88 MSRV - name: Check Tauri backend with Rust 1.88 MSRV
+6
View File
@@ -92,6 +92,12 @@ jobs:
key: macos-release-v1 key: macos-release-v1
workspaces: 'openless-all/app/src-tauri -> target' workspaces: 'openless-all/app/src-tauri -> target'
- name: Cache macOS MLX native build
if: matrix.updater-arch == 'aarch64'
uses: ./.github/actions/cache-macos-mlx
with:
profile: release
- name: Prepare Windows Sherpa static libraries - name: Prepare Windows Sherpa static libraries
if: matrix.platform == 'windows-latest' if: matrix.platform == 'windows-latest'
working-directory: 'openless-all/app' working-directory: 'openless-all/app'
+2
View File
@@ -31,6 +31,8 @@ ARM/Intel 的整个打包步骤分别约 15 分 17 秒、15 分 08 秒。主要
macOS 检查统一关闭 dev/test debug info,分别缓存 Core、Host、backend-tests 的实际 target 目录。stable、MSRV、release 缓存分开,避免不同工具链和 profile 的产物互相挤占。 macOS 检查统一关闭 dev/test debug info,分别缓存 Core、Host、backend-tests 的实际 target 目录。stable、MSRV、release 缓存分开,避免不同工具链和 profile 的产物互相挤占。
MLX 的 CMake 输出另用 [cache-macos-mlx](../.github/actions/cache-macos-mlx/action.yml) 保存。实际使用的 `rust-cache` [源码](https://github.com/Swatinem/rust-cache/blob/6323deb102c322ba6fcbdcafc7e3dddab59af2b6/src/workspace.ts) 排除 workspace 目录内的 path 依赖,导致 `src-tauri/vendor/qwen3-asr-rs` 的原生输出在 post 阶段被清理;首轮验证中,命中 Cargo 缓存仍重建 MLX 约 7 分 17 秒。独立缓存步骤放在 `rust-cache` 后,利用 post 的逆序执行先保存原生输出。缓存按架构、profile、Rust/Clang/CMake/SDK、子模块提交、编译环境和 manifest/lock/config 隔离,无跨 key 的模糊回退。只保存 CMake `out`,不保存 Cargo freshness 指纹,下一轮仍执行 build script 与 CMake 输入校验。
`scripts/macos-build-env.sh` 为 macOS 打包默认设置 `CARGO_PROFILE_RELEASE_CODEGEN_UNITS=16`,保留 `opt-level=3`、thin LTO 和 unwind;环境变量可以显式覆盖为其他值。参数取舍依据 [Cargo profiles](https://doc.rust-lang.org/cargo/reference/profiles.html#codegen-units):更多 codegen units 允许更快的并行代码生成,可能影响最终体积或优化效果。共享 `Cargo.toml` 不修改。CI 在恢复缓存前加载同一环境,本地 `build-mac.sh` 也加载它。 `scripts/macos-build-env.sh` 为 macOS 打包默认设置 `CARGO_PROFILE_RELEASE_CODEGEN_UNITS=16`,保留 `opt-level=3`、thin LTO 和 unwind;环境变量可以显式覆盖为其他值。参数取舍依据 [Cargo profiles](https://doc.rust-lang.org/cargo/reference/profiles.html#codegen-units):更多 codegen units 允许更快的并行代码生成,可能影响最终体积或优化效果。共享 `Cargo.toml` 不修改。CI 在恢复缓存前加载同一环境,本地 `build-mac.sh` 也加载它。
MLX 清理只比较含非空 metallib 的输出目录,保留 build-script 可执行文件。构建前删除本次架构的旧 app、DMG 和 updater,保留 Cargo 编译缓存;Tauri 非零退出直接失败。因此热构建复用旧时间戳二进制时仍能正确打包,失败时也不会接受旧安装包。现有用途声明、签名、公证和 MLX 包内容校验继续执行。 MLX 清理只比较含非空 metallib 的输出目录,保留 build-script 可执行文件。构建前删除本次架构的旧 app、DMG 和 updater,保留 Cargo 编译缓存;Tauri 非零退出直接失败。因此热构建复用旧时间戳二进制时仍能正确打包,失败时也不会接受旧安装包。现有用途声明、签名、公证和 MLX 包内容校验继续执行。