mirror of
https://github.com/openai/codex.git
synced 2026-04-28 16:45:54 +00:00
## Summary This PR removes the temporary `CODEX_BWRAP_ENABLE_FFI` flag and makes Linux builds always compile vendored bubblewrap support for `codex-linux-sandbox`. ## Changes - Removed `CODEX_BWRAP_ENABLE_FFI` gating from `codex-rs/linux-sandbox/build.rs`. - Linux builds now fail fast if vendored bubblewrap compilation fails (instead of warning and continuing). - Updated fallback/help text in `codex-rs/linux-sandbox/src/vendored_bwrap.rs` to remove references to `CODEX_BWRAP_ENABLE_FFI`. - Removed `CODEX_BWRAP_ENABLE_FFI` env wiring from: - `.github/workflows/rust-ci.yml` - `.github/workflows/bazel.yml` - `.github/workflows/rust-release.yml` --------- Co-authored-by: David Zbarsky <zbarsky@openai.com>
71 lines
2.6 KiB
Rust
71 lines
2.6 KiB
Rust
//! Build-time bubblewrap entrypoint.
|
|
//!
|
|
//! On Linux targets, the build script compiles bubblewrap's C sources and
|
|
//! exposes a `bwrap_main` symbol that we can call via FFI.
|
|
|
|
#[cfg(vendored_bwrap_available)]
|
|
mod imp {
|
|
use std::ffi::CString;
|
|
use std::os::raw::c_char;
|
|
|
|
unsafe extern "C" {
|
|
fn bwrap_main(argc: libc::c_int, argv: *const *const c_char) -> libc::c_int;
|
|
}
|
|
|
|
fn argv_to_cstrings(argv: &[String]) -> Vec<CString> {
|
|
let mut cstrings: Vec<CString> = Vec::with_capacity(argv.len());
|
|
for arg in argv {
|
|
match CString::new(arg.as_str()) {
|
|
Ok(value) => cstrings.push(value),
|
|
Err(err) => panic!("failed to convert argv to CString: {err}"),
|
|
}
|
|
}
|
|
cstrings
|
|
}
|
|
|
|
/// Run the build-time bubblewrap `main` function and return its exit code.
|
|
///
|
|
/// On success, bubblewrap will `execve` into the target program and this
|
|
/// function will never return. A return value therefore implies failure.
|
|
pub(crate) fn run_vendored_bwrap_main(argv: &[String]) -> libc::c_int {
|
|
let cstrings = argv_to_cstrings(argv);
|
|
|
|
let mut argv_ptrs: Vec<*const c_char> = cstrings.iter().map(|arg| arg.as_ptr()).collect();
|
|
argv_ptrs.push(std::ptr::null());
|
|
|
|
// SAFETY: We provide a null-terminated argv vector whose pointers
|
|
// remain valid for the duration of the call.
|
|
unsafe { bwrap_main(cstrings.len() as libc::c_int, argv_ptrs.as_ptr()) }
|
|
}
|
|
|
|
/// Execute the build-time bubblewrap `main` function with the given argv.
|
|
pub(crate) fn exec_vendored_bwrap(argv: Vec<String>) -> ! {
|
|
let exit_code = run_vendored_bwrap_main(&argv);
|
|
std::process::exit(exit_code);
|
|
}
|
|
}
|
|
|
|
#[cfg(not(vendored_bwrap_available))]
|
|
mod imp {
|
|
/// Panics with a clear error when the build-time bwrap path is not enabled.
|
|
pub(crate) fn run_vendored_bwrap_main(_argv: &[String]) -> libc::c_int {
|
|
panic!(
|
|
r#"build-time bubblewrap is not available in this build.
|
|
codex-linux-sandbox should always compile vendored bubblewrap on Linux targets.
|
|
Notes:
|
|
- ensure the target OS is Linux
|
|
- libcap headers must be available via pkg-config
|
|
- bubblewrap sources expected at codex-rs/vendor/bubblewrap (default)"#
|
|
);
|
|
}
|
|
|
|
/// Panics with a clear error when the build-time bwrap path is not enabled.
|
|
pub(crate) fn exec_vendored_bwrap(_argv: Vec<String>) -> ! {
|
|
let _ = run_vendored_bwrap_main(&[]);
|
|
unreachable!("run_vendored_bwrap_main should always panic in this configuration")
|
|
}
|
|
}
|
|
|
|
pub(crate) use imp::exec_vendored_bwrap;
|
|
pub(crate) use imp::run_vendored_bwrap_main;
|