//! Check the model is a model and not an LFS pointer. //! //! `models/keypoints/*.onnx` is stored in Git LFS (see `.gitattributes`). A //! clone made without git-lfs, or with `GIT_LFS_SKIP_SMUDGE` set, leaves a //! ~130-byte text pointer at that path instead of the weights, and //! `include_bytes!` would embed it without complaint. Same guard as //! `dr-segment`'s, for the same failure. use std::path::Path; const MODELS: &[&str] = &[ "../../models/keypoints/xfeat-1024.onnx", "../../models/keypoints/xfeat-768.onnx", ]; fn main() { for m in MODELS { println!("cargo:rerun-if-changed={m}"); } println!("cargo:rerun-if-changed=build.rs"); if std::env::var_os("CARGO_FEATURE_EMBEDDED_MODEL").is_none() { return; } for model in MODELS.iter().copied() { check(model); } } fn check(model: &str) { let path = Path::new(model); let Ok(bytes) = std::fs::read(path) else { panic!( "\n\n{model} is missing.\n\ It ships in Git LFS. Run `git lfs install && git lfs pull`, or build \ with `--no-default-features` for a geometry-only build.\n" ); }; if bytes.starts_with(b"version https://git-lfs.github.com/spec/") { panic!( "\n\n{model} is a Git LFS pointer, not the model.\n\ Run `git lfs install && git lfs pull`, or build with \ `--no-default-features` for a geometry-only build.\n" ); } }