diff --git a/.gitignore b/.gitignore index 0235b806..0f16cb03 100644 --- a/.gitignore +++ b/.gitignore @@ -46,3 +46,9 @@ app.*.map.json /android/app/debug /android/app/profile /android/app/release + +# Rust / FFI artifacts +/rust/target/ +/rust/Cargo.lock +/macos/Frameworks/*.dylib +/macos/Frameworks/*.a diff --git a/Makefile b/Makefile index 13044fe9..31395a97 100644 --- a/Makefile +++ b/Makefile @@ -51,16 +51,9 @@ clean: ## Remove generated artifacts rust-build: rust-build-release ## Build Rust FFI library (release mode) -rust-build-release: ## Build Rust FFI library in release mode +rust-build-release: ## Build Rust FFI library for macOS (arm64) cd rust && cargo build --release --target aarch64-apple-darwin - cd rust && cargo build --release --target x86_64-apple-darwin - @echo "Creating universal binary..." - mkdir -p rust/target/universal - lipo -create \ - rust/target/aarch64-apple-darwin/release/libcodex_ffi.dylib \ - rust/target/x86_64-apple-darwin/release/libcodex_ffi.dylib \ - -output rust/target/universal/libcodex_ffi.dylib || true - @echo "Universal binary created at rust/target/universal/" + @echo "Rust FFI library built successfully" rust-build-debug: ## Build Rust FFI library in debug mode cd rust && cargo build --target aarch64-apple-darwin diff --git a/rust/src/lib.rs b/rust/src/lib.rs index c86f22ed..1cf54268 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -11,7 +11,7 @@ pub use error::CodexError; pub use runtime::{CodexRuntime, CodexConfig, CodexConfigRust, ThreadHandle, RuntimeState}; pub use types::{CodexResult, CodexMessage, CodexEvent}; -use std::ffi::{CStr, CString}; +use std::ffi::CStr; use std::os::raw::c_char; /// FFI-exported initialization function. @@ -55,14 +55,13 @@ pub unsafe extern "C" fn codex_runtime_destroy(runtime: *mut CodexRuntime) { /// Must be called with valid pointers. #[no_mangle] pub unsafe extern "C" fn codex_start_thread( - runtime: *mut CodexRuntime, + _runtime: *mut CodexRuntime, cwd: *const c_char, ) -> ThreadHandle { - if runtime.is_null() || cwd.is_null() { + if cwd.is_null() { return ThreadHandle::null(); } - let _runtime = &mut *runtime; let _cwd = CStr::from_ptr(cwd); ThreadHandle::new(0) @@ -75,7 +74,7 @@ pub unsafe extern "C" fn codex_start_thread( #[no_mangle] pub unsafe extern "C" fn codex_send_message( runtime: *mut CodexRuntime, - thread: ThreadHandle, + _thread: ThreadHandle, message: *const c_char, ) -> i32 { if runtime.is_null() || message.is_null() { diff --git a/rust/src/runtime.rs b/rust/src/runtime.rs index 47e3fa77..60cdca75 100644 --- a/rust/src/runtime.rs +++ b/rust/src/runtime.rs @@ -5,7 +5,6 @@ use std::os::raw::c_char; use std::path::PathBuf; use crate::error::CodexError; -use crate::types::CodexEvent; /// Configuration for Codex runtime. #[derive(Debug, Clone)] @@ -100,24 +99,8 @@ impl CodexConfig { } } -impl Clone for CodexConfig { - fn clone(&self) -> Self { - // Safe to clone the pointers as they're just pointers to strings - CodexConfig { - codex_path: self.codex_path, - working_directory: self.working_directory, - sandbox_mode: self.sandbox_mode, - approval_policy: self.approval_policy, - model: self.model, - api_key: self.api_key, - gateway_url: self.gateway_url, - debug: self.debug, - } - } -} - /// Rust-native config type. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Default)] pub struct CodexConfigRust { pub codex_path: Option, pub working_directory: Option, @@ -218,11 +201,13 @@ impl CodexRuntime { // Check common locations let home = std::env::var("HOME").unwrap_or_default(); - let paths = vec![ + let cargo_path = format!("{}/.cargo/bin/codex", home); + let local_path = format!("{}/.local/bin/codex", home); + let paths = [ "/usr/local/bin/codex", "/opt/homebrew/bin/codex", - &format!("{}/.cargo/bin/codex", home), - &format!("{}/.local/bin/codex", home), + cargo_path.as_str(), + local_path.as_str(), ]; for path in paths {