xll-utils 0.1.0

PE/COFF parsing and export verification utilities for Excel XLL development
Documentation
//! Build script helpers for verifying XLL exports at compile time.
//!
//! This module provides utilities for use in other crates' `build.rs` scripts
//! to verify DLL/XLL exports during the build process.

use std::path::Path;

use crate::error::{Error, Result};

/// Verify that a DLL/XLL contains all expected exports.
///
/// Returns `Ok(())` if all expected exports are present, or an error
/// listing the missing exports. Intended for use in `build.rs` scripts.
///
/// # Example
///
/// ```no_run
/// fn main() {
///     xll_utils::build::verify_exports_in_build(
///         "target/release/my_xll.xll",
///         &["xlAutoOpen", "xlAutoClose", "xlAutoFree12"],
///     ).expect("XLL export verification failed");
/// }
/// ```
pub fn verify_exports_in_build(dll_path: impl AsRef<Path>, expected: &[&str]) -> Result<()> {
    let dll_path = dll_path.as_ref();
    let report = crate::exports::verify_dll_exports(dll_path, expected)?;

    if !report.complete {
        return Err(Error::MissingExport(format!(
            "Missing exports from {}: {}",
            dll_path.display(),
            report.missing.join(", ")
        )));
    }

    Ok(())
}

/// Emit a `cargo:rerun-if-changed` directive for a DLL/XLL file.
///
/// Call this in `build.rs` to ensure rebuilds happen when the DLL changes.
pub fn rerun_if_dll_changed(dll_path: impl AsRef<Path>) {
    println!("cargo:rerun-if-changed={}", dll_path.as_ref().display());
}