diff --git a/Cargo.lock b/Cargo.lock index 3961e96ab..25985c754 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -846,7 +846,6 @@ dependencies = [ "dirs-next", "enum-display-derive", "env_logger", - "git2", "hostname", "lazy_static", "libc", @@ -855,6 +854,7 @@ dependencies = [ "mlua", "nix 0.26.2", "notify", + "once_cell", "ordered-float", "portable-pty", "promise", @@ -1482,6 +1482,7 @@ dependencies = [ "termwiz", "termwiz-funcs", "time-funcs", + "wezterm-version", "winapi", ] @@ -6256,6 +6257,13 @@ dependencies = [ "zvariant", ] +[[package]] +name = "wezterm-version" +version = "0.1.0" +dependencies = [ + "git2", +] + [[package]] name = "wgpu" version = "0.15.1" diff --git a/config/Cargo.toml b/config/Cargo.toml index 310a98e52..856979700 100644 --- a/config/Cargo.toml +++ b/config/Cargo.toml @@ -3,16 +3,12 @@ name = "config" version = "0.1.0" authors = ["Wez Furlong "] edition = "2018" -build = "build.rs" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dev-dependencies] env_logger = "0.10" -[build-dependencies] -git2 = { version = "0.16", default-features = false } - [features] distro-defaults = [] @@ -30,6 +26,7 @@ luahelper = { path = "../luahelper" } mlua = {version="0.8.3", features=["vendored", "lua54", "async", "send"]} # file change notification notify = "5.0.0" +once_cell = "1.8" ordered-float = { version = "3.0", features = ["serde"] } portable-pty = { path = "../pty", features = ["serde_support"]} promise = { path = "../promise" } diff --git a/config/src/version.rs b/config/src/version.rs index aa672f229..dc4f7fc2d 100644 --- a/config/src/version.rs +++ b/config/src/version.rs @@ -1,11 +1,23 @@ +use once_cell::sync::OnceCell; + +static VERSION: OnceCell<&'static str> = OnceCell::new(); +static TRIPLE: OnceCell<&'static str> = OnceCell::new(); + +pub fn assign_version_info(version: &'static str, triple: &'static str) { + VERSION.set(version).unwrap(); + TRIPLE.set(triple).unwrap(); +} + pub fn wezterm_version() -> &'static str { - // See build.rs - env!("WEZTERM_CI_TAG") + VERSION + .get() + .unwrap_or(&"someone forgot to call assign_version_info") } pub fn wezterm_target_triple() -> &'static str { - // See build.rs - env!("WEZTERM_TARGET_TRIPLE") + TRIPLE + .get() + .unwrap_or(&"someone forgot to call assign_version_info") } pub fn running_under_wsl() -> bool { diff --git a/env-bootstrap/Cargo.toml b/env-bootstrap/Cargo.toml index b6b85f031..1281bcacd 100644 --- a/env-bootstrap/Cargo.toml +++ b/env-bootstrap/Cargo.toml @@ -29,6 +29,7 @@ share-data = { path = "../lua-api-crates/share-data" } ssh-funcs = { path = "../lua-api-crates/ssh-funcs" } spawn-funcs = { path = "../lua-api-crates/spawn-funcs" } time-funcs = { path = "../lua-api-crates/time-funcs" } +wezterm-version = { path = "../wezterm-version" } [target."cfg(windows)".dependencies] winapi = "0.3" diff --git a/env-bootstrap/src/lib.rs b/env-bootstrap/src/lib.rs index 286c99bbc..c24f12f32 100644 --- a/env-bootstrap/src/lib.rs +++ b/env-bootstrap/src/lib.rs @@ -184,6 +184,10 @@ fn register_lua_modules() { } pub fn bootstrap() { + config::assign_version_info( + wezterm_version::wezterm_version(), + wezterm_version::wezterm_target_triple(), + ); setup_logger(); register_panic_hook(); diff --git a/wezterm-version/Cargo.toml b/wezterm-version/Cargo.toml new file mode 100644 index 000000000..a1279d521 --- /dev/null +++ b/wezterm-version/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "wezterm-version" +version = "0.1.0" +edition = "2021" +build = "build.rs" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[build-dependencies] +git2 = { version = "0.16", default-features = false } + +[dependencies] diff --git a/config/build.rs b/wezterm-version/build.rs similarity index 86% rename from config/build.rs rename to wezterm-version/build.rs index 9a029c51f..23b11e0f9 100644 --- a/config/build.rs +++ b/wezterm-version/build.rs @@ -1,5 +1,3 @@ -use std::path::Path; - fn main() { println!("cargo:rerun-if-changed=build.rs"); @@ -30,12 +28,7 @@ fn main() { } } } - } - let head = Path::new("../.git/HEAD"); - if head.exists() { - let head = head.canonicalize().unwrap(); - println!("cargo:rerun-if-changed={}", head.display()); if let Ok(output) = std::process::Command::new("git") .args(&[ "-c", @@ -57,5 +50,4 @@ fn main() { println!("cargo:rustc-env=WEZTERM_TARGET_TRIPLE={}", target); println!("cargo:rustc-env=WEZTERM_CI_TAG={}", ci_tag); - println!("cargo:rustc-env=MACOSX_DEPLOYMENT_TARGET=10.9"); } diff --git a/wezterm-version/src/lib.rs b/wezterm-version/src/lib.rs new file mode 100644 index 000000000..7c7f2128d --- /dev/null +++ b/wezterm-version/src/lib.rs @@ -0,0 +1,9 @@ +pub fn wezterm_version() -> &'static str { + // See build.rs + env!("WEZTERM_CI_TAG") +} + +pub fn wezterm_target_triple() -> &'static str { + // See build.rs + env!("WEZTERM_TARGET_TRIPLE") +}