pub fn arg0_dispatch_or_else<F, Fut>(main_fn: F) -> Result<()>Expand description
While we want to deploy the Codex CLI as a single executable for simplicity, we also want to expose some of its functionality as distinct CLIs, so we use the “arg0 trick” to determine which CLI to dispatch. This effectively allows us to simulate deploying multiple executables as a single binary on Mac and Linux (but not Windows).
When the current executable is invoked through the hard-link or alias named
codex-linux-sandbox we directly execute
[codex_linux_sandbox::run_main] (which never returns). Otherwise we:
- Use
dotenvy::from_pathanddotenvy::dotenvto modify the environment before creating any threads. - Construct a Tokio multi-thread runtime.
- Derive the path to the current executable (so children can re-invoke the sandbox) when running on Linux.
- Execute the provided async
main_fninside that runtime, forwarding any error. Note thatmain_fnreceivescodex_linux_sandbox_exe: Option<PathBuf>, as an argument, which is generally needed as part of constructing [codex_core::config::Config].
This function should be used to wrap any main() function in binary crates
in this workspace that depends on these helper CLIs.