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

wazero running on embedded systems #1854

Closed
deadprogram opened this issue Nov 30, 2023 · 9 comments
Closed

wazero running on embedded systems #1854

deadprogram opened this issue Nov 30, 2023 · 9 comments
Labels
enhancement New feature or request

Comments

@deadprogram
Copy link
Contributor

deadprogram commented Nov 30, 2023

I would like to be able to do something like WAMR https://github.com/bytecodealliance/wasm-micro-runtime for embedded systems, but to use wazero as the code/runtime to do this.

Ideal scenario would be that I would be able to run:

cd /path/to/repo/wazero-micro
tinygo build -o wazero-micro.uf2 -target itsybitsy-m4 .

and get a binary I can then flash onto that MCU with the wazero runtime. The binary would contain a minimal version of the wazero runtime.

Pretty sure this could be done with WAMR, but it requires also using an RTOS like Zephyr. Wazero would be running bare metal on the hardware e.g. "The Go runtime is your RTOS"
Also, it would be great to have a pure Go stack able to do this without needing any other languages/compilers.

Specific hardware functionality can be exposed to WASM modules via host functions.
Deciding on how to load new WASM code onto the device can be part of the host program, for example via serial port/OTA updates/etc.

@deadprogram deadprogram added the enhancement New feature or request label Nov 30, 2023
@evacchi
Copy link
Contributor

evacchi commented Nov 30, 2023

A few days ago I ran the same thought experiment. Wazero already builds fine to wasm using the plain Go compiler (and then you can even run wazero-on-wazero in interpreter mode).

I think the bulk of the work is in the syscalls (which are mostly in the WASI lib implementation). e.g. your command fails with

  ❯ tinygo build -o wazero-micro.uf2 -target itsybitsy-m4
  # github.com/tetratelabs/wazero/internal/platform
  internal/platform/mmap_unix.go:42:22: undefined: syscall.Syscall
  internal/platform/mmap_unix.go:42:38: undefined: syscall.SYS_MPROTECT

@deadprogram
Copy link
Contributor Author

Making some progress on this in #1855 when running against latest TinyGo dev branch plus branch of the TinyGo net package.

Current status:

$ tinygo flash -size short -target nano-rp2040 -stack-size 8kb -monitor ./examples/basic/
   code    data     bss |   flash     ram
 414220   72072   15040 |  486292   87112
Connected to /dev/ttyACM0. Press Ctrl-C to exit.
1970/01/01 00:00:05 Starting wazero on tinygo...
panic: runtime error at 0x10006537: out of memory
[tinygo: panic at /home/ron/Development/tinygo/tinygo/src/runtime/slice.go:30:15]

Need to start adding back the memory allocation code that I disabled to get the wazero branch to compile. 😸

@evacchi
Copy link
Contributor

evacchi commented Jan 14, 2024

hey this is awesome!

@deadprogram
Copy link
Contributor Author

We made it! Thank you to @orsinium @evacchi @achille-roussel and everyone else who helped make this happen.

I will close this issue now. We can open smaller more focused individual issues for anything else that we want to work on related to this area.

Thanks again!

@paralin
Copy link

paralin commented Mar 31, 2024

This is awesome! Thanks for the incredible work!

@ncruces
Copy link
Collaborator

ncruces commented May 14, 2024

In light of tinygo-org/tinygo#4156, we will need to revert #2161.

@deadprogram, @orsinium in your opinion, when is it the right time to do that? Do you expect a quick release of the feature? Can we do this now?

Also this one is clearly wrong and escaped review:

// setSliceLimits sets both Cap and Len for the given reflected slice.
func setSliceLimits(s *reflect.SliceHeader, limit uintptr) {
s.Len = limit
s.Len = limit
}

@deadprogram
Copy link
Contributor Author

We will probably have our next release in approximately 4 weeks.

@ncruces
Copy link
Collaborator

ncruces commented May 20, 2024

Tentative PR #2210 waiting for release to update the failing CI test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants