fix(os,termio): FreeBSD support, dev-profile resource precedence, docs

Final fix pass per the stopping criterion (docs/rewrite/PLAN.md),
resolving the remaining RV18 build/behaviour items (final-Z21.md):
- termio errno access uses the per-target libc accessor (__error on
  FreeBSD/DragonFly/Apple, __errno on OpenBSD/NetBSD/Android) instead of
  __errno_location everywhere, unblocking non-Linux BSD builds.
- FreeBSD resource discovery follows Zig (site-terminfo, local/share).
- Zig's Debug-only resource precedence (and the dev workspace-resources
  fallback) key off a ghostty_debug_build cfg set from PROFILE=="debug"
  instead of debug_assertions, so release builds with assertions honor
  GHOSTTY_RESOURCES_DIR first like Zig ReleaseSafe.
- KNOWN_DIFFERENCES.md lists the remaining P3 differences deliberately
  left unfixed (theme-preview editing details, a cleanup timeout edge
  case) and what cannot be verified on this machine.
- DEVIANT_FIXES.md registers the PTY-hangup output drain (35), the
  canvas BGRA conversion (36) and the dev resources fallback.

Test Plan:
- cargo test --workspace --no-fail-fast (exit 0)
- cargo check --target x86_64-unknown-freebsd -p ghostty-os
This commit is contained in:
ddidderr committed 2026-10-12 16:53:27 +02:00
1 parent 729b544820
commit 7b59457cb8
6 files changed
+83 -7

No files matched your search

+12
View File
@@ -0,0 +1,12 @@
//! Emits `cfg(ghostty_debug_build)` for the Cargo `dev` profile (Zig
//! `builtin.mode == .Debug`). `debug_assertions` is not equivalent: the
//! repository's `release` profile enables it, like Zig's `ReleaseSafe`.
fn main() {
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-env-changed=PROFILE");
println!("cargo:rustc-check-cfg=cfg(ghostty_debug_build)");
if std::env::var("PROFILE").is_ok_and(|p| p == "debug") {
println!("cargo:rustc-cfg=ghostty_debug_build");
}
}
+16 -5
View File
@@ -48,9 +48,13 @@ impl ResourcesDir {
/// Sentinels we look for in the path to know we've found the resources
/// directory (Linux).
#[cfg(not(any(windows, target_os = "macos")))]
#[cfg(not(any(windows, target_os = "macos", target_os = "freebsd")))]
const SENTINELS: [&str; 2] = ["terminfo/g/ghostty", "terminfo/x/xterm-ghostty"];
/// Sentinels on FreeBSD (`site-terminfo`, like Zig).
#[cfg(target_os = "freebsd")]
const SENTINELS: [&str; 2] = ["site-terminfo/g/ghostty", "site-terminfo/x/xterm-ghostty"];
/// Sentinel on macOS (terminfo directories are named by hex there).
#[cfg(target_os = "macos")]
const SENTINELS: [&str; 1] = ["terminfo/78/xterm-ghostty"];
@@ -66,12 +70,14 @@ const DEV_SENTINELS: [&str; 1] = ["terminfo/x/xterm-ghostty"];
/// Gets the directory to the bundled resources directory, if it
/// exists (not all platforms or packages have it).
///
/// Zig's `builtin.mode == .Debug` is mapped to `cfg!(debug_assertions)`.
/// Zig's `builtin.mode == .Debug` is mapped to the Cargo `dev` profile
/// (`cfg(ghostty_debug_build)`, set by `build.rs`), not to `debug_assertions`:
/// the repository's `release` profile enables assertions like ReleaseSafe.
pub fn resources_dir() -> io::Result<ResourcesDir> {
let exe = std::env::current_exe().ok();
let env = std::env::var_os("GHOSTTY_RESOURCES_DIR");
Ok(resources_dir_impl(
cfg!(debug_assertions),
cfg!(ghostty_debug_build),
exe.as_deref(),
env,
))
@@ -112,9 +118,14 @@ fn resources_dir_impl(debug: bool, exe: Option<&Path>, env: Option<OsString>) ->
}
}
// We look for a /usr/share style path.
// We look for a /usr/share style path (/usr/local/share on FreeBSD).
let share = if cfg!(target_os = "freebsd") {
"local/share"
} else {
"share"
};
for sentinel in SENTINELS {
if let Some(v) = maybe_dir_os(dir, "share", sentinel) {
if let Some(v) = maybe_dir_os(dir, share, sentinel) {
return ResourcesDir {
app_path: Some(enc(&v.join("ghostty"))),
host_path: None,
+20 -2
View File
@@ -546,20 +546,38 @@ fn execvpe(prep: &Prepared, argv: &[*const c_char], envp: &[*const c_char]) -> E
})
}
#[cfg(not(target_vendor = "apple"))]
#[cfg(not(any(
target_vendor = "apple",
target_os = "freebsd",
target_os = "dragonfly",
target_os = "openbsd",
target_os = "netbsd",
target_os = "android"
)))]
#[allow(unsafe_code)]
fn errno_now() -> i32 {
// SAFETY: __errno_location returns a valid thread-local pointer.
unsafe { *libc::__errno_location() }
}
#[cfg(target_vendor = "apple")]
#[cfg(any(
target_vendor = "apple",
target_os = "freebsd",
target_os = "dragonfly"
))]
#[allow(unsafe_code)]
fn errno_now() -> i32 {
// SAFETY: __error returns a valid thread-local pointer.
unsafe { *libc::__error() }
}
#[cfg(any(target_os = "openbsd", target_os = "netbsd", target_os = "android"))]
#[allow(unsafe_code)]
fn errno_now() -> i32 {
// SAFETY: __errno returns a valid thread-local pointer.
unsafe { *libc::__errno() }
}
fn write_stderr(msg: &[u8]) {
// Best effort, no allocation.
let _ = rustix::io::write(borrow_stderr(), msg);