Skip to content

Question: state of Extension API in Deno 1.11 #11147

@jeffreyjw

Description

@jeffreyjw

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions