// Copyright (C) 2026 Elias Wendland // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, version 3 exclusively. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . use std::{path::Path, process::Command}; fn latest_engine_version(workspace: &Path) -> String { if let Ok(version) = std::env::var("CONVERTIS_ENGINE_VERSION") { return version; } Command::new("git") .args(["describe", "--tags", "--abbrev=0", "--match", "v[0-9]*"]) .current_dir(workspace) .output() .ok() .filter(|output| output.status.success()) .map(|output| String::from_utf8_lossy(&output.stdout).trim().to_owned()) .filter(|version| !version.is_empty()) .map(|version| version.strip_prefix('v').unwrap_or(&version).to_owned()) .unwrap_or_else(|| "unknown".to_owned()) } fn main() { let manifest = std::env::var_os("CARGO_MANIFEST_DIR").expect("Cargo provides manifest dir"); let workspace = Path::new(&manifest).join("../.."); let target = std::env::var("TARGET").unwrap_or_else(|_| "unknown".to_owned()); let engine_version = latest_engine_version(&workspace); println!("cargo:rerun-if-env-changed=CONVERTIS_ENGINE_VERSION"); println!( "cargo:rerun-if-changed={}", workspace.join(".git/HEAD").display() ); println!("cargo:rustc-env=CONVERTIS_ENGINE_VERSION={engine_version}"); println!("cargo:rustc-env=CONVERTIS_TARGET={target}"); }