1#![warn(clippy::pedantic)]
2
3use serde::{de::DeserializeOwned, Serialize};
4
5#[cfg(feature = "bundle")]
6pub mod bundle;
7
8#[cfg(feature = "http")]
9pub mod http;
10
11#[cfg(any(feature = "wasmtime-cranelift", feature = "wasmtime-aot"))]
12pub mod wasm;
13
14#[cfg(feature = "build")]
15pub mod build;
16
17pub trait PolicyDecision {
20 const POLICY_PATH: &'static str;
22
23 type Input: Serialize;
25
26 type Output: DeserializeOwned;
28}
29
30#[cfg(all(feature = "bundle", feature = "build"))]
51#[macro_export]
52macro_rules! include_policy {
53 ($name:literal) => {{
54 let mut bundle = $crate::bundle::Bundle::from_bytes(include_bytes!(concat!(
55 env!("OUT_DIR"),
56 "/opa/",
57 $name,
58 ".tar.gz"
59 )))
60 .unwrap();
61
62 $crate::include_aot!($name, bundle);
63
64 bundle
65 }};
66}
67
68#[doc(hidden)]
69pub mod private {
70 pub use bytes;
71}
72
73#[cfg(all(feature = "build", feature = "wasmtime-aot"))]
74#[doc(hidden)]
75#[macro_export]
76macro_rules! include_aot {
77 ($name:literal, $bundle:ident) => {
78 let b = include_bytes!(concat!(env!("OUT_DIR"), "/opa/", $name, ".cwasm"));
79
80 if !b.is_empty() {
81 unsafe { $bundle.set_wasmtime_bytes($crate::private::bytes::Bytes::from(&b[..])) }
84 }
85 };
86}
87
88#[cfg(all(feature = "build", not(feature = "wasmtime-aot")))]
89#[doc(hidden)]
90#[macro_export]
91macro_rules! include_aot {
92 ($name:literal, $bundle:ident) => {};
93}