From fa84da59b82934d96ff566be3ac7ef03a5c04cc1 Mon Sep 17 00:00:00 2001 From: Codex Date: Mon, 12 Oct 2026 12:10:18 +0000 Subject: [PATCH] ci: verify native OCR on current macOS before packaging --- .github/workflows/release.yml | 35 +++++++++++++++++++++++++++++++++++ src-tauri/src/ocr/image.rs | 6 +++--- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e17175b..c683ae0 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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 diff --git a/src-tauri/src/ocr/image.rs b/src-tauri/src/ocr/image.rs index d581d39..01426ec 100644 --- a/src-tauri/src/ocr/image.rs +++ b/src-tauri/src/ocr/image.rs @@ -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, 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(