fix: resolve Rust FFI compilation errors and simplify build
- Fix duplicate Clone implementation conflict in CodexConfig - Add Default derive to CodexConfigRust for unwrap_or_default() - Fix temporary lifetime issues in find_codex_binary() - Remove unused imports (CString, CodexEvent) - Update Makefile rust-build-release to target arm64 only (no x86_64/lipo) - Add gitignore rules for Rust build artifacts
This commit is contained in:
parent
a7760abdc6
commit
6b6a586f8d
6
.gitignore
vendored
6
.gitignore
vendored
@ -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
|
||||
|
||||
11
Makefile
11
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
|
||||
|
||||
@ -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() {
|
||||
|
||||
@ -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<String>,
|
||||
pub working_directory: Option<String>,
|
||||
@ -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 {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user