Skip to content

Conversation

unullmass
Copy link

@unullmass unullmass commented Nov 15, 2023

Resolves #161.

use std::collections::HashMap;
use wasmtime::{Config, Engine, Module, Store};
use opa_wasm::Runtime;
use anyhow::Result;


#[tokio::main]
async fn main() -> Result<()> {
    // Configure the WASM runtime
    let mut config = Config::new();
    config.async_support(true);

    let engine = Engine::new(&config)?;

    // Load the policy WASM module
    let module = opa_wasm::read_bundle("bundle.tar.gz").await?;
    let module:Module = Module::new(&engine, module)?;

    // Create a store which will hold the module instance

    let mut store = Store::new(&engine, ());


    let data = HashMap::from([("hello", "world")]);
    let input = HashMap::from([("message", "world")]);

    // Instantiate the module
    let runtime = Runtime::new(&mut store, &module).await?;

    let policy = runtime.with_data(&mut store, &data).await?;

    // Evaluate the policy
    let res: serde_json::Value = policy.evaluate(&mut store, "hello/world", &input).await?;

    println!("{}", res);

    Ok(())
}

Able to see the evaluation result now for this code:

Error: could not find entrypoint hello/world

@unullmass unullmass changed the title Update minimum memlimit for policy.rs Update minimum memlimit for policy.rs to fix runtime error Nov 15, 2023
@sandhose
Copy link
Member

Whilst I don't see any harm with upping the minimum memory linked with the module (other that it will allocate one potentially unused 64k page by default), I'm not sure I see the point of enabling memory64 support? OPA's WASM module won't use it, and the memory type allocated to it is not in 64bit mode either?

@unullmass
Copy link
Author

unullmass commented Nov 22, 2023

@sandhose I have removed the code pertaining to 64-bit memory from the above example.

@sandhose
Copy link
Member

Sure, but then what is this PR fixing exactly? The example should work without this PR, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Runtime error: memory types incompatible: expected memory limit for bundle evaluation

2 participants