aranya-policy-compiler

Crates.ioaranya-policy-compiler
lib.rsaranya-policy-compiler
version0.13.0
created_at2024-10-16 20:08:36.74506+00
updated_at2025-09-17 21:23:18.868495+00
descriptionThe Aranya Policy Compiler
homepage
repositoryhttps://github.com/aranya-project/aranya-core
max_upload_size
id1412283
size296,632
(aranya-project-bot)

documentation

README

aranya-policy-compiler

The Aranya Policy Compiler is a core component of the Aranya project that compiles policies written in the Aranya Policy Language into modules that can be loaded and executed by the Aranya runtime.

Overview

The compiler reads policy source code, often stored in a Markdown file, and emits bytecode that can be executed by the Aranya Policy VM.

Usage

As a Library

use aranya_policy_compiler::{Compiler, validate};
use aranya_policy_lang::lang::parse_policy_document;
use aranya_policy_vm::VM;

// Parse policy source code
let policy_str = std::fs::read_to_string("policy.md")?;
let policy = parse_policy_document(&policy_str)?;

// Compile to module
let compiler = Compiler::new(&policy);
let module = compiler.compile()?;

// Validate the compiled module
if !validate(&module) {
    eprintln!("Module validation failed");
}

// Execute a policy action
let mut vm = VM::new();
vm.load_module(module)?;
let result = vm.call_action("my_action", &args)?;
println!("Action result: {:?}", result);

As a Command-Line Tool

The crate also provides a command-line interface through the policy-compiler binary:

# Compile a policy file
policy-compiler input.md -o output.pmod

# Compile without validation
policy-compiler input.md --no-validate

# Compile with FFI stubbing for testing
policy-compiler input.md --stub-ffi
Commit count: 536

cargo fmt