|
2 | 2 | import { MODULE_PATH /* #if USE_SHARED_MEMORY */, MEMORY_TYPE /* #endif */} from "../instantiate.js" |
3 | 3 | /* #if IS_WASI */ |
4 | 4 | /* #if USE_UWASI */ |
| 5 | +import { browserMainThreadSleep, createUwasi } from './uwasi.js'; |
| 6 | +/* #if USE_UWASI_FILESYSTEM */ |
5 | 7 | /* #if USE_WASI_CDN */ |
6 | 8 | // @ts-ignore |
7 | | -import { WASI, MemoryFileSystem, useAll, lineBuffered } from 'https://cdn.jsdelivr.net/npm/uwasi@1.5.2/+esm'; |
| 9 | +import { WASI, lineBuffered, MemoryFileSystem, useAll } from 'https://cdn.jsdelivr.net/npm/uwasi@1.5.2/+esm'; |
8 | 10 | /* #else */ |
9 | | -import { WASI, MemoryFileSystem, useAll, lineBuffered } from 'uwasi'; |
| 11 | +import { WASI, lineBuffered, MemoryFileSystem, useAll } from 'uwasi'; |
| 12 | +/* #endif */ |
| 13 | +const uwasiRuntime = { WASI, lineBuffered, MemoryFileSystem, useAll }; |
| 14 | +/* #else */ |
| 15 | +/* #if USE_WASI_CDN */ |
| 16 | +// @ts-ignore |
| 17 | +import { WASI, lineBuffered, useStdio, useArgs, useEnviron, useClock, usePoll, useProc, useRandom } from 'https://cdn.jsdelivr.net/npm/uwasi@1.5.2/+esm'; |
| 18 | +/* #else */ |
| 19 | +import { WASI, lineBuffered, useStdio, useArgs, useEnviron, useClock, usePoll, useProc, useRandom } from 'uwasi'; |
| 20 | +/* #endif */ |
| 21 | +const uwasiRuntime = { WASI, lineBuffered, useStdio, useArgs, useEnviron, useClock, usePoll, useProc, useRandom }; |
10 | 22 | /* #endif */ |
11 | | -import { browserMainThreadSleep, createUwasi } from './uwasi.js'; |
12 | 23 | /* #else */ |
13 | 24 | /* #if USE_WASI_CDN */ |
14 | 25 | // @ts-ignore |
@@ -38,10 +49,7 @@ export async function defaultBrowserThreadSetup() { |
38 | 49 |
|
39 | 50 | /* #if IS_WASI */ |
40 | 51 | /* #if USE_UWASI */ |
41 | | - const { wasi } = createUwasi( |
42 | | - { WASI, MemoryFileSystem, useAll, lineBuffered }, |
43 | | - { modulePath: MODULE_PATH } |
44 | | - ) |
| 52 | + const { wasi } = createUwasi(uwasiRuntime, { modulePath: MODULE_PATH }) |
45 | 53 | /* #else */ |
46 | 54 | const wasi = new WASI(/* args */[MODULE_PATH], /* env */[], /* fd */[ |
47 | 55 | new OpenFile(new File([])), // stdin |
@@ -127,16 +135,13 @@ export async function defaultBrowserSetup(options) { |
127 | 135 | const onStdoutLine = options.onStdoutLine ?? ((line) => console.log(line)) |
128 | 136 | const onStderrLine = options.onStderrLine ?? ((line) => console.error(line)) |
129 | 137 | /* #if USE_UWASI */ |
130 | | - const { wasi } = createUwasi( |
131 | | - { WASI, MemoryFileSystem, useAll, lineBuffered }, |
132 | | - { |
133 | | - modulePath: MODULE_PATH, |
134 | | - args, |
135 | | - onStdoutLine, |
136 | | - onStderrLine, |
137 | | - sleep: browserMainThreadSleep(), |
138 | | - } |
139 | | - ) |
| 138 | + const { wasi } = createUwasi(uwasiRuntime, { |
| 139 | + modulePath: MODULE_PATH, |
| 140 | + args, |
| 141 | + onStdoutLine, |
| 142 | + onStderrLine, |
| 143 | + sleep: browserMainThreadSleep(), |
| 144 | + }) |
140 | 145 | /* #else */ |
141 | 146 | const wasi = new WASI(/* args */[MODULE_PATH, ...args], /* env */[], /* fd */[ |
142 | 147 | new OpenFile(new File([])), // stdin |
|
0 commit comments