From 5bc4c5c997eff7f2683c6f08b05207b0bf478a55 Mon Sep 17 00:00:00 2001 From: Jeremy Lewi Date: Mon, 13 Apr 2026 09:55:19 -0700 Subject: [PATCH] refactor: trim wasm blockers from shared api dependencies Compile websocket-only exports out of codex-api on wasm and stop enabling Tokio net there by default. Also cut the Tokio process dependency out of wasm builds of codex-git-utils by gating the async git-info module, move codex-utils-image's Tokio dependency to tests, and enable uuid's js RNG feature for wasm in codex-protocol. Native cargo checks passed for codex-api, codex-git-utils, and codex-protocol after the refactor. --- codex-rs/codex-api/Cargo.toml | 9 ++++++--- codex-rs/codex-api/src/endpoint/mod.rs | 2 ++ codex-rs/codex-api/src/lib.rs | 10 ++++++++++ codex-rs/codex-api/src/telemetry.rs | 3 +++ codex-rs/git-utils/Cargo.toml | 4 +++- codex-rs/git-utils/src/lib.rs | 16 ++++++++++++++++ codex-rs/protocol/Cargo.toml | 3 +++ codex-rs/utils/image/Cargo.toml | 2 +- 8 files changed, 44 insertions(+), 5 deletions(-) diff --git a/codex-rs/codex-api/Cargo.toml b/codex-rs/codex-api/Cargo.toml index a3a5fa4d92..bf2cdb6407 100644 --- a/codex-rs/codex-api/Cargo.toml +++ b/codex-rs/codex-api/Cargo.toml @@ -15,9 +15,7 @@ http = { workspace = true } serde = { workspace = true, features = ["derive"] } serde_json = { workspace = true } thiserror = { workspace = true } -tokio = { workspace = true, features = ["macros", "net", "rt", "sync", "time"] } -tokio-tungstenite = { workspace = true } -tungstenite = { workspace = true } +tokio = { workspace = true, features = ["macros", "rt", "sync", "time"] } tracing = { workspace = true } eventsource-stream = { workspace = true } regex-lite = { workspace = true } @@ -32,5 +30,10 @@ tokio-test = { workspace = true } wiremock = { workspace = true } reqwest = { workspace = true } +[target.'cfg(not(target_arch = "wasm32"))'.dependencies] +tokio = { workspace = true, features = ["net"] } +tokio-tungstenite = { workspace = true } +tungstenite = { workspace = true } + [lints] workspace = true diff --git a/codex-rs/codex-api/src/endpoint/mod.rs b/codex-rs/codex-api/src/endpoint/mod.rs index 6a748e533d..7aa7867fe4 100644 --- a/codex-rs/codex-api/src/endpoint/mod.rs +++ b/codex-rs/codex-api/src/endpoint/mod.rs @@ -1,7 +1,9 @@ pub mod compact; pub mod memories; pub mod models; +#[cfg(not(target_arch = "wasm32"))] pub mod realtime_websocket; pub mod responses; +#[cfg(not(target_arch = "wasm32"))] pub mod responses_websocket; mod session; diff --git a/codex-rs/codex-api/src/lib.rs b/codex-rs/codex-api/src/lib.rs index 865abf8a76..25b829179e 100644 --- a/codex-rs/codex-api/src/lib.rs +++ b/codex-rs/codex-api/src/lib.rs @@ -30,20 +30,30 @@ pub use crate::common::response_create_client_metadata; pub use crate::endpoint::compact::CompactClient; pub use crate::endpoint::memories::MemoriesClient; pub use crate::endpoint::models::ModelsClient; +#[cfg(not(target_arch = "wasm32"))] pub use crate::endpoint::realtime_websocket::RealtimeEventParser; +#[cfg(not(target_arch = "wasm32"))] pub use crate::endpoint::realtime_websocket::RealtimeSessionConfig; +#[cfg(not(target_arch = "wasm32"))] pub use crate::endpoint::realtime_websocket::RealtimeSessionMode; +#[cfg(not(target_arch = "wasm32"))] pub use crate::endpoint::realtime_websocket::RealtimeWebsocketClient; +#[cfg(not(target_arch = "wasm32"))] pub use crate::endpoint::realtime_websocket::RealtimeWebsocketConnection; pub use crate::endpoint::responses::ResponsesClient; pub use crate::endpoint::responses::ResponsesOptions; +#[cfg(not(target_arch = "wasm32"))] pub use crate::endpoint::responses_websocket::ResponsesWebsocketClient; +#[cfg(not(target_arch = "wasm32"))] pub use crate::endpoint::responses_websocket::ResponsesWebsocketConnection; pub use crate::error::ApiError; pub use crate::provider::Provider; pub use crate::provider::is_azure_responses_wire_base_url; pub use crate::sse::stream_from_fixture; pub use crate::telemetry::SseTelemetry; +#[cfg(not(target_arch = "wasm32"))] pub use crate::telemetry::WebsocketTelemetry; +#[cfg(not(target_arch = "wasm32"))] pub use codex_protocol::protocol::RealtimeAudioFrame; +#[cfg(not(target_arch = "wasm32"))] pub use codex_protocol::protocol::RealtimeEvent; diff --git a/codex-rs/codex-api/src/telemetry.rs b/codex-rs/codex-api/src/telemetry.rs index 91918a65b9..12fa2defb4 100644 --- a/codex-rs/codex-api/src/telemetry.rs +++ b/codex-rs/codex-api/src/telemetry.rs @@ -11,7 +11,9 @@ use std::future::Future; use std::sync::Arc; use std::time::Duration; use tokio::time::Instant; +#[cfg(not(target_arch = "wasm32"))] use tokio_tungstenite::tungstenite::Error; +#[cfg(not(target_arch = "wasm32"))] use tokio_tungstenite::tungstenite::Message; /// Generic telemetry. @@ -31,6 +33,7 @@ pub trait SseTelemetry: Send + Sync { ); } +#[cfg(not(target_arch = "wasm32"))] /// Telemetry for Responses WebSocket transport. pub trait WebsocketTelemetry: Send + Sync { fn on_ws_request(&self, duration: Duration, error: Option<&ApiError>, connection_reused: bool); diff --git a/codex-rs/git-utils/Cargo.toml b/codex-rs/git-utils/Cargo.toml index 7ecc72dfa9..016098eb0f 100644 --- a/codex-rs/git-utils/Cargo.toml +++ b/codex-rs/git-utils/Cargo.toml @@ -17,7 +17,6 @@ schemars = { workspace = true } serde = { workspace = true, features = ["derive"] } tempfile = { workspace = true } thiserror = { workspace = true } -tokio = { workspace = true, features = ["macros", "process", "rt", "time"] } ts-rs = { workspace = true, features = [ "uuid-impl", "serde-json-impl", @@ -28,3 +27,6 @@ walkdir = { workspace = true } [dev-dependencies] assert_matches = { workspace = true } pretty_assertions = { workspace = true } + +[target.'cfg(not(target_arch = "wasm32"))'.dependencies] +tokio = { workspace = true, features = ["macros", "process", "rt", "time"] } diff --git a/codex-rs/git-utils/src/lib.rs b/codex-rs/git-utils/src/lib.rs index 8f188e4bf0..af0aea15fb 100644 --- a/codex-rs/git-utils/src/lib.rs +++ b/codex-rs/git-utils/src/lib.rs @@ -5,6 +5,7 @@ mod apply; mod branch; mod errors; mod ghost_commits; +#[cfg(not(target_arch = "wasm32"))] mod info; mod operations; mod platform; @@ -29,20 +30,35 @@ pub use ghost_commits::create_ghost_commit_with_report; pub use ghost_commits::restore_ghost_commit; pub use ghost_commits::restore_ghost_commit_with_options; pub use ghost_commits::restore_to_commit; +#[cfg(not(target_arch = "wasm32"))] pub use info::CommitLogEntry; +#[cfg(not(target_arch = "wasm32"))] pub use info::GitDiffToRemote; +#[cfg(not(target_arch = "wasm32"))] pub use info::GitInfo; +#[cfg(not(target_arch = "wasm32"))] pub use info::collect_git_info; +#[cfg(not(target_arch = "wasm32"))] pub use info::current_branch_name; +#[cfg(not(target_arch = "wasm32"))] pub use info::default_branch_name; +#[cfg(not(target_arch = "wasm32"))] pub use info::get_git_remote_urls; +#[cfg(not(target_arch = "wasm32"))] pub use info::get_git_remote_urls_assume_git_repo; +#[cfg(not(target_arch = "wasm32"))] pub use info::get_git_repo_root; +#[cfg(not(target_arch = "wasm32"))] pub use info::get_has_changes; +#[cfg(not(target_arch = "wasm32"))] pub use info::get_head_commit_hash; +#[cfg(not(target_arch = "wasm32"))] pub use info::git_diff_to_remote; +#[cfg(not(target_arch = "wasm32"))] pub use info::local_git_branches; +#[cfg(not(target_arch = "wasm32"))] pub use info::recent_commits; +#[cfg(not(target_arch = "wasm32"))] pub use info::resolve_root_git_project_for_trust; pub use platform::create_symlink; use schemars::JsonSchema; diff --git a/codex-rs/protocol/Cargo.toml b/codex-rs/protocol/Cargo.toml index 58f3e06067..ffd310fd3c 100644 --- a/codex-rs/protocol/Cargo.toml +++ b/codex-rs/protocol/Cargo.toml @@ -42,6 +42,9 @@ anyhow = { workspace = true } pretty_assertions = { workspace = true } tempfile = { workspace = true } +[target.'cfg(target_arch = "wasm32")'.dependencies] +uuid = { workspace = true, features = ["js"] } + [package.metadata.cargo-shear] # Required because: # `icu_provider`: contains a required `sync` feature for `icu_decimal` diff --git a/codex-rs/utils/image/Cargo.toml b/codex-rs/utils/image/Cargo.toml index 9fcd3166bf..c899d0bdf8 100644 --- a/codex-rs/utils/image/Cargo.toml +++ b/codex-rs/utils/image/Cargo.toml @@ -13,7 +13,7 @@ image = { workspace = true, features = ["jpeg", "png", "gif", "webp"] } codex-utils-cache = { workspace = true } mime_guess = { workspace = true } thiserror = { workspace = true } -tokio = { workspace = true, features = ["fs", "rt", "rt-multi-thread", "macros"] } [dev-dependencies] image = { workspace = true, features = ["jpeg", "png", "gif", "webp"] } +tokio = { workspace = true, features = ["fs", "rt", "rt-multi-thread", "macros"] }