From 13ddd8c0e74c11371d93c85bc11dbefd5eacd3f7 Mon Sep 17 00:00:00 2001 From: Mike Solar Date: Thu, 24 Sep 2026 13:37:23 +0800 Subject: [PATCH] fix(macos): compile the VideoToolbox import and clean platform warnings The macOS job finally reached the build (after the vcpkg manifest fix) and hit a macOS-only compile error in the VideoToolbox import: `*ptr as *const T` parses as `(*ptr) as *const T`, so `sw_format` was read off a pointer instead of the AVHWFramesContext. Bind the frames pointer first. Also fix the warnings the cross-check surfaced: the redundant MTLPixelFormat import, and doc comments on an extern block and a thread_local! (rustdoc does not document those). Verified locally with a host-cc wrapper: `cargo check -p oak-core -p oak-codec -p oak-node -p oak-render -p oak-task -p oak-plugin --target aarch64-apple-darwin` is clean. (oak-app itself needs a real Apple toolchain for ring.) --- crates/oak-codec/src/gpuinterop.rs | 5 +++-- crates/oak-core/src/backend/external.rs | 3 +-- crates/oak-plugin/src/gl_bridge.rs | 18 +++++++++--------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/crates/oak-codec/src/gpuinterop.rs b/crates/oak-codec/src/gpuinterop.rs index 56f01645e..f47626cd3 100644 --- a/crates/oak-codec/src/gpuinterop.rs +++ b/crates/oak-codec/src/gpuinterop.rs @@ -516,7 +516,7 @@ fn d3d11_import(req: &HwImportRequest<'_>, ctx: &Arc) -> ImportOutco // macOS: VideoToolbox CVPixelBuffer -> IOSurface -> Metal textures // --------------------------------------------------------------------------- -/// `CVPixelBufferGetIOSurface` (CoreVideo). +// `CVPixelBufferGetIOSurface` (CoreVideo). #[cfg(target_os = "macos")] #[link(name = "CoreVideo", kind = "framework")] extern "C" { @@ -543,7 +543,8 @@ fn videotoolbox_import(req: &HwImportRequest<'_>, ctx: &Arc) -> Impo return ImportOutcome::Unsupported; } // SAFETY: `hw_frames_ctx` is an AVHWFramesContext for this frame. - let sw_format = unsafe { (*(*frames).data as *const sys::AVHWFramesContext).sw_format }; + let hw_frames = unsafe { (*frames).data as *const sys::AVHWFramesContext }; + let sw_format = unsafe { (*hw_frames).sw_format }; let format = match sw_format { sys::AVPixelFormat::AV_PIX_FMT_NV12 => PlanarFormat::Nv12, sys::AVPixelFormat::AV_PIX_FMT_P010LE | sys::AVPixelFormat::AV_PIX_FMT_P010BE => { diff --git a/crates/oak-core/src/backend/external.rs b/crates/oak-core/src/backend/external.rs index f7e31e2cc..80bf6e894 100644 --- a/crates/oak-core/src/backend/external.rs +++ b/crates/oak-core/src/backend/external.rs @@ -459,8 +459,7 @@ impl GpuContext { use objc2::runtime::ProtocolObject; use objc2_io_surface::IOSurfaceRef; use objc2_metal::{ - MTLDevice as _, MTLPixelFormat, MTLStorageMode, MTLTextureDescriptor, - MTLTextureType, MTLTextureUsage, + MTLDevice as _, MTLStorageMode, MTLTextureDescriptor, MTLTextureType, MTLTextureUsage, }; use wgpu::hal; diff --git a/crates/oak-plugin/src/gl_bridge.rs b/crates/oak-plugin/src/gl_bridge.rs index bc24e1dda..ccfa85458 100644 --- a/crates/oak-plugin/src/gl_bridge.rs +++ b/crates/oak-plugin/src/gl_bridge.rs @@ -252,13 +252,13 @@ mod imp { const K_CGL_PFA_COLOR_SIZE: i32 = 8; const K_CGL_PFA_ALPHA_SIZE: i32 = 11; - /// macOS:CGL + OpenGL 的 FFI 声明(直接链接 OpenGL.framework)。 - /// - /// # Safety - /// - /// 全部是系统 framework 导出函数;指针参数语义见各函数注释。 - /// CGL* 类型用 `*mut c_void` 表示不透明对象指针(CGLContextObj / - /// CGLPixelFormatObj)。 + // macOS:CGL + OpenGL 的 FFI 声明(直接链接 OpenGL.framework)。 + // + // # Safety + // + // 全部是系统 framework 导出函数;指针参数语义见各函数注释。 + // CGL* 类型用 `*mut c_void` 表示不透明对象指针(CGLContextObj / + // CGLPixelFormatObj)。 #[link(name = "OpenGL", kind = "framework")] unsafe extern "C" { /// 按属性列表选像素格式(成功返回 kCGLNoError=0;`npix` 是 @@ -406,8 +406,8 @@ mod imp { _ctx: Arc, } - /// 当前线程的 acquire 嵌套深度。>0 = 本线程已持外层 guard(上下文 - /// 已 current);嵌套 acquire 只递增深度,不重取锁。 + // 当前线程的 acquire 嵌套深度。>0 = 本线程已持外层 guard(上下文 + // 已 current);嵌套 acquire 只递增深度,不重取锁。 thread_local! { static ACQUIRE_DEPTH: std::cell::Cell = const { std::cell::Cell::new(0) }; }