regex-mumu 0.1.1

Regex tools plugin for the Lava language
Documentation
// regex/build.rs
use std::env;
use std::fs;
use std::path::PathBuf;

fn main() {
    // Only run on "cargo build", not for docs/tests
    if env::var("CARGO_CFG_DOCS_RS").is_ok() {
        return;
    }

    // Get OUT_DIR, which is something like .../regex/target/debug/build/...
    let out_dir = env::var("OUT_DIR").expect("OUT_DIR not set");
    // Go up to .../regex/target/{debug|release}
    let profile_dir = PathBuf::from(&out_dir)
        .ancestors().nth(3)
        .expect("Failed to get profile dir").to_path_buf();

    // Plugin name - must match your Cargo.toml [lib] name!
    let so_name = format!(
        "libmumuregex{}",
        std::env::consts::DLL_SUFFIX // ".so", ".dylib", ".dll"
    );

    let from = profile_dir.join(&so_name);
    // Destination: the project root (parent of regex/)
    let project_root = profile_dir.parent().and_then(|p| p.parent()).unwrap().to_path_buf();
    let to = project_root.join(&so_name);

    // Only copy if the source exists (build done)
    if from.exists() {
        match fs::copy(&from, &to) {
            Ok(_) => println!("cargo:warning=Copied {:?} -> {:?}", from, to),
            Err(e) => println!("cargo:warning=Failed to copy plugin: {e}"),
        }
    } else {
        println!("cargo:warning=Did not find plugin to copy: {:?}", from);
    }
}