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

API for using middleware with cranelift #1418

Closed
webmaster128 opened this issue Apr 30, 2020 · 5 comments
Closed

API for using middleware with cranelift #1418

webmaster128 opened this issue Apr 30, 2020 · 5 comments
Labels
❓ question I've a question!

Comments

@webmaster128
Copy link
Contributor

Right now we use the following code to create a singlepass compiler with a middleware chain:

pub fn compile(code: &[u8]) -> VmResult<Module> {
    compile_with(code, compiler().as_ref()).context(CompileErr {})
}

pub fn compiler() -> Box<dyn Compiler> {
    let c: StreamingCompiler<wasmer_singlepass_backend::ModuleCodeGenerator, _, _, _, _> =
        StreamingCompiler::new(move || {
            let mut chain = MiddlewareChain::new();
            chain.push(DeterministicMiddleware::new());
            chain.push(metering::Metering::new(GAS_LIMIT));
            chain
        });
    Box::new(c)
}

However, trying to do the same thing (minus the metering) with cranelift does not work due to a missing export:

pub fn compiler() -> Box<dyn Compiler> {
    let c: StreamingCompiler<wasmer_clif_backend::ModuleCodeGenerator, _, _, _, _> =
        StreamingCompiler::new(move || {
            let mut chain = MiddlewareChain::new();
            chain.push(DeterministicMiddleware::new());
            chain
        });
    Box::new(c)
}

It seems like there is only the 4-element type

/// Streaming compiler implementation for the Cranelift backed. Compiles web assembly binary into
/// machine code.
pub type CraneliftCompiler = SimpleStreamingCompilerGen<
    code::CraneliftModuleCodeGenerator,
    code::CraneliftFunctionCodeGenerator,
    signal::Caller,
    code::CodegenError,
>;

exposed and wasmer_clif_backend::code::CraneliftModuleCodeGenerator is private.

If this a missing feature or am I doing something wrong here?

@syrusakbary
Copy link
Member

Hi @webmaster128,

We currently don't support middleware in Cranelift. However we will ship soon support for it! :)

@webmaster128
Copy link
Contributor Author

Ah cool, thanks. No rush. Good to know I did not miss something obvious.

@syrusakbary
Copy link
Member

We are currently refactoring Wasmer.
I'm happy to announce that this feature (using middleware with Cranelift) is now supported there :)

@syrusakbary
Copy link
Member

We are in the process to add full support for middleware in the refactor.
Right now, only one thing is missing, but the good news is that middleware is supported across every compiler :)

@webmaster128
Copy link
Contributor Author

Assuming this is done on current master by now. Will open more specific issues when I run into trouble.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
❓ question I've a question!
Projects
None yet
Development

No branches or pull requests

2 participants