|
| 1 | +#include <stdio.h> |
| 2 | +#include <stdlib.h> |
| 3 | + |
| 4 | +#include "hello-wasi-wasm.h" |
| 5 | +#include "wasm-rt-uvwasi-adapter.h" |
| 6 | +#include "uvwasi.h" |
| 7 | + |
| 8 | +int main(int argc, const char** argv) { |
| 9 | + w2c_hello__wasi hello = {0}; |
| 10 | + struct w2c_wasi__snapshot__preview1 wasi = {0}; |
| 11 | + uvwasi_t uvwasi = {0}; |
| 12 | + uvwasi_options_t init_options = {0}; |
| 13 | + uvwasi_preopen_t preopens[2] = {0}; |
| 14 | + |
| 15 | + init_options.in = 0; |
| 16 | + init_options.out = 1; |
| 17 | + init_options.err = 2; |
| 18 | + init_options.fd_table_size = 10; |
| 19 | + |
| 20 | + extern const char** environ; |
| 21 | + init_options.argc = argc; |
| 22 | + init_options.argv = argv; |
| 23 | + init_options.envp = (const char**)environ; |
| 24 | + |
| 25 | + preopens[0].mapped_path = "/tmp"; |
| 26 | + preopens[0].real_path = "/tmp"; |
| 27 | + preopens[1].mapped_path = "."; |
| 28 | + preopens[1].real_path = "."; |
| 29 | + init_options.preopenc = 2; |
| 30 | + init_options.preopens = preopens; |
| 31 | + init_options.allocator = NULL; |
| 32 | + |
| 33 | + wasm_rt_init(); |
| 34 | + uvwasi_errno_t ret = uvwasi_init(&uvwasi, &init_options); |
| 35 | + if (ret != UVWASI_ESUCCESS) { |
| 36 | + fprintf(stderr, "uvwasi_init failed with error %u\n", ret); |
| 37 | + return 1; |
| 38 | + } |
| 39 | + |
| 40 | + wasm2c_uvwasi_link(&wasi, &hello.w2c_memory, &uvwasi); |
| 41 | + wasm2c_hello__wasi_instantiate(&hello, &wasi); |
| 42 | + w2c_hello__wasi_0x5Fstart(&hello); |
| 43 | + wasm2c_hello__wasi_free(&hello); |
| 44 | + |
| 45 | + uvwasi_destroy(&uvwasi); |
| 46 | + wasm_rt_free(); |
| 47 | + |
| 48 | + return 0; |
| 49 | +} |
0 commit comments