use std::env::*;
use std::path::*;
use std::process::*;
fn main() {
let target = var("TARGET").expect("Failed to get target triple");
let out_dir = PathBuf::from(var("OUT_DIR").expect("Failed to get output directory"));
let file_path = out_dir.join("machdxcompiler.tar.gz");
download_url(&get_target_url(&target), &file_path);
extract_tar_gz(&file_path, &out_dir);
println!("cargo:rustc-link-lib=static=machdxcompiler");
println!("cargo:rustc-link-search=native={}", out_dir.display());
}
fn get_target_url(target: &str) -> String {
const BASE_URL: &str = "https://github.com/hexops/mach-dxcompiler/releases/download/2023.12.14%2B0b7073b.1/";
BASE_URL.to_string() + match target {
"x86_64-pc-windows-msvc" => "x86_64-windows-msvc_ReleaseFast_lib.tar.gz",
"x86_64-pc-windows-gnu" => "x86_64-windows-gnu_ReleaseFast_lib.tar.gz",
_ => panic!("Unsupported target '{target}' for mach-dxcompiler")
}
}
fn download_url(url: &str, file_path: &Path) {
Command::new("curl")
.arg("--location")
.arg("-o")
.arg(file_path)
.arg(url)
.spawn()
.expect("Failed to start Curl to download DXC binary")
.wait()
.expect("Failed to download DXC binary");
}
fn extract_tar_gz(path: &Path, output_dir: &Path) {
Command::new("tar")
.current_dir(output_dir)
.arg("-xzf")
.arg(path)
.spawn()
.expect("Failed to start Tar to extract DXC binary")
.wait()
.expect("Failed to extract DXC binary");
}