chore: remove once_cell dependency from multiple crates (#4154)

This commit removes the `once_cell` dependency from `Cargo.toml` files
in the `codex-rs` and `apply-patch` directories, replacing its usage
with `std::sync::LazyLock` and `std::sync::OnceLock` where applicable.
This change simplifies the dependency tree and utilizes standard library
features for lazy initialization.

# External (non-OpenAI) Pull Request Requirements

Before opening this Pull Request, please read the dedicated
"Contributing" markdown file or your PR may be closed:
https://github.com/openai/codex/blob/main/docs/contributing.md

If your PR conforms to our contribution guidelines, replace this text
with a detailed and high quality description of your changes.
This commit is contained in:
Tien Nguyen
2025-09-24 23:15:57 +07:00
committed by GitHub
parent 82e65975b2
commit 00c7f7a16c
6 changed files with 8 additions and 17 deletions

2
codex-rs/Cargo.lock generated
View File

@@ -595,7 +595,6 @@ version = "0.0.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"assert_cmd", "assert_cmd",
"once_cell",
"pretty_assertions", "pretty_assertions",
"similar", "similar",
"tempfile", "tempfile",
@@ -956,7 +955,6 @@ dependencies = [
"lazy_static", "lazy_static",
"libc", "libc",
"mcp-types", "mcp-types",
"once_cell",
"path-clean", "path-clean",
"pathdiff", "pathdiff",
"pretty_assertions", "pretty_assertions",

View File

@@ -94,7 +94,6 @@ maplit = "1.0.2"
mime_guess = "2.0.5" mime_guess = "2.0.5"
multimap = "0.10.0" multimap = "0.10.0"
nucleo-matcher = "0.3.1" nucleo-matcher = "0.3.1"
once_cell = "1"
openssl-sys = "*" openssl-sys = "*"
os_info = "3.12.0" os_info = "3.12.0"
owo-colors = "4.2.0" owo-colors = "4.2.0"

View File

@@ -20,7 +20,6 @@ similar = { workspace = true }
thiserror = { workspace = true } thiserror = { workspace = true }
tree-sitter = { workspace = true } tree-sitter = { workspace = true }
tree-sitter-bash = { workspace = true } tree-sitter-bash = { workspace = true }
once_cell = { workspace = true }
[dev-dependencies] [dev-dependencies]
assert_cmd = { workspace = true } assert_cmd = { workspace = true }

View File

@@ -6,10 +6,10 @@ use std::collections::HashMap;
use std::path::Path; use std::path::Path;
use std::path::PathBuf; use std::path::PathBuf;
use std::str::Utf8Error; use std::str::Utf8Error;
use std::sync::LazyLock;
use anyhow::Context; use anyhow::Context;
use anyhow::Result; use anyhow::Result;
use once_cell::sync::Lazy;
pub use parser::Hunk; pub use parser::Hunk;
pub use parser::ParseError; pub use parser::ParseError;
use parser::ParseError::*; use parser::ParseError::*;
@@ -351,7 +351,7 @@ fn extract_apply_patch_from_bash(
// also run an arbitrary query against the AST. This is useful for understanding // also run an arbitrary query against the AST. This is useful for understanding
// how tree-sitter parses the script and whether the query syntax is correct. Be sure // how tree-sitter parses the script and whether the query syntax is correct. Be sure
// to test both positive and negative cases. // to test both positive and negative cases.
static APPLY_PATCH_QUERY: Lazy<Query> = Lazy::new(|| { static APPLY_PATCH_QUERY: LazyLock<Query> = LazyLock::new(|| {
let language = BASH.into(); let language = BASH.into();
#[expect(clippy::expect_used)] #[expect(clippy::expect_used)]
Query::new( Query::new(

View File

@@ -53,7 +53,6 @@ image = { workspace = true, features = [
itertools = { workspace = true } itertools = { workspace = true }
lazy_static = { workspace = true } lazy_static = { workspace = true }
mcp-types = { workspace = true } mcp-types = { workspace = true }
once_cell = { workspace = true }
path-clean = { workspace = true } path-clean = { workspace = true }
rand = { workspace = true } rand = { workspace = true }
ratatui = { workspace = true, features = [ ratatui = { workspace = true, features = [

View File

@@ -2,27 +2,27 @@ use std::fs::File;
use std::fs::OpenOptions; use std::fs::OpenOptions;
use std::io::Write; use std::io::Write;
use std::path::PathBuf; use std::path::PathBuf;
use std::sync::LazyLock;
use std::sync::Mutex; use std::sync::Mutex;
use std::sync::OnceLock;
use codex_core::config::Config; use codex_core::config::Config;
use codex_core::protocol::Op; use codex_core::protocol::Op;
use once_cell::sync::Lazy;
use once_cell::sync::OnceCell;
use serde::Serialize; use serde::Serialize;
use serde_json::json; use serde_json::json;
use crate::app_event::AppEvent; use crate::app_event::AppEvent;
static LOGGER: Lazy<SessionLogger> = Lazy::new(SessionLogger::new); static LOGGER: LazyLock<SessionLogger> = LazyLock::new(SessionLogger::new);
struct SessionLogger { struct SessionLogger {
file: OnceCell<Mutex<File>>, file: OnceLock<Mutex<File>>,
} }
impl SessionLogger { impl SessionLogger {
fn new() -> Self { fn new() -> Self {
Self { Self {
file: OnceCell::new(), file: OnceLock::new(),
} }
} }
@@ -37,11 +37,7 @@ impl SessionLogger {
} }
let file = opts.open(path)?; let file = opts.open(path)?;
// If already initialized, ignore and succeed. self.file.get_or_init(|| Mutex::new(file));
if self.file.get().is_some() {
return Ok(());
}
let _ = self.file.set(Mutex::new(file));
Ok(()) Ok(())
} }