Skip to content

Commit d0df24a

Browse files
aibrahim-oaicodex
andcommitted
codex: fix CI failure on PR #16806
Co-authored-by: Codex <noreply@openai.com>
1 parent bffd9df commit d0df24a

File tree

2 files changed

+79
-12
lines changed

2 files changed

+79
-12
lines changed

MODULE.bazel

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,6 @@ bazel_dep(name = "meson", version = "1.5.1.bcr.1")
420420
crate.annotation(
421421
build_script_tools = [
422422
"@meson//:meson",
423-
"@@//tools/ninja_wrapper:ninja_wrapper.sh",
424423
"@ninja_1.11.0_linux//:ninja_bin",
425424
"@ninja_1.11.0_mac//:ninja_bin",
426425
"@ninja_1.11.0_win//:ninja_bin",
@@ -429,12 +428,12 @@ crate.annotation(
429428
"MESON": "$(execpath @meson//:meson)",
430429
},
431430
build_script_env_select = {
432-
"aarch64-apple-darwin": "{\"NINJA\":\"$(execpath @@//tools/ninja_wrapper:ninja_wrapper.sh)\",\"NINJA_REAL\":\"$(execpath @ninja_1.11.0_mac//:ninja_bin)\"}",
433-
"x86_64-apple-darwin": "{\"NINJA\":\"$(execpath @@//tools/ninja_wrapper:ninja_wrapper.sh)\",\"NINJA_REAL\":\"$(execpath @ninja_1.11.0_mac//:ninja_bin)\"}",
434-
"aarch64-unknown-linux-gnu": "{\"NINJA\":\"$(execpath @@//tools/ninja_wrapper:ninja_wrapper.sh)\",\"NINJA_REAL\":\"$(execpath @ninja_1.11.0_linux//:ninja_bin)\"}",
435-
"x86_64-unknown-linux-gnu": "{\"NINJA\":\"$(execpath @@//tools/ninja_wrapper:ninja_wrapper.sh)\",\"NINJA_REAL\":\"$(execpath @ninja_1.11.0_linux//:ninja_bin)\"}",
436-
"aarch64-unknown-linux-musl": "{\"NINJA\":\"$(execpath @@//tools/ninja_wrapper:ninja_wrapper.sh)\",\"NINJA_REAL\":\"$(execpath @ninja_1.11.0_linux//:ninja_bin)\"}",
437-
"x86_64-unknown-linux-musl": "{\"NINJA\":\"$(execpath @@//tools/ninja_wrapper:ninja_wrapper.sh)\",\"NINJA_REAL\":\"$(execpath @ninja_1.11.0_linux//:ninja_bin)\"}",
431+
"aarch64-apple-darwin": "{\"NINJA_REAL\":\"$(execpath @ninja_1.11.0_linux//:ninja_bin)\"}",
432+
"x86_64-apple-darwin": "{\"NINJA_REAL\":\"$(execpath @ninja_1.11.0_linux//:ninja_bin)\"}",
433+
"aarch64-unknown-linux-gnu": "{\"NINJA_REAL\":\"$(execpath @ninja_1.11.0_linux//:ninja_bin)\"}",
434+
"x86_64-unknown-linux-gnu": "{\"NINJA_REAL\":\"$(execpath @ninja_1.11.0_linux//:ninja_bin)\"}",
435+
"aarch64-unknown-linux-musl": "{\"NINJA_REAL\":\"$(execpath @ninja_1.11.0_linux//:ninja_bin)\"}",
436+
"x86_64-unknown-linux-musl": "{\"NINJA_REAL\":\"$(execpath @ninja_1.11.0_linux//:ninja_bin)\"}",
438437
"aarch64-pc-windows-msvc": "{\"NINJA\":\"$(execpath @ninja_1.11.0_win//:ninja_bin)\"}",
439438
"x86_64-pc-windows-msvc": "{\"NINJA\":\"$(execpath @ninja_1.11.0_win//:ninja_bin)\"}",
440439
"aarch64-pc-windows-gnullvm": "{\"NINJA\":\"$(execpath @ninja_1.11.0_win//:ninja_bin)\"}",

patches/webrtc-audio-processing-sys_meson_env.patch

Lines changed: 73 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
--- a/build.rs
22
+++ b/build.rs
3-
@@ -2,9 +2,9 @@
3+
@@ -2,9 +2,10 @@
44
use bindgen::callbacks::{AttributeInfo, DeriveInfo, ParseCallbacks};
5+
+use std::os::unix::fs::{symlink, PermissionsExt};
56
use std::{
67
env,
78
- fs::File,
@@ -12,7 +13,7 @@
1213
process::Command,
1314
};
1415

15-
@@ -203,8 +203,97 @@
16+
@@ -203,8 +203,165 @@
1617
let webrtc_build_dir = build_dir.join(BUNDLED_SOURCE_PATH);
1718
eprintln!("Building webrtc-audio-processing in {}", webrtc_build_dir.display());
1819

@@ -29,7 +30,7 @@
2930
+ let mut meson_runfiles = staged_meson.as_os_str().to_owned();
3031
+ meson_runfiles.push(".runfiles");
3132
+ let _ = fs::remove_file(&meson_runfiles);
32-
+ std::os::unix::fs::symlink(runfiles_dir, &meson_runfiles)
33+
+ symlink(runfiles_dir, &meson_runfiles)
3334
+ .context("Failed to link Meson runfiles")?;
3435
+
3536
+ let mut meson = Command::new(staged_meson);
@@ -73,6 +74,73 @@
7374
+ }
7475
+ }
7576
+
77+
+ let mut ninja_launcher = env::var_os("NINJA");
78+
+ if let Some(ninja_real) = env::var_os("NINJA_REAL") {
79+
+ let mut temp_dirs = Vec::new();
80+
+ if let Some(dir) = env::var_os("CODEX_NINJA_TMPDIR") {
81+
+ temp_dirs.push(PathBuf::from(dir));
82+
+ }
83+
+ temp_dirs.extend([
84+
+ PathBuf::from("/private/var/tmp"),
85+
+ PathBuf::from("/var/tmp"),
86+
+ env::temp_dir(),
87+
+ PathBuf::from("/tmp"),
88+
+ ]);
89+
+ if let Some(home) = env::var_os("HOME") {
90+
+ temp_dirs.push(PathBuf::from(home));
91+
+ }
92+
+
93+
+ let mut staged_ninja = None;
94+
+ for (attempt, temp_dir) in temp_dirs.into_iter().enumerate() {
95+
+ if !temp_dir.is_dir() {
96+
+ continue;
97+
+ }
98+
+
99+
+ let stage_dir = temp_dir.join(format!(
100+
+ "codex-ninja-{}-{attempt}",
101+
+ std::process::id()
102+
+ ));
103+
+ let _ = fs::remove_dir_all(&stage_dir);
104+
+ if fs::create_dir_all(&stage_dir).is_err() {
105+
+ continue;
106+
+ }
107+
+
108+
+ let candidate_ninja = stage_dir.join("ninja");
109+
+ let stage_result = fs::copy(&ninja_real, &candidate_ninja)
110+
+ .and_then(|_| {
111+
+ let mut permissions =
112+
+ fs::metadata(&candidate_ninja)?.permissions();
113+
+ permissions.set_mode(0o755);
114+
+ fs::set_permissions(&candidate_ninja, permissions)
115+
+ });
116+
+ if stage_result.is_err() {
117+
+ let _ = fs::remove_dir_all(&stage_dir);
118+
+ continue;
119+
+ }
120+
+
121+
+ let can_execute = Command::new(&candidate_ninja)
122+
+ .arg("--version")
123+
+ .status()
124+
+ .map(|status| status.success())
125+
+ .unwrap_or(false);
126+
+ if can_execute {
127+
+ staged_ninja = Some(candidate_ninja);
128+
+ break;
129+
+ }
130+
+
131+
+ let _ = fs::remove_dir_all(&stage_dir);
132+
+ }
133+
+
134+
+ let staged_ninja = staged_ninja.with_context(|| {
135+
+ format!(
136+
+ "Failed to stage executable Ninja from {}",
137+
+ Path::new(&ninja_real).display()
138+
+ )
139+
+ })?;
140+
+ ninja_launcher = Some(staged_ninja.into_os_string());
141+
+ }
142+
+ let ninja_launcher = ninja_launcher.expect("NINJA or NINJA_REAL is set by Bazel");
143+
+
76144
+ if let Ok(ldflags) = env::var("LDFLAGS") {
77145
+ let mut execroot = build_dir.clone();
78146
+ while execroot.file_name().map_or(true, |name| name != "bazel-out") {
@@ -104,19 +172,19 @@
104172
+ meson.env("LDFLAGS", ldflags);
105173
+ }
106174
meson.args(["setup", "--prefix", install_dir.to_str().unwrap()]);
175+
+ meson.env("NINJA", &ninja_launcher);
107176
+ if let Some(cross_file) = meson_cross_file {
108177
+ meson.arg("--cross-file");
109178
+ meson.arg(cross_file);
110179
+ }
111180
meson.arg("--reconfigure");
112181

113182
if cfg!(target_os = "macos") {
114-
@@ -221,14 +310,15 @@
183+
@@ -221,14 +379,14 @@
115184
.context("Failed to execute meson. Do you have it installed?")?;
116185
assert!(status.success(), "Command failed: {:?}", &meson);
117186

118187
- let mut ninja = Command::new("ninja");
119-
+ let ninja_launcher = env::var_os("NINJA").expect("NINJA is set by Bazel");
120188
+ let mut ninja = Command::new(ninja_launcher.clone());
121189
let status = ninja
122190
.current_dir(&webrtc_build_dir)

0 commit comments

Comments
 (0)