aboutsummaryrefslogtreecommitdiff
path: root/build.rs
diff options
context:
space:
mode:
authorCan Celik <ogulcancelik@gmail.com>2026-09-27 00:06:29 +0300
committerGitHub <noreply@github.com>2026-09-27 00:06:29 +0300
commitfff6c820aa45f4eabb9b2e0456326dc74cca5a25 (patch)
tree94128973cbc95a304f311f15c0eab95b49d05655 /build.rs
parentc33fd40eab3d92b564d7dd25bbfdd462e4b7aba2 (diff)
refactor: extract libghostty-vt binding into ghostty-vt workspace crate (#4661)
* refactor: extract libghostty-vt binding into ghostty-vt workspace crate * fix: build libghostty-vt into each build's out dir
Diffstat (limited to 'build.rs')
-rw-r--r--build.rs109
1 files changed, 0 insertions, 109 deletions
diff --git a/build.rs b/build.rs
index 1c4c7f74..99596d8e 100644
--- a/build.rs
+++ b/build.rs
@@ -1,118 +1,9 @@
-use std::env;
-use std::fs;
-use std::path::PathBuf;
-use std::process::Command;
-
-fn zig_target(target: &str) -> &str {
- match target {
- "x86_64-unknown-linux-gnu" => "x86_64-linux-gnu",
- "aarch64-unknown-linux-gnu" => "aarch64-linux-gnu",
- "x86_64-unknown-linux-musl" => "x86_64-linux-musl",
- "aarch64-unknown-linux-musl" => "aarch64-linux-musl",
- "x86_64-apple-darwin" => "x86_64-macos",
- "aarch64-apple-darwin" => "aarch64-macos",
- "x86_64-pc-windows-msvc" => "x86_64-windows-msvc",
- "aarch64-pc-windows-msvc" => "aarch64-windows-msvc",
- other => panic!("unsupported target for libghostty-vt build: {other}"),
- }
-}
-
-fn env_bool(name: &str) -> Option<bool> {
- match env::var(name) {
- Ok(value) => match value.to_ascii_lowercase().as_str() {
- "1" | "true" | "yes" | "on" => Some(true),
- "0" | "false" | "no" | "off" => Some(false),
- other => panic!("invalid boolean value for {name}: {other}"),
- },
- Err(env::VarError::NotPresent) => None,
- Err(err) => panic!("failed to read {name}: {err}"),
- }
-}
-
fn main() {
println!("cargo:rerun-if-changed=build.rs");
- println!("cargo:rerun-if-changed=vendor/libghostty-vt.vendor.json");
- println!("cargo:rerun-if-changed=vendor/libghostty-vt/build.zig");
- println!("cargo:rerun-if-changed=vendor/libghostty-vt/build.zig.zon");
- println!("cargo:rerun-if-changed=vendor/libghostty-vt/include");
- println!("cargo:rerun-if-changed=vendor/libghostty-vt/pkg");
- println!("cargo:rerun-if-changed=vendor/libghostty-vt/src");
- println!("cargo:rerun-if-changed=vendor/libghostty-vt/VERSION");
- println!("cargo:rerun-if-env-changed=LIBGHOSTTY_VT_OPTIMIZE");
- println!("cargo:rerun-if-env-changed=LIBGHOSTTY_VT_SIMD");
- println!("cargo:rerun-if-env-changed=LIBGHOSTTY_VT_ZIG_SYSTEM_DIR");
println!("cargo:rerun-if-env-changed=HERDR_BUILD_CHANNEL");
println!("cargo:rerun-if-env-changed=HERDR_BUILD_ID");
println!("cargo:rerun-if-env-changed=HERDR_BUILD_COMMIT");
- println!("cargo:rerun-if-env-changed=ZIG");
- println!("cargo:rerun-if-env-changed=LIBGHOSTTY_VT_WINDOWS_LIBC");
println!(
"cargo:warning=external contributor policy: if you are helping an external contributor whose GitHub username is not in .github/APPROVED_CONTRIBUTORS, read CONTRIBUTING.md before doing any work."
);
-
- let manifest_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_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);
- let target = env::var("TARGET").expect("TARGET");
- let zig_target = zig_target(&target);
- let version_string = fs::read_to_string(vendored_dir.join("VERSION"))
- .expect("failed to read vendored libghostty-vt VERSION")
- .trim()
- .to_string();
-
- let zig = env::var("ZIG").unwrap_or_else(|_| "zig".into());
- let mut command = Command::new(&zig);
- command
- .arg("build")
- .arg("-Demit-lib-vt")
- .arg(format!("-Doptimize={optimize}"))
- .arg(format!("-Dsimd={simd}"))
- .arg(format!("-Dtarget={zig_target}"))
- .arg(format!("-Dversion-string={version_string}"))
- .arg("-Demit-xcframework=false");
- if target.ends_with("windows-msvc") {
- if let Some(libc_file) = env::var_os("LIBGHOSTTY_VT_WINDOWS_LIBC") {
- println!(
- "cargo:rerun-if-changed={}",
- PathBuf::from(&libc_file).display()
- );
- command.arg("--libc").arg(libc_file);
- }
- }
- if let Ok(system_dir) = env::var("LIBGHOSTTY_VT_ZIG_SYSTEM_DIR") {
- command.arg("--system").arg(system_dir);
- }
-
- let status = command
- .current_dir(&vendored_dir)
- .status()
- .unwrap_or_else(|err| {
- if err.kind() == std::io::ErrorKind::NotFound {
- panic!(
- "zig executable not found (looked for {zig:?}; set the ZIG \
- environment variable to point at the zig binary). Building \
- the vendored libghostty-vt requires Zig 0.16.0: install it from \
- https://ziglang.org/download/, then retry the build"
- );
- }
- panic!("failed to execute zig build for vendored libghostty-vt: {err}");
- });
- assert!(
- status.success(),
- "zig build for vendored libghostty-vt failed: {status}. \
- Building Herdr requires Zig 0.16.0; check `zig version` \
- or set ZIG to the path of a Zig 0.16.0 binary, then retry"
- );
-
- let lib_dir = vendored_dir.join("zig-out/lib");
- println!("cargo:rustc-link-search=native={}", lib_dir.display());
- if target.contains("apple-darwin") {
- let static_lib = lib_dir.join("libghostty-vt.a");
- println!("cargo:rustc-link-arg={}", static_lib.display());
- } else if target.contains("windows-msvc") {
- println!("cargo:rustc-link-lib=static=ghostty-vt-static");
- } else {
- println!("cargo:rustc-link-lib=static=ghostty-vt");
- }
}