wasi: make the demo run on wasi and run it in CI

This commit is contained in:
Laytan Laats
2024-06-29 23:15:31 +02:00
parent 476d0087c8
commit 604551eb2d
12 changed files with 129 additions and 54 deletions
+12
View File
@@ -6,6 +6,8 @@ import "base:runtime"
Handle :: distinct i32
Errno :: distinct i32
INVALID_HANDLE :: -1
ERROR_NONE :: Errno(wasi.errno_t.SUCCESS)
O_RDONLY :: 0x00000
@@ -26,6 +28,16 @@ stdout: Handle = 1
stderr: Handle = 2
current_dir: Handle = 3
args := _alloc_command_line_arguments()
_alloc_command_line_arguments :: proc() -> (args: []string) {
args = make([]string, len(runtime.args__))
for &arg, i in args {
arg = string(runtime.args__[i])
}
return
}
write :: proc(fd: Handle, data: []byte) -> (int, Errno) {
iovs := wasi.ciovec_t(data)
n, err := wasi.fd_write(wasi.fd_t(fd), {iovs})