From 4785b945e83ea4084f26175c87dda994205bea58 Mon Sep 17 00:00:00 2001 From: Ruslan Nigmatullin Date: Tue, 21 Apr 2026 17:35:49 -0700 Subject: [PATCH] codex: fix CI failure on PR #18431 ## Summary Load LocalAuthentication.framework at runtime before constructing LAContext instead of linking the framework into every macOS target. The previous direct framework link made unrelated macOS Bazel targets link against an SDK-backed framework path, which caused the macOS CI jobs to fail during linking. The signing flow still uses LAContext for authenticated private-key operations; this only changes how the framework becomes available to the Objective-C runtime. ## Validation - just fmt - cargo test -p codex-device-key - just fix -p codex-device-key - git diff --check - bazel build //codex-rs/device-key:device-key --- codex-rs/device-key/src/platform/macos.rs | 30 ++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/codex-rs/device-key/src/platform/macos.rs b/codex-rs/device-key/src/platform/macos.rs index 204e105fd2..1d1ca0499a 100644 --- a/codex-rs/device-key/src/platform/macos.rs +++ b/codex-rs/device-key/src/platform/macos.rs @@ -55,12 +55,13 @@ unsafe extern "C" { static kSecUseAuthenticationContext: CFStringRef; } -#[link(name = "LocalAuthentication", kind = "framework")] -unsafe extern "C" {} +unsafe extern "C" { + fn dlopen(path: *const c_char, mode: i32) -> *mut c_void; + fn dlsym(handle: *mut c_void, symbol: *const c_char) -> *mut c_void; +} #[link(name = "objc")] unsafe extern "C" { - fn dlsym(handle: *mut c_void, symbol: *const c_char) -> *mut c_void; fn objc_getClass(name: *const c_char) -> ObjcId; fn sel_registerName(name: *const c_char) -> ObjcSel; } @@ -68,6 +69,8 @@ unsafe extern "C" { type ObjcId = *mut c_void; type ObjcSel = *mut c_void; +const LOCAL_AUTHENTICATION_FRAMEWORK_PATH: &[u8] = + b"/System/Library/Frameworks/LocalAuthentication.framework/LocalAuthentication\0"; const LA_CONTEXT_CLASS: &[u8] = b"LAContext\0"; const OBJC_MSG_SEND_SYMBOL: &[u8] = b"objc_msgSend\0"; const OBJC_ALLOC_SELECTOR: &[u8] = b"alloc\0"; @@ -76,6 +79,8 @@ const OBJC_RELEASE_SELECTOR: &[u8] = b"release\0"; const SET_TOUCH_ID_AUTHENTICATION_REUSE_DURATION_SELECTOR: &[u8] = b"setTouchIDAuthenticationAllowableReuseDuration:\0"; const TOUCH_ID_AUTHENTICATION_REUSE_DURATION_SECONDS: c_double = 300.0; +const RTLD_LAZY: i32 = 0x1; +const RTLD_LOCAL: i32 = 0x4; #[derive(Debug)] pub(crate) struct MacOsDeviceKeyProvider; @@ -156,6 +161,7 @@ unsafe impl Send for LocalAuthenticationContext {} impl LocalAuthenticationContext { fn new() -> Result { + load_local_authentication_framework()?; let class = unsafe { objc_getClass(LA_CONTEXT_CLASS.as_ptr().cast::()) }; if class.is_null() { return Err(DeviceKeyError::Platform( @@ -225,6 +231,24 @@ fn sel(name: &'static [u8]) -> ObjcSel { unsafe { sel_registerName(name.as_ptr().cast::()) } } +fn load_local_authentication_framework() -> Result<(), DeviceKeyError> { + let handle = unsafe { + dlopen( + LOCAL_AUTHENTICATION_FRAMEWORK_PATH + .as_ptr() + .cast::(), + RTLD_LAZY | RTLD_LOCAL, + ) + }; + if handle.is_null() { + Err(DeviceKeyError::Platform( + "failed to load LocalAuthentication.framework".to_string(), + )) + } else { + Ok(()) + } +} + unsafe fn objc_msg_send_id(receiver: ObjcId, selector: ObjcSel) -> Result { let msg_send: unsafe extern "C" fn(ObjcId, ObjcSel) -> ObjcId = unsafe { std::mem::transmute(objc_msg_send_symbol()?) };