| Crates.io | aranya-policy-compiler |
| lib.rs | aranya-policy-compiler |
| version | 0.13.0 |
| created_at | 2024-10-16 20:08:36.74506+00 |
| updated_at | 2025-09-17 21:23:18.868495+00 |
| description | The Aranya Policy Compiler |
| homepage | |
| repository | https://github.com/aranya-project/aranya-core |
| max_upload_size | |
| id | 1412283 |
| size | 296,632 |
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.
The compiler reads policy source code, often stored in a Markdown file, and emits bytecode that can be executed by the Aranya Policy VM.
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);
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