vyre-conform 0.1.0

Conformance suite for vyre backends — proves byte-identical output to CPU reference
Documentation
//! Shared immutable enforcement context.

use std::path::PathBuf;

use crate::spec::types::OpSpec;

/// Inputs supplied to every [`crate::enforce::Enforcer`].
#[derive(Clone, Copy)]
pub struct EnforceCtx<'a> {
    /// Operation specs visible to registry-wide enforcers.
    pub specs: &'a [OpSpec],
    /// Optional backend for runtime probes.
    pub backend: Option<&'a dyn vyre::VyreBackend>,
    /// Workspace root used by filesystem-backed gates.
    pub workspace_root: &'a std::path::Path,
}

impl<'a> EnforceCtx<'a> {
    /// Build a context from explicit inputs.
    ///
    /// The context is intentionally cheap to construct (it only holds
    /// references) so that orchestrators can create it once and pass it
    /// to every registered enforcer without cloning heavy data structures.
    #[inline]
    pub fn new(
        specs: &'a [OpSpec],
        backend: Option<&'a dyn vyre::VyreBackend>,
        workspace_root: &'a std::path::Path,
    ) -> Self {
        Self {
            specs,
            backend,
            workspace_root,
        }
    }
}

/// Return the workspace root inferred from `CARGO_MANIFEST_DIR`.
///
/// This function is used by the registry and by CI scripts that need a
/// stable filesystem anchor for gates that walk source files (structural
/// rules, category tripwire, etc.). It returns the parent of the conform
/// crate's manifest directory, which is the workspace root in the standard
/// vyre layout.
#[inline]
pub fn workspace_root() -> PathBuf {
    std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
        .parent()
        .map(std::path::Path::to_path_buf)
        .unwrap_or_else(|| PathBuf::from(env!("CARGO_MANIFEST_DIR")))
}