Rinomina: crate akode-*, cartelle akode-rs/ e akode-cli/, binario akode, ~/.akode, AKODE_* (A)
Riapplica la fase 5 di aKode (86e7c72e) sulla base ripulita:
- crate codex-* -> akode-*, codex-rs -> akode-rs, codex-cli -> akode-cli, binario e ausiliari akode;
- ~/.codex -> ~/.akode, CODEX_HOME -> AKODE_HOME, variabili CODEX_* -> AKODE_*, .codex/ -> .akode/ di progetto;
nessun fallback a ~/.codex o a CODEX_*;
- testi per l'utente "Codex" -> "aKode"; testi verso il modello e istruzioni di sistema invariati;
- snapshot insta rinominati (non ancora rigenerati).
I conflitti con la base ripulita sono stati risolti riapplicando la rinomina ai file senza le
funzioni di imeAI (script di mappa dei token per file).
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
73
akode-rs/bwrap/BUILD.bazel
Normal file
73
akode-rs/bwrap/BUILD.bazel
Normal file
@@ -0,0 +1,73 @@
|
||||
load("@rules_cc//cc:defs.bzl", "cc_library")
|
||||
load("//:defs.bzl", "codex_rust_crate")
|
||||
load("//bazel/rules:runtime_package.bzl", "release_binary")
|
||||
|
||||
codex_rust_crate(
|
||||
name = "bwrap",
|
||||
# Bazel wires vendored bubblewrap + libcap via :bwrap-ffi below and sets
|
||||
# bwrap_available explicitly, so we skip Cargo's build.rs in Bazel builds.
|
||||
build_script_enabled = False,
|
||||
crate_name = "codex_bwrap",
|
||||
deps_extra = select({
|
||||
"@platforms//os:linux": [":bwrap-ffi"],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
rustc_flags_extra = select({
|
||||
"@platforms//os:linux": [
|
||||
"--cfg=bwrap_available",
|
||||
# TODO(anp) Extract bwrap symbols before stripping.
|
||||
"-Cstrip=symbols",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
)
|
||||
|
||||
release_binary(
|
||||
binary = ":bwrap",
|
||||
target_compatible_with = ["@platforms//os:linux"],
|
||||
)
|
||||
|
||||
genrule(
|
||||
name = "bwrap-sha256-env",
|
||||
srcs = [":bwrap"],
|
||||
outs = ["bwrap.sha256.env"],
|
||||
cmd = " && ".join([
|
||||
'$(execpath @bazel_tools//tools/build_defs/hash:sha256) $(execpath :bwrap) "$@"',
|
||||
'digest=$$(<"$@")',
|
||||
'printf "AKODE_BWRAP_SHA256=%s\\n" "$$digest" > "$@"',
|
||||
]),
|
||||
target_compatible_with = ["@platforms//os:linux"],
|
||||
tools = ["@bazel_tools//tools/build_defs/hash:sha256"],
|
||||
visibility = ["//akode-rs/linux-sandbox:__pkg__"],
|
||||
)
|
||||
|
||||
config_setting(
|
||||
name = "optimized",
|
||||
values = {"compilation_mode": "opt"},
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "bwrap-ffi",
|
||||
srcs = ["//akode-rs/vendor:bubblewrap_c_sources"],
|
||||
hdrs = [
|
||||
"config.h",
|
||||
"//akode-rs/vendor:bubblewrap_headers",
|
||||
],
|
||||
copts = [
|
||||
"-D_GNU_SOURCE",
|
||||
"-Dmain=bwrap_main",
|
||||
] + select({
|
||||
# Cargo cc-rs uses release OPT_LEVEL=3 and DEBUG=true, without
|
||||
# the C toolchain's default NDEBUG; retain native symbols for packaging.
|
||||
":optimized": [
|
||||
"-O3",
|
||||
"-g",
|
||||
"-UNDEBUG",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
includes = ["."],
|
||||
target_compatible_with = ["@platforms//os:linux"],
|
||||
visibility = ["//visibility:private"],
|
||||
deps = ["@libcap"],
|
||||
)
|
||||
19
akode-rs/bwrap/Cargo.toml
Normal file
19
akode-rs/bwrap/Cargo.toml
Normal file
@@ -0,0 +1,19 @@
|
||||
[package]
|
||||
name = "akode-bwrap"
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
|
||||
[[bin]]
|
||||
name = "bwrap"
|
||||
path = "src/main.rs"
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
[target.'cfg(target_os = "linux")'.dependencies]
|
||||
libc = { workspace = true }
|
||||
|
||||
[build-dependencies]
|
||||
cc = "1"
|
||||
pkg-config = "0.3"
|
||||
106
akode-rs/bwrap/build.rs
Normal file
106
akode-rs/bwrap/build.rs
Normal file
@@ -0,0 +1,106 @@
|
||||
use std::env;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
|
||||
fn main() {
|
||||
println!("cargo:rustc-check-cfg=cfg(bwrap_available)");
|
||||
println!("cargo:rerun-if-env-changed=AKODE_BWRAP_SOURCE_DIR");
|
||||
println!("cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS");
|
||||
println!("cargo:rerun-if-env-changed=PKG_CONFIG_PATH");
|
||||
println!("cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR");
|
||||
println!("cargo:rerun-if-env-changed=AKODE_SKIP_BWRAP_BUILD");
|
||||
|
||||
let manifest_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap_or_default());
|
||||
let vendor_dir = manifest_dir.join("../vendor/bubblewrap");
|
||||
for source in ["bubblewrap.c", "bind-mount.c", "network.c", "utils.c"] {
|
||||
println!(
|
||||
"cargo:rerun-if-changed={}",
|
||||
vendor_dir.join(source).display()
|
||||
);
|
||||
}
|
||||
|
||||
let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap_or_default();
|
||||
if target_os != "linux" || env::var_os("AKODE_SKIP_BWRAP_BUILD").is_some() {
|
||||
return;
|
||||
}
|
||||
|
||||
if let Err(err) = try_build_bwrap() {
|
||||
panic!("failed to compile bubblewrap for Linux target: {err}");
|
||||
}
|
||||
}
|
||||
|
||||
fn try_build_bwrap() -> Result<(), String> {
|
||||
let manifest_dir =
|
||||
PathBuf::from(env::var("CARGO_MANIFEST_DIR").map_err(|err| err.to_string())?);
|
||||
let out_dir = PathBuf::from(env::var("OUT_DIR").map_err(|err| err.to_string())?);
|
||||
let src_dir = resolve_bwrap_source_dir(&manifest_dir)?;
|
||||
let libcap = pkg_config::Config::new()
|
||||
.cargo_metadata(false)
|
||||
.probe("libcap")
|
||||
.map_err(|err| format!("libcap not available via pkg-config: {err}"))?;
|
||||
|
||||
let config_h = out_dir.join("config.h");
|
||||
std::fs::write(
|
||||
&config_h,
|
||||
r#"#pragma once
|
||||
#define PACKAGE_STRING "bubblewrap built for Codex"
|
||||
"#,
|
||||
)
|
||||
.map_err(|err| format!("failed to write {}: {err}", config_h.display()))?;
|
||||
|
||||
let mut build = cc::Build::new();
|
||||
build
|
||||
.file(src_dir.join("bubblewrap.c"))
|
||||
.file(src_dir.join("bind-mount.c"))
|
||||
.file(src_dir.join("network.c"))
|
||||
.file(src_dir.join("utils.c"))
|
||||
.include(&out_dir)
|
||||
.include(&src_dir)
|
||||
.define("_GNU_SOURCE", None)
|
||||
// Rename `main` so the Rust wrapper can expose the Cargo-built binary.
|
||||
.define("main", Some("bwrap_main"));
|
||||
for include_path in libcap.include_paths {
|
||||
// Use -idirafter so target sysroot headers win (musl cross builds),
|
||||
// while still allowing libcap headers from the host toolchain.
|
||||
build.flag(format!("-idirafter{}", include_path.display()));
|
||||
}
|
||||
|
||||
build.compile("standalone_bwrap");
|
||||
for link_path in libcap.link_paths {
|
||||
println!("cargo:rustc-link-search=native={}", link_path.display());
|
||||
}
|
||||
for lib in libcap.libs {
|
||||
println!("cargo:rustc-link-lib={lib}");
|
||||
}
|
||||
println!("cargo:rustc-cfg=bwrap_available");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Resolve the bubblewrap source directory used for build-time compilation.
|
||||
///
|
||||
/// Priority:
|
||||
/// 1. `AKODE_BWRAP_SOURCE_DIR` points at an existing bubblewrap checkout.
|
||||
/// 2. The vendored bubblewrap tree under `akode-rs/vendor/bubblewrap`.
|
||||
fn resolve_bwrap_source_dir(manifest_dir: &Path) -> Result<PathBuf, String> {
|
||||
if let Ok(path) = env::var("AKODE_BWRAP_SOURCE_DIR") {
|
||||
let src_dir = PathBuf::from(path);
|
||||
if src_dir.exists() {
|
||||
return Ok(src_dir);
|
||||
}
|
||||
return Err(format!(
|
||||
"AKODE_BWRAP_SOURCE_DIR was set but does not exist: {}",
|
||||
src_dir.display()
|
||||
));
|
||||
}
|
||||
|
||||
let vendor_dir = manifest_dir.join("../vendor/bubblewrap");
|
||||
if vendor_dir.exists() {
|
||||
return Ok(vendor_dir);
|
||||
}
|
||||
|
||||
Err(format!(
|
||||
"expected vendored bubblewrap at {}, but it was not found.\n\
|
||||
Set AKODE_BWRAP_SOURCE_DIR to an existing checkout or vendor bubblewrap under akode-rs/vendor.",
|
||||
vendor_dir.display()
|
||||
))
|
||||
}
|
||||
1
akode-rs/bwrap/config.h
Normal file
1
akode-rs/bwrap/config.h
Normal file
@@ -0,0 +1 @@
|
||||
#define PACKAGE_STRING "bubblewrap built for Codex"
|
||||
45
akode-rs/bwrap/src/main.rs
Normal file
45
akode-rs/bwrap/src/main.rs
Normal file
@@ -0,0 +1,45 @@
|
||||
#[cfg(all(target_os = "linux", bwrap_available))]
|
||||
fn main() {
|
||||
use std::ffi::CStr;
|
||||
use std::ffi::CString;
|
||||
use std::os::raw::c_char;
|
||||
use std::os::unix::ffi::OsStrExt;
|
||||
|
||||
unsafe extern "C" {
|
||||
fn bwrap_main(argc: libc::c_int, argv: *const *const c_char) -> libc::c_int;
|
||||
}
|
||||
|
||||
let cstrings = std::env::args_os()
|
||||
.map(|arg| {
|
||||
CString::new(arg.as_os_str().as_bytes())
|
||||
.unwrap_or_else(|err| panic!("failed to convert argv to CString: {err}"))
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
let mut argv_ptrs = cstrings
|
||||
.iter()
|
||||
.map(CString::as_c_str)
|
||||
.map(CStr::as_ptr)
|
||||
.collect::<Vec<*const c_char>>();
|
||||
argv_ptrs.push(std::ptr::null());
|
||||
|
||||
// SAFETY: We provide a null-terminated argv vector whose pointers remain
|
||||
// valid for the duration of the call.
|
||||
let exit_code = unsafe { bwrap_main(cstrings.len() as libc::c_int, argv_ptrs.as_ptr()) };
|
||||
std::process::exit(exit_code);
|
||||
}
|
||||
|
||||
#[cfg(all(target_os = "linux", not(bwrap_available)))]
|
||||
fn main() {
|
||||
panic!(
|
||||
r#"bubblewrap is not available in this build.
|
||||
Notes:
|
||||
- ensure the target OS is Linux
|
||||
- libcap headers must be available via pkg-config
|
||||
- bubblewrap sources expected at akode-rs/vendor/bubblewrap (default)"#
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
fn main() {
|
||||
panic!("bwrap is only supported on Linux");
|
||||
}
|
||||
Reference in New Issue
Block a user