Skip to content

Commit 2ef91b7

Browse files
authored
chore: move pty and windows sandbox to Rust 2024 (openai#15954)
## Why `codex-utils-pty` and `codex-windows-sandbox` were the remaining crates in `codex-rs` that still overrode the workspace's Rust 2024 edition. Moving them forward in a separate PR keeps the baseline edition update isolated from the follow-on Bazel clippy workflow in openai#15955, while making linting and formatting behavior consistent with the rest of the workspace. This PR also needs Cargo and Bazel to agree on the edition for `codex-windows-sandbox`. Without the Bazel-side sync, the experimental Bazel app-server builds fail once they compile `windows-sandbox-rs`. ## What changed - switch `codex-rs/utils/pty` and `codex-rs/windows-sandbox-rs` to `edition = "2024"` - update `codex-utils-pty` callsites and tests to use the collapsed `if let` form that Clippy expects under the new edition - fix the Rust 2024 fallout in `windows-sandbox-rs`, including the reserved `gen` identifier, `unsafe extern` requirements, and new Clippy findings that surfaced under the edition bump - keep the edition bump separate from a larger unsafe cleanup by temporarily allowing `unsafe_op_in_unsafe_fn` in the Windows entrypoint modules that now report it under Rust 2024 - update `codex-rs/windows-sandbox-rs/BUILD.bazel` to `crate_edition = "2024"` so Bazel compiles the crate with the same edition as Cargo --- [//]: # (BEGIN SAPLING FOOTER) Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/openai/codex/pull/15954). * openai#15976 * openai#15955 * __->__ openai#15954
1 parent 2e84970 commit 2ef91b7

30 files changed

+255
-248
lines changed

codex-rs/utils/pty/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
edition = "2021"
2+
edition = "2024"
33
license.workspace = true
44
name = "codex-utils-pty"
55
version.workspace = true

codex-rs/utils/pty/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ pub const DEFAULT_OUTPUT_BYTES_CAP: usize = 1024 * 1024;
1313
pub use pipe::spawn_process as spawn_pipe_process;
1414
/// Spawn a non-interactive process using regular pipes, but close stdin immediately.
1515
pub use pipe::spawn_process_no_stdin as spawn_pipe_process_no_stdin;
16-
/// Combine stdout/stderr receivers into a single broadcast receiver.
17-
pub use process::combine_output_receivers;
1816
/// Handle for interacting with a spawned process (PTY or pipe).
1917
pub use process::ProcessHandle;
2018
/// Bundle of process handles plus split output and exit receivers returned by spawn helpers.
2119
pub use process::SpawnedProcess;
2220
/// Terminal size in character cells used for PTY spawn and resize operations.
2321
pub use process::TerminalSize;
22+
/// Combine stdout/stderr receivers into a single broadcast receiver.
23+
pub use process::combine_output_receivers;
2424
/// Backwards-compatible alias for ProcessHandle.
2525
pub type ExecCommandSession = ProcessHandle;
2626
/// Backwards-compatible alias for SpawnedProcess.

codex-rs/utils/pty/src/pipe.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ use std::io;
33
use std::io::ErrorKind;
44
use std::path::Path;
55
use std::process::Stdio;
6-
use std::sync::atomic::AtomicBool;
76
use std::sync::Arc;
87
use std::sync::Mutex as StdMutex;
8+
use std::sync::atomic::AtomicBool;
99

1010
use anyhow::Result;
1111
use tokio::io::AsyncRead;
@@ -64,11 +64,7 @@ fn kill_process(pid: u32) -> io::Result<()> {
6464
let success = winapi::um::processthreadsapi::TerminateProcess(handle, 1);
6565
let err = io::Error::last_os_error();
6666
winapi::um::handleapi::CloseHandle(handle);
67-
if success == 0 {
68-
Err(err)
69-
} else {
70-
Ok(())
71-
}
67+
if success == 0 { Err(err) } else { Ok(()) }
7268
}
7369
}
7470

codex-rs/utils/pty/src/process.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ use core::fmt;
22
use std::io;
33
#[cfg(unix)]
44
use std::os::fd::RawFd;
5-
use std::sync::atomic::AtomicBool;
65
use std::sync::Arc;
76
use std::sync::Mutex as StdMutex;
7+
use std::sync::atomic::AtomicBool;
88

99
use anyhow::anyhow;
1010
use portable_pty::MasterPty;
@@ -118,10 +118,10 @@ impl ProcessHandle {
118118

119119
/// Returns a channel sender for writing raw bytes to the child stdin.
120120
pub fn writer_sender(&self) -> mpsc::Sender<Vec<u8>> {
121-
if let Ok(writer_tx) = self.writer_tx.lock() {
122-
if let Some(writer_tx) = writer_tx.as_ref() {
123-
return writer_tx.clone();
124-
}
121+
if let Ok(writer_tx) = self.writer_tx.lock()
122+
&& let Some(writer_tx) = writer_tx.as_ref()
123+
{
124+
return writer_tx.clone();
125125
}
126126

127127
let (writer_tx, writer_rx) = mpsc::channel(1);
@@ -165,36 +165,36 @@ impl ProcessHandle {
165165
/// Attempts to kill the child while leaving the reader/writer tasks alive
166166
/// so callers can still drain output until EOF.
167167
pub fn request_terminate(&self) {
168-
if let Ok(mut killer_opt) = self.killer.lock() {
169-
if let Some(mut killer) = killer_opt.take() {
170-
let _ = killer.kill();
171-
}
168+
if let Ok(mut killer_opt) = self.killer.lock()
169+
&& let Some(mut killer) = killer_opt.take()
170+
{
171+
let _ = killer.kill();
172172
}
173173
}
174174

175175
/// Attempts to kill the child and abort helper tasks.
176176
pub fn terminate(&self) {
177177
self.request_terminate();
178178

179-
if let Ok(mut h) = self.reader_handle.lock() {
180-
if let Some(handle) = h.take() {
181-
handle.abort();
182-
}
179+
if let Ok(mut h) = self.reader_handle.lock()
180+
&& let Some(handle) = h.take()
181+
{
182+
handle.abort();
183183
}
184184
if let Ok(mut handles) = self.reader_abort_handles.lock() {
185185
for handle in handles.drain(..) {
186186
handle.abort();
187187
}
188188
}
189-
if let Ok(mut h) = self.writer_handle.lock() {
190-
if let Some(handle) = h.take() {
191-
handle.abort();
192-
}
189+
if let Ok(mut h) = self.writer_handle.lock()
190+
&& let Some(handle) = h.take()
191+
{
192+
handle.abort();
193193
}
194-
if let Ok(mut h) = self.wait_handle.lock() {
195-
if let Some(handle) = h.take() {
196-
handle.abort();
197-
}
194+
if let Ok(mut h) = self.wait_handle.lock()
195+
&& let Some(handle) = h.take()
196+
{
197+
handle.abort();
198198
}
199199
}
200200
}

codex-rs/utils/pty/src/pty.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ use std::path::Path;
1515
use std::process::Command as StdCommand;
1616
#[cfg(unix)]
1717
use std::process::Stdio;
18-
use std::sync::atomic::AtomicBool;
1918
use std::sync::Arc;
2019
use std::sync::Mutex as StdMutex;
20+
use std::sync::atomic::AtomicBool;
2121
use std::time::Duration;
2222

2323
use anyhow::Result;
24+
use portable_pty::CommandBuilder;
2425
#[cfg(not(windows))]
2526
use portable_pty::native_pty_system;
26-
use portable_pty::CommandBuilder;
2727
use tokio::sync::mpsc;
2828
use tokio::sync::oneshot;
2929
use tokio::task::JoinHandle;

codex-rs/utils/pty/src/tests.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ use std::path::Path;
33

44
use pretty_assertions::assert_eq;
55

6+
use crate::SpawnedProcess;
7+
use crate::TerminalSize;
68
use crate::combine_output_receivers;
79
#[cfg(unix)]
810
use crate::pipe::spawn_process_no_stdin_with_inherited_fds;
@@ -11,18 +13,15 @@ use crate::pty::spawn_process_with_inherited_fds;
1113
use crate::spawn_pipe_process;
1214
use crate::spawn_pipe_process_no_stdin;
1315
use crate::spawn_pty_process;
14-
use crate::SpawnedProcess;
15-
use crate::TerminalSize;
1616

1717
fn find_python() -> Option<String> {
1818
for candidate in ["python3", "python"] {
1919
if let Ok(output) = std::process::Command::new(candidate)
2020
.arg("--version")
2121
.output()
22+
&& output.status.success()
2223
{
23-
if output.status.success() {
24-
return Some(candidate.to_string());
25-
}
24+
return Some(candidate.to_string());
2625
}
2726
}
2827
None
@@ -855,8 +854,7 @@ async fn pty_spawn_with_inherited_fds_supports_resize() -> anyhow::Result<()> {
855854
let write_end = unsafe { std::fs::File::from_raw_fd(fds[1]) };
856855

857856
let env_map: HashMap<String, String> = std::env::vars().collect();
858-
let script =
859-
"stty -echo; printf 'start:%s\\n' \"$(stty size)\"; IFS= read _line; printf 'after:%s\\n' \"$(stty size)\"";
857+
let script = "stty -echo; printf 'start:%s\\n' \"$(stty size)\"; IFS= read _line; printf 'after:%s\\n' \"$(stty size)\"";
860858
let spawned = spawn_process_with_inherited_fds(
861859
"/bin/sh",
862860
&["-c".to_string(), script.to_string()],

codex-rs/utils/pty/src/win/conpty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ use crate::win::psuedocon::PsuedoCon;
2222
use anyhow::Error;
2323
use filedescriptor::FileDescriptor;
2424
use filedescriptor::Pipe;
25-
use portable_pty::cmdbuilder::CommandBuilder;
2625
use portable_pty::Child;
2726
use portable_pty::MasterPty;
2827
use portable_pty::PtyPair;
2928
use portable_pty::PtySize;
3029
use portable_pty::PtySystem;
3130
use portable_pty::SlavePty;
31+
use portable_pty::cmdbuilder::CommandBuilder;
3232
use std::mem::ManuallyDrop;
3333
use std::os::windows::io::AsRawHandle;
3434
use std::os::windows::io::RawHandle;

codex-rs/utils/pty/src/win/mod.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,7 @@ impl Child for WinChild {
142142

143143
fn process_id(&self) -> Option<u32> {
144144
let res = unsafe { GetProcessId(self.proc.lock().unwrap().as_raw_handle() as _) };
145-
if res == 0 {
146-
None
147-
} else {
148-
Some(res)
149-
}
145+
if res == 0 { None } else { Some(res) }
150146
}
151147

152148
fn as_raw_handle(&self) -> Option<std::os::windows::io::RawHandle> {

codex-rs/utils/pty/src/win/procthreadattr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
// SOFTWARE.
2020

2121
use super::psuedocon::HPCON;
22-
use anyhow::ensure;
2322
use anyhow::Error;
23+
use anyhow::ensure;
2424
use std::io::Error as IoError;
2525
use std::mem;
2626
use std::ptr;

codex-rs/utils/pty/src/win/psuedocon.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121

2222
use super::WinChild;
2323
use crate::win::procthreadattr::ProcThreadAttributeList;
24+
use anyhow::Error;
2425
use anyhow::bail;
2526
use anyhow::ensure;
26-
use anyhow::Error;
2727
use filedescriptor::FileDescriptor;
2828
use filedescriptor::OwnedHandle;
2929
use lazy_static::lazy_static;
@@ -356,8 +356,8 @@ fn append_quoted(arg: &OsStr, cmdline: &mut Vec<u16>) {
356356

357357
#[cfg(test)]
358358
mod tests {
359-
use super::windows_build_number;
360359
use super::MIN_CONPTY_BUILD;
360+
use super::windows_build_number;
361361

362362
#[test]
363363
fn windows_build_number_returns_value() {

0 commit comments

Comments
 (0)