aboutsummaryrefslogtreecommitdiff
path: root/build.rs
diff options
context:
space:
mode:
authorOgulcan Celik <ogulcancelik@gmail.com>2026-05-07 18:29:21 +0300
committerOgulcan Celik <ogulcancelik@gmail.com>2026-05-07 18:29:21 +0300
commitdcfe11a7588fcd42471159453810abc9b7720a57 (patch)
treec32a77266028e73ca2382b96c96f8438a5fcd621 /build.rs
parent2dfed860103c4e4505ac7f25def9fe37da1e1e6a (diff)
build: update libghostty-vt vendor
vendor ghostty 063ac3e and remove the musl libc++ link workaround. expose the new selection formatter and hyperlink uri apis for follow-up rendering work. add manual artifact validation for static linux builds.
Diffstat (limited to 'build.rs')
-rw-r--r--build.rs99
1 files changed, 1 insertions, 98 deletions
diff --git a/build.rs b/build.rs
index b61d88ac..c68d420a 100644
--- a/build.rs
+++ b/build.rs
@@ -1,6 +1,6 @@
use std::env;
use std::fs;
-use std::path::{Path, PathBuf};
+use std::path::PathBuf;
use std::process::Command;
fn zig_target(target: &str) -> &str {
@@ -27,75 +27,6 @@ fn env_bool(name: &str) -> Option<bool> {
}
}
-/// Extract the final archive path for a named Zig runtime archive from
-/// verbose compiler/linker output.
-fn find_archive_path(output: &str, archive_name: &str) -> Option<PathBuf> {
- output
- .split_whitespace()
- .map(|token| token.trim_matches(|c| matches!(c, '"' | '\'')))
- .filter(|token| token.ends_with(archive_name) && token.contains('/'))
- .map(PathBuf::from)
- .last()
-}
-
-/// Ask Zig which musl-compatible C++ runtime archives it would use for a
-/// trivial target build.
-///
-/// This is necessary because `cargo:rustc-link-lib=stdc++` on a musl target
-/// resolves through the host toolchain and produces a mixed musl/glibc binary,
-/// while Zig's musl C++ driver resolves to its bundled libc++/libc++abi
-/// archives.
-fn zig_musl_cpp_runtime_archives(out_dir: &Path, zig_target: &str) -> (PathBuf, PathBuf) {
- let probe_dir = out_dir.join("zig-cpp-runtime-probe");
- fs::create_dir_all(&probe_dir).expect("failed to create Zig C++ runtime probe dir");
-
- let source = probe_dir.join("probe.cpp");
- fs::write(&source, "int main() { return 0; }\n")
- .expect("failed to write Zig C++ runtime probe source");
-
- let binary = probe_dir.join("probe");
- let local_cache = probe_dir.join("local-cache");
- let global_cache = probe_dir.join("global-cache");
-
- let output = Command::new("zig")
- .arg("c++")
- .arg("-target")
- .arg(zig_target)
- .arg("-v")
- .arg(&source)
- .arg("-o")
- .arg(&binary)
- .env("ZIG_LOCAL_CACHE_DIR", &local_cache)
- .env("ZIG_GLOBAL_CACHE_DIR", &global_cache)
- .output()
- .expect("failed to execute Zig C++ runtime probe");
-
- let stdout = String::from_utf8_lossy(&output.stdout);
- let stderr = String::from_utf8_lossy(&output.stderr);
- let combined = format!("{stdout}\n{stderr}");
-
- assert!(
- output.status.success(),
- "Zig C++ runtime probe failed: {}\nstdout:\n{}\nstderr:\n{}",
- output.status,
- stdout,
- stderr
- );
-
- let libcxxabi = find_archive_path(&combined, "libc++abi.a").unwrap_or_else(|| {
- panic!(
- "failed to locate Zig musl libc++abi archive path for target {zig_target}; zig output was:\n{combined}"
- )
- });
- let libcxx = find_archive_path(&combined, "libc++.a").unwrap_or_else(|| {
- panic!(
- "failed to locate Zig musl libc++ archive path for target {zig_target}; zig output was:\n{combined}"
- )
- });
-
- (libcxxabi, libcxx)
-}
-
fn main() {
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=vendor/libghostty-vt.vendor.json");
@@ -106,7 +37,6 @@ fn main() {
println!("cargo:rerun-if-env-changed=LIBGHOSTTY_VT_SIMD");
let manifest_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR"));
- let out_dir = PathBuf::from(env::var("OUT_DIR").expect("OUT_DIR"));
let vendored_dir = manifest_dir.join("vendor/libghostty-vt");
let optimize = env::var("LIBGHOSTTY_VT_OPTIMIZE").unwrap_or_else(|_| "ReleaseFast".into());
let simd = env_bool("LIBGHOSTTY_VT_SIMD").unwrap_or(true);
@@ -137,34 +67,7 @@ fn main() {
if target.contains("apple-darwin") {
let static_lib = lib_dir.join("libghostty-vt.a");
println!("cargo:rustc-link-arg={}", static_lib.display());
- if simd {
- println!("cargo:rustc-link-lib=dylib=c++");
- }
} else {
println!("cargo:rustc-link-lib=static=ghostty-vt");
- if target.contains("linux") && simd {
- if target.contains("musl") {
- // Keep musl SIMD builds entirely in Zig's musl/libc++ runtime
- // world. Asking Cargo to link `stdc++` here resolves through the
- // host toolchain and reintroduces the crashing mixed-runtime
- // artifact shape.
- let (libcxxabi, libcxx) = zig_musl_cpp_runtime_archives(&out_dir, zig_target);
- let libcxxabi_dir = libcxxabi
- .parent()
- .expect("libc++abi archive should have a parent dir");
- let libcxx_dir = libcxx
- .parent()
- .expect("libc++ archive should have a parent dir");
-
- println!("cargo:rustc-link-search=native={}", libcxxabi_dir.display());
- if libcxx_dir != libcxxabi_dir {
- println!("cargo:rustc-link-search=native={}", libcxx_dir.display());
- }
- println!("cargo:rustc-link-lib=static=c++abi");
- println!("cargo:rustc-link-lib=static=c++");
- } else {
- println!("cargo:rustc-link-lib=dylib=stdc++");
- }
- }
}
}