ci: verify native OCR on current macOS before packaging

This commit is contained in:
Codex committed 2026-10-12 12:10:18 +00:00
1 parent bf75be270a
commit fa84da59b8
2 files changed
+38 -3

No files matched your search

+35
View File
@@ -16,7 +16,42 @@ concurrency:
cancel-in-progress: true
jobs:
ocr-current-macos:
# xcode-27 currently runs macOS 27 on Apple Silicon. Keep packaging on the
# existing runner, but exercise the real OCR pipeline on the newer OS too.
runs-on: xcode-27
timeout-minutes: 15
permissions:
contents: read
steps:
- name: Check out source
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
- name: Install Rust stable
uses: dtolnay/rust-toolchain@4be7066ada62dd38de10e7b70166bc74ed198c30 # stable
- name: Cache current macOS OCR dependencies
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4
with:
path: |
~/.cargo/registry
~/.cargo/git
src-tauri/target
key: macos-27-ocr-${{ hashFiles('src-tauri/Cargo.lock') }}
restore-keys: |
macos-27-ocr-
- name: Record native OCR runtime
run: |
sw_vers
uname -m
swift --version
- name: Exercise native OCR on current macOS
run: cargo test --manifest-path src-tauri/Cargo.toml ocr:: -- --nocapture
verify:
needs: ocr-current-macos
runs-on: macos-14
permissions:
contents: read
+3 -3
View File
@@ -4,8 +4,8 @@
use objc2_core_foundation::{CFData, CFRetained, CGPoint, CGRect, CGSize};
use objc2_core_graphics::{
kCGColorSpaceSRGB, CGBitmapContextCreate, CGBitmapContextCreateImage, CGBitmapInfo,
CGColorSpace, CGContext, CGImage, CGImageAlphaInfo,
kCGColorSpaceSRGB, CGBitmapContextCreate, CGBitmapContextCreateImage,
CGColorSpace, CGContext, CGImage, CGImageAlphaInfo, CGImageByteOrderInfo,
};
use objc2_image_io::CGImageSource;
@@ -39,7 +39,7 @@ pub(super) fn prepare_png(bytes: &[u8]) -> Result<CFRetained<CGImage>, String> {
// 8-bit sRGB、32-bit RGBX,并用白色背景消除透明通道的歧义。
let color_space = CGColorSpace::with_name(Some(unsafe { kCGColorSpaceSRGB }))
.ok_or_else(|| "创建 OCR 色彩空间失败".to_string())?;
let bitmap_info = CGImageAlphaInfo::NoneSkipLast.0 | CGBitmapInfo::ByteOrder32Big.bits();
let bitmap_info = CGImageAlphaInfo::NoneSkipLast.0 | CGImageByteOrderInfo::Order32Big.0;
// SAFETY: null 让 CoreGraphics 自行管理内存;尺寸已检查且每像素 4 字节。
let context = unsafe {
CGBitmapContextCreate(