mirror of
https://github.com/openai/codex.git
synced 2026-04-28 02:11:08 +03:00
Fix Bazel Ninja launcher for realtime audio build script
Co-authored-by: Codex <noreply@openai.com>
This commit is contained in:
@@ -369,11 +369,11 @@ bazel_dep(name = "meson", version = "1.5.1.bcr.1")
|
||||
crate.annotation(
|
||||
build_script_tools = [
|
||||
"@meson//:meson",
|
||||
"@rules_foreign_cc//toolchains/private:ninja_tool",
|
||||
"//tools/ninja_wrapper:ninja",
|
||||
],
|
||||
build_script_env = {
|
||||
"MESON": "$(execpath @meson//:meson)",
|
||||
"NINJA": "$(execpath @rules_foreign_cc//toolchains/private:ninja_tool)/bin/ninja",
|
||||
"NINJA": "$(execpath //tools/ninja_wrapper:ninja)",
|
||||
},
|
||||
crate = "webrtc-audio-processing-sys",
|
||||
gen_build_script = "on",
|
||||
@@ -384,7 +384,6 @@ crate.annotation(
|
||||
)
|
||||
|
||||
inject_repo(crate, "meson")
|
||||
inject_repo(crate, "rules_foreign_cc")
|
||||
|
||||
bazel_dep(name = "v8", version = "14.6.202.9")
|
||||
archive_override(
|
||||
|
||||
11
tools/ninja_wrapper/BUILD.bazel
Normal file
11
tools/ninja_wrapper/BUILD.bazel
Normal file
@@ -0,0 +1,11 @@
|
||||
load("@rules_rust//rust:defs.bzl", "rust_binary")
|
||||
|
||||
rust_binary(
|
||||
name = "ninja",
|
||||
crate_name = "ninja_wrapper",
|
||||
crate_root = "main.rs",
|
||||
srcs = ["main.rs"],
|
||||
edition = "2021",
|
||||
tags = ["manual"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
115
tools/ninja_wrapper/main.rs
Normal file
115
tools/ninja_wrapper/main.rs
Normal file
@@ -0,0 +1,115 @@
|
||||
use std::env;
|
||||
use std::ffi::OsString;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
use std::process::ExitCode;
|
||||
|
||||
fn main() -> ExitCode {
|
||||
let args: Vec<OsString> = env::args_os().skip(1).collect();
|
||||
let Some(ninja) = find_ninja() else {
|
||||
eprintln!("unable to locate ninja");
|
||||
return ExitCode::from(127);
|
||||
};
|
||||
|
||||
let status = match Command::new(&ninja).args(&args).status() {
|
||||
Ok(status) => status,
|
||||
Err(err) => {
|
||||
eprintln!("failed to launch {}: {err}", ninja.display());
|
||||
return ExitCode::from(127);
|
||||
}
|
||||
};
|
||||
|
||||
status
|
||||
.code()
|
||||
.and_then(|code| u8::try_from(code).ok())
|
||||
.map_or(ExitCode::FAILURE, ExitCode::from)
|
||||
}
|
||||
|
||||
fn find_ninja() -> Option<PathBuf> {
|
||||
path_ninja().or_else(common_ninja)
|
||||
}
|
||||
|
||||
fn path_ninja() -> Option<PathBuf> {
|
||||
let path = env::var_os("PATH")?;
|
||||
for directory in env::split_paths(&path) {
|
||||
for binary in binary_names() {
|
||||
let candidate = directory.join(binary);
|
||||
if candidate.is_file() {
|
||||
return Some(candidate);
|
||||
}
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
fn common_ninja() -> Option<PathBuf> {
|
||||
for env_var in ["ProgramFiles", "ProgramFiles(x86)"] {
|
||||
let Some(root) = env::var_os(env_var) else {
|
||||
continue;
|
||||
};
|
||||
for edition in ["Enterprise", "Professional", "BuildTools"] {
|
||||
let candidate = PathBuf::from(&root)
|
||||
.join("Microsoft Visual Studio")
|
||||
.join("2022")
|
||||
.join(edition)
|
||||
.join("Common7")
|
||||
.join("IDE")
|
||||
.join("CommonExtensions")
|
||||
.join("Microsoft")
|
||||
.join("CMake")
|
||||
.join("Ninja")
|
||||
.join("ninja.exe");
|
||||
if candidate.is_file() {
|
||||
return Some(candidate);
|
||||
}
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
fn common_ninja() -> Option<PathBuf> {
|
||||
for candidate in [
|
||||
PathBuf::from("/usr/bin/ninja"),
|
||||
PathBuf::from("/bin/ninja"),
|
||||
PathBuf::from("/usr/local/bin/ninja"),
|
||||
PathBuf::from("/opt/homebrew/bin/ninja"),
|
||||
] {
|
||||
if candidate.is_file() {
|
||||
return Some(candidate);
|
||||
}
|
||||
}
|
||||
|
||||
let output = Command::new("xcrun").args(["-f", "ninja"]).output().ok()?;
|
||||
if !output.status.success() {
|
||||
return None;
|
||||
}
|
||||
let resolved = String::from_utf8(output.stdout).ok()?;
|
||||
let candidate = PathBuf::from(resolved.trim());
|
||||
candidate.is_file().then_some(candidate)
|
||||
}
|
||||
|
||||
#[cfg(all(unix, not(target_os = "macos")))]
|
||||
fn common_ninja() -> Option<PathBuf> {
|
||||
for candidate in [
|
||||
PathBuf::from("/usr/bin/ninja"),
|
||||
PathBuf::from("/bin/ninja"),
|
||||
PathBuf::from("/usr/local/bin/ninja"),
|
||||
] {
|
||||
if candidate.is_file() {
|
||||
return Some(candidate);
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
fn binary_names() -> &'static [&'static str] {
|
||||
&["ninja.exe"]
|
||||
}
|
||||
|
||||
#[cfg(not(windows))]
|
||||
fn binary_names() -> &'static [&'static str] {
|
||||
&["ninja"]
|
||||
}
|
||||
Reference in New Issue
Block a user