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

WASI Serial api #350

Open
lachlansneff opened this issue Nov 8, 2020 · 14 comments
Open

WASI Serial api #350

lachlansneff opened this issue Nov 8, 2020 · 14 comments
Labels
feature-request Requests for new WASI APIs

Comments

@lachlansneff
Copy link

Recently, I've been casually involved in the hardware scene and I've realized that programming and interfacing with hardware can be annoying platform-independent. Often software will work, but it's quite complicated to get all the dependencies it requires in exactly the right place. I've noticed some niches start to move towards packaging software as wasm modules that can run on any platform with a compliant wasi runtime (see YoWASP), but this hasn't included the programmers and debuggers themselves. To fully fulfill that role, WASI would need a USB api (akin to WebUSB), but a low-hanging fruit, which would still go a very long way, is a serial api for WASI.

I went ahead and wrote a preliminary witx module (see here) and also implemented a (pretty rough) wasmtime crate for it (see here).

My goal here is to open the conversation about what interfacing with external hardware through WASI could look like. The API I've come up with here does not follow the capability-based security that WASI is based on, so it's obviously not finished.

Applications:

  • Programming and debugging microcontrollers (e.g. arduinos, etc) and FPGAs
  • Interfacing with MIDI devices(?)
  • lots more stuff
@lachlansneff
Copy link
Author

If there's no interest in a serial api, I'll close this issue.

@programmerjake
Copy link
Contributor

I guess that there are more interested people, just that most of them (like me) are fine letting someone else do the initial work and only saying something if it looked broken somehow.

@lachlansneff
Copy link
Author

I already implemented it, and linked to the implementation in the issue above. But it needs discussion of how security can work in this context before a PR can be made.

@programmerjake
Copy link
Contributor

programmerjake commented Nov 29, 2020

I'd consider security and related API design discussions to be partially part of "initial work"...

In any case, there is at least 1 other person interested in this (me), so it might be worth reopening, even if it may take a long time due to low interest.

@sunfishcode
Copy link
Member

I don't have an immediate use case for this myself, but it is an interesting feature.

This highlights an area where WASI's infrastructure needs to provide better support: we need better mechanisms for passing new capabilities into programs.

On the proposal itself, how important are 7-bit, 6-bit, and 5-bit data streams these days? If there aren't many devices that need these, it might be nice to avoid including these so that we can more easily abstract over these streams and other kinds of datastreams (files, sockets, etc.) which will likely all be 8-bit?

@programmerjake
Copy link
Contributor

there's also 9-bit and bigger serial protocols that make really messy APIs.

@lachlansneff lachlansneff reopened this Dec 4, 2020
@beriberikix
Copy link

I'm torn while I suggest this but it probably makes sense to use Web Serial API is the starting point of a Serial API. In lieu of champions who can express the nuanced differences between RS232 on windows vs tty (for example,) it is reasonable to adopt the constraints spec'd by the W3C folks as a starting point. And it is also reasonable to assume that some users will be using WASI in some browsers that support Web Serial if it ever does become a ratified standard.

@zwhitchcox
Copy link

This would be useful for creating in-browser drivers for USB devices with lower latency than usbip for example.

Especially for drivers you only want to use one time or have frequent changes.

For example, to flash a beagle bone black with the S2 button, it exposes an RNDIS interface, which expects a pbx server (tftp server with the bootloader/spl) which then converts it to a ums.

Rather than download all these drivers, you could just flash from an electron process running the WASI code.

The same is true for many IoT devices, like the Jetson line, and many compute modules/carrier boards.

+1 for serial interface!

@sunfishcode sunfishcode added the feature-request Requests for new WASI APIs label Jul 19, 2022
@lukedukeus
Copy link

Still would love to see this / use it.

@sascha1337
Copy link

sascha1337 commented Nov 19, 2022 via email

@sunfishcode
Copy link
Member

We've always known that we wanted to build WASI on top of WebAssembly standards rather than having WASI invent everything it needs for itself. WASI needs an IDL, and there is now one being developed toward becoming a WebAssembly standard: wit. It will provide many things that WASI needs, such as support for non-C-like languages, support for capability-based security, proper support for types like string, list, variant, and so on. So it makes sense that WASI should aim to be built on wit rather than building up a whole separate IDL and having to solve all the same problems in a parallel system.

Wit has turned out to take longer than initially expected to develop, but it is progressing. I recommend this talk for anyone interested in the path to how we got to where we are now, and the road ahead.

If anyone is interested in prototyping a WASI serial API with the wit IDL, the wasi sockets proposal is an example of how to work with wit. The wit tooling is still in development, but it is possible to work on this in parallel.

@RaulRG
Copy link

RaulRG commented Feb 13, 2023

My company would be quite interested in serial support for webassembly (RS232, USB, ...). We have got some software that could be ported to webassembly only if we could access serial ports as we communicate with different devices using it. I think that is something quite interesting / important for WASI to be general-purpose.

@rccarlson
Copy link

If you're still looking for interest in this, I have a project I would like to distribute as WebAssembly, but it requires access to a user's peripheral device via serial connection.

@FrankReh
Copy link

Seems like the pieces are in place for someone to give this a try.

A WIT could be created that defined a resource representing a serial port. A Rust embedder could be written with the WasmTime library and creates like serialport, mio-serial, or tokio-serial.

The Component guest could be written in any language that can be compiled to a wasm32-wasi2p target.

I don't understand the questions around security. The embedder CLI, like a fork of WasmTime CLI, would require the user name the ports they want to give their tool access to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Requests for new WASI APIs
Projects
None yet
Development

No branches or pull requests

10 participants