denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
94.63k stars 5.25k forks source link

Importing a native module #296

Closed robbym closed 4 years ago

robbym commented 6 years ago

I know that using protobufs simplifies the writing of native modules, but how does importing them work? What's the structure of it supposed to be? How do we specify how the native module should be built?

styfle commented 6 years ago

Maybe the solution is to compile native modules to wasm files and import into deno?

I know that with Node.js you can use the WebAssembly.compile() function just like you can in the browser so maybe deno should support this.

robbym commented 6 years ago

I'm talking about importing libraries that talk to the underlying operating system. Some examples would be:

These things are inherently native and can't be 'compiled' to wasm.

styfle commented 6 years ago

Good point, for legacy software there would need to be a way to interface with it.

But for new software, there are emerging standards like WebUSB that I think deno should adopt.

https://developers.google.com/web/updates/2016/03/access-usb-devices-on-the-web

ry commented 5 years ago

Before we think about how to have native addons, I want to release a crate #1209 - that provides a way to link in native code (albeit only if you're building your own executable)

nayeemrmn commented 4 years ago

Closed in #3372.

brandonros commented 3 years ago

How would I implement something like a thin layer above libusb (or the existing rusb crate) with this if the return value for all plugin ops needs to be https://docs.rs/deno_core/0.48.1/deno_core/plugin_api/type.Buf.html?

I might be missing something obvious in terms of how to pass references as Box<[u8]>.