llzk-sys 30.0.0

Rust bindings to the LLZK C API.
//! Generated bindings of LLZK's C API.
//!
//! Follows a similar model to `mlir-sys` and integrates with that crate.

#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
#![warn(rustdoc::broken_intra_doc_links)]
#![deny(missing_debug_implementations)]
// This lint should never set to `deny` since the functions here depend on code written in the llzk-lib repository.
// It's set to warn as a reminder for the CAPI maintainers to add missing documentation.
#![warn(missing_docs)]

mod sys {

    #![allow(
        non_camel_case_types,
        non_snake_case,
        non_upper_case_globals,
        dead_code,
        unsafe_op_in_unsafe_fn,
        clippy::missing_safety_doc
    )]

    use mlir_sys::{
        MlirAffineExpr, MlirAffineMap, MlirAsmState, MlirAttribute, MlirBlock,
        MlirBytecodeWriterConfig, MlirContext, MlirDialectHandle, MlirDialectRegistry,
        MlirIdentifier, MlirLocation, MlirLogicalResult, MlirModule, MlirNamedAttribute,
        MlirOpPrintingFlags, MlirOperation, MlirOperationState, MlirOperationWalkCallback,
        MlirPass, MlirRegion, MlirStringCallback, MlirStringRef, MlirType, MlirTypeID, MlirValue,
        MlirWalkOrder,
    };
    include!(concat!(env!("OUT_DIR"), "/bindings.rs"));

    impl Copy for LlzkRecordValue {}
    impl Clone for LlzkRecordValue {
        fn clone(&self) -> Self {
            *self
        }
    }
}

pub use sys::*;

use std::{ffi::CStr, sync::LazyLock};

/// Macro to create safe Rust string constants for C FFI string constants.
macro_rules! c_str_constant {
    ($(#[$meta:meta])* $const_name:ident, $c_const:ident) => {
        $(#[$meta])*
        pub static $const_name: LazyLock<&'static str> = LazyLock::new(|| {
            unsafe { CStr::from_ptr($c_const) }
                .to_str()
                .expect(concat!(stringify!($c_const), " is valid UTF-8"))
        });
    };
}

c_str_constant!(
    /// Symbol name for the @compute function within a struct.
    FUNC_NAME_COMPUTE,
    LLZK_FUNC_NAME_COMPUTE
);

c_str_constant!(
    /// Symbol name for the @constraint function within a struct.
    FUNC_NAME_CONSTRAIN,
    LLZK_FUNC_NAME_CONSTRAIN
);

c_str_constant!(
    /// Symbol name for the @product function within a struct.
    FUNC_NAME_PRODUCT,
    LLZK_FUNC_NAME_PRODUCT
);

c_str_constant!(
    /// Name of the attribute on the top-level ModuleOp that identifies the ModuleOp as the
    /// root module and specifies the frontend language name that the IR was compiled from,
    /// if available.
    LANG_ATTR_NAME,
    LLZK_LANG_ATTR_NAME
);

c_str_constant!(
    /// Name of the attribute on the top-level ModuleOp that specifies the type of the main struct.
    /// This attribute can appear zero or one times on the top-level ModuleOp and is associated with
    /// a `TypeAttribute` specifying the `StructType` of the main struct.
    MAIN_ATTR_NAME,
    LLZK_MAIN_ATTR_NAME
);

#[cfg(test)]
mod sanity_tests;