|
1 | 1 | --- a/build.rs |
2 | 2 | +++ b/build.rs |
3 | | -@@ -2,9 +2,9 @@ |
| 3 | +@@ -2,9 +2,10 @@ |
4 | 4 | use bindgen::callbacks::{AttributeInfo, DeriveInfo, ParseCallbacks}; |
| 5 | ++use std::os::unix::fs::{symlink, PermissionsExt}; |
5 | 6 | use std::{ |
6 | 7 | env, |
7 | 8 | - fs::File, |
|
12 | 13 | process::Command, |
13 | 14 | }; |
14 | 15 |
|
15 | | -@@ -203,8 +203,97 @@ |
| 16 | +@@ -203,8 +203,165 @@ |
16 | 17 | let webrtc_build_dir = build_dir.join(BUNDLED_SOURCE_PATH); |
17 | 18 | eprintln!("Building webrtc-audio-processing in {}", webrtc_build_dir.display()); |
18 | 19 |
|
|
29 | 30 | + let mut meson_runfiles = staged_meson.as_os_str().to_owned(); |
30 | 31 | + meson_runfiles.push(".runfiles"); |
31 | 32 | + let _ = fs::remove_file(&meson_runfiles); |
32 | | -+ std::os::unix::fs::symlink(runfiles_dir, &meson_runfiles) |
| 33 | ++ symlink(runfiles_dir, &meson_runfiles) |
33 | 34 | + .context("Failed to link Meson runfiles")?; |
34 | 35 | + |
35 | 36 | + let mut meson = Command::new(staged_meson); |
|
73 | 74 | + } |
74 | 75 | + } |
75 | 76 | + |
| 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 | ++ |
76 | 144 | + if let Ok(ldflags) = env::var("LDFLAGS") { |
77 | 145 | + let mut execroot = build_dir.clone(); |
78 | 146 | + while execroot.file_name().map_or(true, |name| name != "bazel-out") { |
|
104 | 172 | + meson.env("LDFLAGS", ldflags); |
105 | 173 | + } |
106 | 174 | meson.args(["setup", "--prefix", install_dir.to_str().unwrap()]); |
| 175 | ++ meson.env("NINJA", &ninja_launcher); |
107 | 176 | + if let Some(cross_file) = meson_cross_file { |
108 | 177 | + meson.arg("--cross-file"); |
109 | 178 | + meson.arg(cross_file); |
110 | 179 | + } |
111 | 180 | meson.arg("--reconfigure"); |
112 | 181 |
|
113 | 182 | if cfg!(target_os = "macos") { |
114 | | -@@ -221,14 +310,15 @@ |
| 183 | +@@ -221,14 +379,14 @@ |
115 | 184 | .context("Failed to execute meson. Do you have it installed?")?; |
116 | 185 | assert!(status.success(), "Command failed: {:?}", &meson); |
117 | 186 |
|
118 | 187 | - let mut ninja = Command::new("ninja"); |
119 | | -+ let ninja_launcher = env::var_os("NINJA").expect("NINJA is set by Bazel"); |
120 | 188 | + let mut ninja = Command::new(ninja_launcher.clone()); |
121 | 189 | let status = ninja |
122 | 190 | .current_dir(&webrtc_build_dir) |
|
0 commit comments