use cp2k_build_utils as bu;
use std::process::Command;
const LIBTORCH_VER: &str = "2.7.1";
const LIBTORCH_SHA256: &str = "63d572598c8d532128a335018913e795c1bbb32602ce378896dc8cfbb5590976";
fn main() {
println!("cargo:rerun-if-changed=build.rs");
let stable_dir = bu::stable_dir("libtorch");
let install_dir = stable_dir.join("libtorch");
if install_dir.join("lib").join("libtorch.so").exists() {
println!(
"cargo:warning=libtorch already present at {}",
install_dir.display()
);
bu::emit_root(&install_dir);
return;
}
println!("cargo:warning=Downloading libtorch {LIBTORCH_VER} (CPU, cxx11-abi)...");
let zip = stable_dir.join(format!(
"libtorch-cxx11-abi-shared-with-deps-{LIBTORCH_VER}+cpu.zip"
));
bu::download(
&format!(
"https://download.pytorch.org/libtorch/cpu/\
libtorch-cxx11-abi-shared-with-deps-{LIBTORCH_VER}%2Bcpu.zip"
),
&zip,
);
bu::verify_sha256(&zip, LIBTORCH_SHA256);
println!("cargo:warning=Extracting libtorch...");
bu::run(
Command::new("unzip")
.args(["-q", "-o", zip.to_str().unwrap(), "-d"])
.arg(stable_dir.to_str().unwrap()),
"libtorch extract",
);
println!("cargo:warning=libtorch ready at {}", install_dir.display());
bu::emit_root(&install_dir);
}