captcha-engine 0.1.0

ONNX-based captcha recognition engine
Documentation
#![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
use std::env;
use std::fs;
use std::path::Path;

fn main() {
    // Only run if the embed-model feature is enabled
    if env::var("CARGO_FEATURE_EMBED_MODEL").is_ok() {
        let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
        let training_dir = fs::canonicalize(Path::new(&manifest_dir).join("../../training"))
            .expect("Failed to canonicalize training directory");
        let model_path = training_dir.join("captcha_schwarz_finetuned.onnx");

        let out_dir = env::var("OUT_DIR").unwrap();
        let dest_path = Path::new(&out_dir).join("model.onnx");

        if !model_path.exists() {
            println!(
                "cargo:warning=Model file not found at {}. Embedded model validation will fail.",
                model_path.display()
            );
            // We might want to panic here if we strictly require it, or let the include_bytes fail.
            // Panicking is better to give a clear error.
            panic!(
                "Model file not found at {}. Please run training or ensure the file exists.",
                model_path.display()
            );
        }

        fs::copy(&model_path, &dest_path).expect("Failed to copy model file");

        println!("cargo:rerun-if-changed={}", model_path.display());
        println!("cargo:rerun-if-env-changed=CARGO_FEATURE_EMBED_MODEL");
    }
}