Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 71 additions & 9 deletions .github/workflows/check-ios.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
name: iOS tests and device build

on:
# PRs only read the shared Rust caches. Keep a default-branch writer so the
# first PR does not create an isolated cache that later PRs cannot restore.
push:
branches: [main, beta]
paths:
- 'openless-all/ios/**'
- 'openless-all/app/crates/openless-core/**'
- 'openless-all/app/crates/micyou-*/**'
- 'openless-all/app/contract/**'
- 'openless-all/app/assets/**'
- '.github/workflows/check-ios.yml'
pull_request:
paths:
- 'openless-all/ios/**'
Expand All @@ -15,19 +26,19 @@ permissions:
contents: read

concurrency:
group: ios-checks-${{ github.ref }}
cancel-in-progress: true
# Supersede older checks of the same kind. A manual run must not cancel the
# PR check required for merging, or the push run that maintains beta caches.
group: ios-checks-${{ github.ref }}-${{ github.event_name }}
cancel-in-progress: ${{ github.event_name != 'push' }}

env:
CARGO_PROFILE_DEV_DEBUG: 0
CARGO_PROFILE_TEST_DEBUG: 0

jobs:
changes:
# `test` builds and lints the shared Core for iOS, so it must run whenever the
# Rust graph moves. `device-build` (13 minutes on a 10x-cost macOS runner)
# only proves the Xcode/Rime project layer still builds — shared-crate edits
# cannot reach it, so it is gated on the project layer alone.
# Shared Rust changes also need real device-target compilation. The area
# detector covers the iOS Core dependency graph and Xcode project layer.
name: Changed areas
runs-on: ubuntu-latest
timeout-minutes: 10
Expand Down Expand Up @@ -66,13 +77,27 @@ jobs:
git rev-parse HEAD:openless-all/app
- name: Prepare the isolated mobile Core
run: python3 openless-all/ios/scripts/prepare-core.py
- name: Resolve Xcode cache identity
id: xcode
run: echo "version=$(xcodebuild -version | tr '\n' '-')" >> "$GITHUB_OUTPUT"
- name: Cache iOS host Rust dependencies
uses: swatinem/rust-cache@v2
with:
shared-key: ios-host
key: ${{ steps.xcode.outputs.version }}
workspaces: 'openless-all/ios/CoreHost -> target'
save-if: ${{ github.ref == 'refs/heads/beta' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch') }}
- name: Test shared keyboard contracts
timeout-minutes: 5
run: swift test --package-path openless-all/ios/Packages/OpenLessShared
- name: Test mobile Core and iOS Host
run: cargo test --manifest-path openless-all/ios/CoreHost/Cargo.toml --workspace --lib --locked
timeout-minutes: 12
run: cargo test --manifest-path openless-all/ios/CoreHost/Cargo.toml --workspace --lib --locked --timings
- name: Check mobile Core
timeout-minutes: 5
run: cargo clippy --manifest-path openless-all/ios/CoreHost/Cargo.toml -p openless-core --all-targets --locked -- -D warnings
- name: Test interface resources, predictions and native audio
timeout-minutes: 5
working-directory: openless-all/ios
run: |
python3 scripts/test-interface-resources.py
Expand All @@ -81,9 +106,19 @@ jobs:
bash scripts/test-audio.sh
- name: Verify shared sources were not modified
run: git diff --exit-code -- openless-all/app
- name: Upload host Cargo timings
if: ${{ !cancelled() }}
uses: actions/upload-artifact@v4
with:
name: ios-host-cargo-timings
path: openless-all/ios/CoreHost/target/cargo-timings/
if-no-files-found: ignore
retention-days: 7

device-build:
needs: [changes, test]
# Separate runners and no artifacts exchanged with `test`: compile in
# parallel. Both existing checks still report their own failures.
needs: [changes]
if: needs.changes.outputs.device != 'false'
runs-on: xcode-27
timeout-minutes: 60
Expand All @@ -92,22 +127,41 @@ jobs:
working-directory: openless-all/ios
steps:
- uses: actions/checkout@v6
- uses: dtolnay/rust-toolchain@1.99.0
with:
targets: aarch64-apple-ios
- name: Prepare native build tools and dependencies
timeout-minutes: 10
run: |
xcodebuild -version
command -v cmake >/dev/null || brew install cmake
bash scripts/bootstrap.sh
bash scripts/bootstrap-local-speech.sh
- name: Resolve Xcode cache identity
id: xcode
run: echo "version=$(xcodebuild -version | tr '\n' '-')" >> "$GITHUB_OUTPUT"
- name: Cache iOS device Rust dependencies
uses: swatinem/rust-cache@v2
with:
shared-key: ios-device
key: ios16-${{ steps.xcode.outputs.version }}
workspaces: 'openless-all/ios/CoreHost -> ../.build/core-ios16'
save-if: ${{ github.ref == 'refs/heads/beta' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch') }}
- name: Prepare verified local speech dependencies
timeout-minutes: 10
run: bash scripts/bootstrap-local-speech.sh
- name: Build Rime and test composition
timeout-minutes: 12
run: |
bash scripts/build-rime.sh host
bash scripts/test-rime.sh
bash scripts/build-rime.sh device
- name: Build the mobile Core and refresh attribution
timeout-minutes: 10
run: |
bash scripts/build-core.sh device
python3 scripts/collect-rust-licenses.py
- name: Build and validate the unsigned iPhone app
timeout-minutes: 12
env:
OPENLESS_DERIVED_DATA: ${{ runner.temp }}/ios-device
run: |
Expand All @@ -118,3 +172,11 @@ jobs:
"$RUNNER_TEMP/OpenLess-ci-unsigned.ipa"
- name: Verify shared sources were not modified
run: git diff --exit-code -- ../app
- name: Upload device Cargo timings
if: ${{ !cancelled() }}
uses: actions/upload-artifact@v4
with:
name: ios-device-cargo-timings
path: openless-all/ios/.build/core-ios16/cargo-timings/
if-no-files-found: ignore
retention-days: 7
29 changes: 29 additions & 0 deletions docs/ios-ci-performance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# iOS CI 耗时与缓存

本次补充 `.github/workflows/check-ios.yml`,与桌面/Android 优化草稿 [#1412](https://github.com/Open-Less/openless/pull/1412) 独立,二者可以分别合并。

## 历史证据

以下为 GitHub Actions jobs/steps API 的完成时间减开始时间,不包含首次 runner 排队。三次运行使用相同的串行结构,没有控制机器负载,不能直接作为加速比的对照。

| 运行 | host 测试 | 其中 Rust 测试 / Clippy | device 构建 | 首个 job 开始到最后完成 |
|---|---:|---:|---:|---:|
| [42447525487](https://github.com/Open-Less/openless/actions/runs/42447525487) | 555 秒 | 334 / 76 秒 | 637 秒 | 1195 秒 |
| [42502799269](https://github.com/Open-Less/openless/actions/runs/42502799269) | 580 秒 | 353 / 90 秒 | 931 秒 | 1516 秒 |
| [42502805940](https://github.com/Open-Less/openless/actions/runs/42502805940) | 509 秒 | 307 / 81 秒 | 1080 秒 | 1592 秒 |

后两轮是同一 head `121597d8` 的 PR 与手动运行。它们并非运行内的必需依赖;日常应优先复用 PR 结果。手动运行仍与 PR 隔离:取消 PR 检查后,手动运行的成功不会补回 PR 所需的检查结果。

## 改动

- `test` 和 `device-build` 使用各自的 checkout,没有交换构件。设备构建只等待区域判断,测试和构建并行;保留原来的两个 job 名称和独立失败状态。区域检测失败仍阻止设备构建,共享 Rust 变更仍需要 device target 编译。
- 同类型、同 ref 的新 PR/手动检查取消旧任务;默认分支 push 独立运行,维持缓存写入。增加与 PR 相同路径范围的 `main`/`beta` push 触发,避免只读缓存却没有基线写入者。
- host debug/test 与 device release 的 Rust 缓存分开;显式映射 `CoreHost/target` 和 `.build/core-ios16`,不缓存生成的 Core 源码。缓存键含 Rust 环境、lockfile 和 Xcode build identity,device 再区分 iOS 16 部署下限。只允许 beta push/手动运行写缓存,PR 只恢复。
- 为 Swift、Rust、Rime、模型下载、Xcode 编译设置步骤超时,保留原来的 30/60 分钟 job 上限。curl 同时限制连接时间、单次总时间和最低传输速度;模型下载保持断点续传和 SHA-256 校验。Boost 下载先写临时文件,校验后再替换正式归档。
- Cargo 测试和 device 编译生成 timings,成功/失败时上传,保留 7 天。未新增矩阵、签名、发布、模型归档或 CMake 二进制缓存。

## 验证与收益边界

下载行为测试覆盖首次成功、超时后续传、持续超时、校验失败及已验证文件复用。每个长步骤的超时与原有校验保持在同一失败链中。

删除串行依赖可以消除历史样本中 509–580 秒的测试等待,但收益取决于 macOS runner 是否能同时启动。并行本身不会减少 runner 总用时;两个新 Rust 缓存要在 beta 首次运行后才可供后续 PR 恢复,首轮 PR 不承诺提速。记录后续冷/热缓存运行的实际耗时和缓存体积,再按仓库既有缓存预算决定是否保留;不把排队变化计入构建收益。
108 changes: 108 additions & 0 deletions openless-all/app/scripts/ios-ci-downloads.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import assert from 'node:assert/strict';
import { createHash } from 'node:crypto';
import { spawnSync } from 'node:child_process';
import {
chmodSync,
existsSync,
mkdtempSync,
mkdirSync,
readFileSync,
rmSync,
writeFileSync,
} from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';

// Exercise the production downloader with a curl that times out after writing
// a partial response. Retrying must resume that file and still verify integrity.
const source = readFileSync(
new URL('../../ios/scripts/bootstrap-local-speech.sh', import.meta.url),
'utf8',
);
const fetchFunction = source.match(/^fetch\(\) \{[\s\S]*?^\}/m)?.[0];
assert.ok(fetchFunction);
const scratch = mkdtempSync(join(tmpdir(), 'openless-ios-download-'));
try {
const bin = join(scratch, 'bin');
mkdirSync(bin);
const executable = (name, content) => {
const path = join(bin, name);
writeFileSync(path, '#!/usr/bin/env bash\nset -eu\n' + content);
chmodSync(path, 0o755);
};
executable('sleep', 'exit 0\n');
executable(
'curl',
`
max=0; speed=0; window=0; resume=''; output=''
while [ "$#" -gt 0 ]; do
case "$1" in
--max-time) max="$2"; shift ;;
--speed-limit) speed="$2"; shift ;;
--speed-time) window="$2"; shift ;;
--continue-at) resume="$2"; shift ;;
-o) output="$2"; shift ;;
esac
shift
done
[ "$max" -gt 0 ] && [ "$speed" -gt 0 ] && [ "$window" -gt 0 ] && [ "$resume" = '-' ] || exit 99
count=0; [ ! -f "$TRACE" ] || count=$(cat "$TRACE")
count=$((count + 1)); echo "$count" > "$TRACE"
case "$MODE" in
timeout) printf partial > "$output"; exit 28 ;;
resume)
if [ "$count" = 1 ]; then printf partial > "$output"; exit 28; fi
[ "$(cat "$output")" = partial ] || exit 99
;;
corrupt) printf corrupt > "$output"; exit 0 ;;
esac
printf verified > "$output"
`,
);
const sha = createHash('sha256').update('verified').digest('hex');
const run = (mode, output) => {
const result = spawnSync(
'bash',
['-e', '-c', fetchFunction + '\nfetch https://example.invalid/model "$SHA" "$OUTPUT"'],
{
env: {
...process.env,
PATH: bin + ':' + process.env.PATH,
MODE: mode,
TRACE: join(scratch, mode + '-calls'),
SHA: sha,
OUTPUT: output,
},
encoding: 'utf8',
timeout: 5000,
},
);
assert.ifError(result.error);
return result;
};
for (const [mode, expectedCalls] of [
['success', 1],
['resume', 2],
]) {
const output = join(scratch, mode);
const result = run(mode, output);
assert.equal(result.status, 0, result.stdout + result.stderr);
assert.equal(readFileSync(output, 'utf8'), 'verified');
assert.ok(!existsSync(output + '.download'));
assert.equal(Number(readFileSync(join(scratch, mode + '-calls'), 'utf8')), expectedCalls);
assert.equal(run(mode, output).status, 0);
assert.equal(Number(readFileSync(join(scratch, mode + '-calls'), 'utf8')), expectedCalls);
}
for (const [mode, expectedCalls] of [
['timeout', 6],
['corrupt', 1],
]) {
const output = join(scratch, mode);
assert.notEqual(run(mode, output).status, 0);
assert.ok(!existsSync(output), 'failed downloads must not be promoted to verified files');
assert.equal(Number(readFileSync(join(scratch, mode + '-calls'), 'utf8')), expectedCalls);
}
} finally {
rmSync(scratch, { recursive: true, force: true });
}
console.log('ios-ci-downloads.test.mjs passed');
3 changes: 2 additions & 1 deletion openless-all/ios/scripts/bootstrap-local-speech.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ fetch() {
# truncate a partially downloaded file back to its initial offset.
local attempt
for attempt in 1 2 3 4 5 6; do
if curl --http1.1 -fL --continue-at - --connect-timeout 20 "$url" -o "$output.download"; then break; fi
if curl --http1.1 -fL --continue-at - --connect-timeout 20 \
--max-time 180 --speed-limit 1024 --speed-time 30 "$url" -o "$output.download"; then break; fi
[ "$attempt" != 6 ] || return 1
sleep 2
done
Expand Down
7 changes: 6 additions & 1 deletion openless-all/ios/scripts/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ grep -q '^MIT License' "$ROOT/.vendor/KeyboardKit/LICENSE"
cp "$ROOT/.vendor/KeyboardKit/LICENSE" "$ROOT/Resources/Licenses/KeyboardKit-LICENSE.txt"
checkout https://github.com/rime/rime-pinyin-simp.git "$ROOT/.vendor/rime-pinyin-simp" 0c6861ef7420ee780270ca6d993d18d4101049d0
BOOST="$ROOT/.vendor/boost_1_85_0.tar.bz2"
[ -f "$BOOST" ] || curl -LfsS --retry 2 https://archives.boost.io/release/1.85.0/source/boost_1_85_0.tar.bz2 -o "$BOOST"
if [ ! -f "$BOOST" ]; then
curl -LfsS --retry 2 --connect-timeout 20 --max-time 300 \
--speed-limit 1024 --speed-time 30 https://archives.boost.io/release/1.85.0/source/boost_1_85_0.tar.bz2 -o "$BOOST.download"
echo "7009fe1faa1697476bdc7027703a2badb84e849b7b0baad5086b087b971f8617 $BOOST.download" | shasum -a 256 -c -
mv "$BOOST.download" "$BOOST"
fi
echo "7009fe1faa1697476bdc7027703a2badb84e849b7b0baad5086b087b971f8617 $BOOST" | shasum -a 256 -c -
[ -d "$ROOT/.vendor/boost_1_85_0/boost" ] || tar -xjf "$BOOST" -C "$ROOT/.vendor" boost_1_85_0/boost boost_1_85_0/LICENSE_1_0.txt
swift build --package-path "$ROOT/.build-tools/XcodeGen" -c release
Expand Down
2 changes: 1 addition & 1 deletion openless-all/ios/scripts/build-core.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ for spec in "device:aarch64-apple-ios:iphoneos" "simulator:aarch64-apple-ios-sim
[ "$PLATFORM" = all ] || [ "$PLATFORM" = "$platform" ] || continue
mkdir -p "$ROOT/Frameworks/$platform"
IPHONEOS_DEPLOYMENT_TARGET=16.0 SDKROOT="$(xcrun --sdk "$sdk" --show-sdk-path)" \
rustup run 1.99.0 cargo build --manifest-path "$ROOT/CoreHost/Cargo.toml" --locked --release --target "$target"
rustup run 1.99.0 cargo build --manifest-path "$ROOT/CoreHost/Cargo.toml" --locked --release --target "$target" --timings
cp "$CARGO_TARGET_DIR/$target/release/libopenless_ios_host.a" "$ROOT/Frameworks/$platform/libOpenLessCore.a"
python3 "$ROOT/scripts/validate-deployment.py" "$ROOT/Frameworks/$platform/libOpenLessCore.a"
done
Loading