Skip to main content

eclexiaiser/
lib.rs

1// SPDX-License-Identifier: PMPL-1.0-or-later
2// Copyright (c) 2026 Jonathan D.A. Jewell <j.d.a.jewell@open.ac.uk>
3//
4// eclexiaiser library — Add energy, carbon, and resource-cost awareness to
5// existing software via Eclexia economics-as-code.
6//
7// This library provides:
8// - ABI types for energy budgets, carbon intensity, and sustainability reports
9// - Manifest parsing and validation for `eclexiaiser.toml`
10// - Code generation for instrumentation wrappers and Eclexia constraints
11// - Sustainability report generation (text, JSON, EU CSRD)
12
13pub mod abi;
14pub mod codegen;
15pub mod manifest;
16
17pub use manifest::{load_manifest, parse_manifest, validate, Manifest};
18
19/// Generate all eclexiaiser artifacts from a manifest file.
20///
21/// This is the main library entry point. It loads the manifest, validates it,
22/// and generates instrumentation code, Eclexia constraints, and a sustainability
23/// report in the specified output directory.
24///
25/// # Arguments
26/// - `manifest_path` — Path to `eclexiaiser.toml`
27/// - `output_dir` — Directory for generated artifacts
28///
29/// # Errors
30/// Returns an error if the manifest cannot be loaded, fails validation, or
31/// if code generation encounters an I/O error.
32pub fn generate(manifest_path: &str, output_dir: &str) -> anyhow::Result<()> {
33    let m = load_manifest(manifest_path)?;
34    validate(&m)?;
35    codegen::generate_all(&m, output_dir)
36}