Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
unullmass opened this issue Nov 14, 2023 · 1 comment · May be fixed by #162
Open

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

unullmass opened this issue Nov 14, 2023 · 1 comment · May be fixed by #162

Comments

@unullmass
Copy link

unullmass commented Nov 14, 2023

Hi, trying to integrate this with my application service and seeing this runtime error.

Error: incompatible import type for `env::memory`

Caused by:
    memory types incompatible: expected memory limits (min: 3, max: none) doesn't match provided memory limits (min: 2, max: none)

This is the code:

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);
    config.wasm_memory64(true); // Set minimum memory limit to 3 pages

    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(())
}

Here is the cargo.toml:

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
env_logger = "0.10.1"
log = "0.4.20"
opa-wasm = { git = "https://github.com/matrix-org/rust-opa-wasm.git", branch = "main", features = ["loader","all-builtins","default"] }
tokio = { version = "1", features = ["full"] }
mini-redis = "0.4"
anyhow = "1.0.75"
serde_json = "1.0.108"
wasmtime = "14.0.4"

Requesting guidance on how to fix this. Tried a bunch of things around setting memory limits and nothing has resolved this so far.

@unullmass
Copy link
Author

Raised PR #162 to resolve this.

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 a pull request may close this issue.

1 participant