| 1 | use std::io::Write as _; |
| 2 | |
| 3 | fn main() { |
| 4 | println!("cargo::rustc-check-cfg=cfg(embedded_onnxruntime)"); |
| 5 | println!("cargo::rerun-if-env-changed=CALLING_ONNXRUNTIME_DLL"); |
| 6 | let windows = std::env::var("CARGO_CFG_TARGET_OS").as_deref() == Ok("windows"); |
| 7 | let Some(library) = std::env::var_os("CALLING_ONNXRUNTIME_DLL").filter(|_| windows) else { |
| 8 | return; |
| 9 | }; |
| 10 | println!("cargo::rerun-if-changed={}", library.to_string_lossy()); |
| 11 | let bytes = std::fs::read(&library).expect("CALLING_ONNXRUNTIME_DLL is readable"); |
| 12 | let output = std::path::Path::new(&std::env::var("OUT_DIR").expect("out dir")) |
| 13 | .join("onnxruntime.dll.deflate"); |
| 14 | let mut encoder = flate2::write::DeflateEncoder::new( |
| 15 | std::fs::File::create(&output).expect("deflate output"), |
| 16 | flate2::Compression::best(), |
| 17 | ); |
| 18 | encoder.write_all(&bytes).expect("deflate written"); |
| 19 | encoder.finish().expect("deflate finished"); |
| 20 | println!("cargo::rustc-cfg=embedded_onnxruntime"); |
| 21 | } |