Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Question: state of Extension API in Deno 1.11 #11147

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

Closed
jeffreyjw opened this issue Jun 27, 2021 · 1 comment
Closed

Question: state of Extension API in Deno 1.11 #11147

jeffreyjw opened this issue Jun 27, 2021 · 1 comment

Comments

@jeffreyjw
Copy link

I know the extension API is unstable and that there are currently issues about problems with it

#10671 #10534

This issue is more of a question: is there any way for Deno 1.11.2 to actually create a working native extension? The example code in https://github.com/denoland/deno/tree/main/test_plugin causes a segfault (at least on linux), the only way that I was able to have a plugin that does not crash is to not use any args struct and any zero copy struct, and to return a primitive like i32, like this:

use deno_core::Extension;
use deno_core::op_sync;
use deno_core::OpState;
use deno_core::ZeroCopyBuf;
use deno_core::error::AnyError;
use serde::Deserialize;

#[no_mangle]
pub fn init() -> Extension {
    println!("Initializing hello_world extension...");
    Extension::builder()
        .ops(vec![
            ("hello_world", op_sync(hello_world))
        ])
        .build()
}

#[derive(Debug, Deserialize)]
struct HelloWorldArgs {
    example: i32,
}

fn hello_world(
    _state: &mut OpState,
    // args: HelloWorldArgs,
    _: (),
    // _zero_copy: Option<ZeroCopyBuf>
    _: ()
) -> Result<i32, AnyError> {
    // format!("Hello rust world {}!", args.example);
    return Ok(42);
}
const pluginRid = Deno.openPlugin("./target/debug/libtest.so");
const {
    hello_world,
} = (Deno as any).core.ops();
const result = (Deno as any).core.opSync(hello_world, null, null);

But anything more, like returning a String, adding zerocopy or args other than a unit struct causes either a segmentation fault or an assertion error.

Is there ANY way to have a working extension in the current state of Deno? If not, is there any estimation (even a rough one without any promises) when writing extensions will be again possible?

@crowlKats
Copy link
Member

No. plugins will go away in favour of FFI. See #8490/#10908. There is currently no ETA, but ideally 1.12 for FFI, as that's when plugins get removed.

@kitsonk kitsonk closed this as completed Jun 27, 2021
@denoland denoland locked and limited conversation to collaborators Jun 27, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants