Zig treats paths, arguments and environment values as byte slices; the port converted them lossily in many places. Now (final-Z1.md): - argv, env (incl. present non-UTF-8 values), HOME, PATH lookup, passwd, resources dir, TMPDIR, cgroup, config path canonicalization, +validate-config, +list-themes and Zig-string escapes (\xFF) keep raw bytes. String-based config values carry bytes via ghostty_os::osbytes, a bijective escape (noncharacter U+FDD0 + byte) that leaves all valid UTF-8 - including Nerd Font private-use icons - unchanged. - os/file rlimit fallbacks exist on all targets. - i18n locale canonicalization is an exact port of libintl's tables (e.g. pa-Guru -> pa_IN). - New ghostty-build-info crate is the single source of version, channel, commit and build mode for all consumers. Test Plan: - cargo test -p ghostty-os -p ghostty-config -p ghostty-cli (incl. randomized osbytes round-trip property tests)
64 lines
2.5 KiB
Rust
64 lines
2.5 KiB
Rust
//! Build metadata for `+version` and the generated docs.
|
|
//!
|
|
//! * the compiler version (Zig: `builtin.zig_version_string`)
|
|
//!
|
|
//! The app version, channel, commit and build mode live in
|
|
//! `ghostty-build-info` (single source of truth).
|
|
|
|
use std::{
|
|
path::{Path, PathBuf},
|
|
process::Command,
|
|
};
|
|
|
|
/// Generates the per-action help table (Zig: `helpgen.zig` `genActions`):
|
|
/// the doc comment of each action's `run` function becomes
|
|
/// `Action::help_text`.
|
|
fn gen_action_help(manifest_dir: &Path) {
|
|
let ghostty_rs = manifest_dir.join("src/ghostty.rs");
|
|
println!("cargo:rerun-if-changed={}", ghostty_rs.display());
|
|
let src = std::fs::read_to_string(&ghostty_rs).expect("read ghostty.rs");
|
|
let mut table = Vec::new();
|
|
for (variant, _) in ghostty_helpgen::enum_variant_docs(&src, "Action") {
|
|
// `ListFonts` -> `list_fonts` (file name, as Zig `Action.file`).
|
|
let mut file = String::new();
|
|
for (i, c) in variant.chars().enumerate() {
|
|
if c.is_ascii_uppercase() && i > 0 {
|
|
file.push('_');
|
|
}
|
|
file.push(c.to_ascii_lowercase());
|
|
}
|
|
let path = manifest_dir.join(format!("src/{file}.rs"));
|
|
println!("cargo:rerun-if-changed={}", path.display());
|
|
let text = std::fs::read_to_string(&path).expect("read action source");
|
|
let help = ghostty_helpgen::run_fn_doc(&text).unwrap_or_else(|| {
|
|
panic!("doc comment must be present on run function of the {file} action!")
|
|
});
|
|
table.push((variant, help));
|
|
}
|
|
assert!(!table.is_empty(), "no actions found");
|
|
let out = PathBuf::from(std::env::var_os("OUT_DIR").expect("OUT_DIR"));
|
|
std::fs::write(
|
|
out.join("action_help.rs"),
|
|
ghostty_helpgen::cli_help_match(&table),
|
|
)
|
|
.expect("write action_help.rs");
|
|
}
|
|
|
|
fn main() {
|
|
println!("cargo:rerun-if-changed=build.rs");
|
|
gen_action_help(&PathBuf::from(
|
|
std::env::var_os("CARGO_MANIFEST_DIR").unwrap_or_default(),
|
|
));
|
|
println!("cargo:rerun-if-env-changed=RUSTC");
|
|
let rustc = std::env::var("RUSTC").unwrap_or_else(|_| "rustc".into());
|
|
let version = Command::new(rustc)
|
|
.arg("--version")
|
|
.output()
|
|
.ok()
|
|
.and_then(|o| String::from_utf8(o.stdout).ok())
|
|
// "rustc 1.99.0 (b940084d7 2026-09-28)" -> "1.99.0"
|
|
.and_then(|s| s.split_whitespace().nth(1).map(str::to_owned))
|
|
.unwrap_or_else(|| "unknown".into());
|
|
println!("cargo:rustc-env=GHOSTTY_RUSTC_VERSION={version}");
|
|
}
|