@solidjs/compiler-wasm32-wasi 2.0.0-rc.2 → 2.0.0-rc.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/compiler.wasi-browser.js +620 -0
- package/compiler.wasi.cjs +927 -0
- package/compiler.wasm32-wasi.wasm +0 -0
- package/package.json +2 -2
- package/wasi-worker-browser.mjs +51 -0
- package/wasi-worker.mjs +74 -0
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solidjs/compiler-wasm32-wasi",
|
|
3
|
-
"version": "2.0.0-rc.
|
|
3
|
+
"version": "2.0.0-rc.4",
|
|
4
4
|
"main": "compiler.wasi.cjs",
|
|
5
5
|
"files": [
|
|
6
6
|
"compiler.wasm32-wasi.wasm",
|
|
@@ -26,4 +26,4 @@
|
|
|
26
26
|
"@emnapi/core": "1.11.3",
|
|
27
27
|
"@emnapi/runtime": "1.11.3"
|
|
28
28
|
}
|
|
29
|
-
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import {
|
|
2
|
+
instantiateNapiModuleSync,
|
|
3
|
+
MessageHandler,
|
|
4
|
+
WASI,
|
|
5
|
+
emnapiAsyncWorkPlugin,
|
|
6
|
+
emnapiTSFNPlugin,
|
|
7
|
+
} from '@napi-rs/wasm-runtime'
|
|
8
|
+
|
|
9
|
+
const errorOutputs = []
|
|
10
|
+
|
|
11
|
+
const handler = new MessageHandler({
|
|
12
|
+
onLoad({ wasmModule, wasmMemory }) {
|
|
13
|
+
const wasi = new WASI({
|
|
14
|
+
print: function () {
|
|
15
|
+
// eslint-disable-next-line no-console
|
|
16
|
+
console.log.apply(console, arguments)
|
|
17
|
+
},
|
|
18
|
+
printErr: function() {
|
|
19
|
+
// eslint-disable-next-line no-console
|
|
20
|
+
console.error.apply(console, arguments)
|
|
21
|
+
|
|
22
|
+
errorOutputs.push([...arguments])
|
|
23
|
+
},
|
|
24
|
+
})
|
|
25
|
+
return instantiateNapiModuleSync(wasmModule, {
|
|
26
|
+
childThread: true,
|
|
27
|
+
wasi,
|
|
28
|
+
// The wasm links a "basic" emnapi archive (no C async-work /
|
|
29
|
+
// threadsafe-function implementations), so every thread that
|
|
30
|
+
// instantiates it must provide the JavaScript implementations
|
|
31
|
+
// through the emnapi plugins.
|
|
32
|
+
plugins: [emnapiAsyncWorkPlugin, emnapiTSFNPlugin],
|
|
33
|
+
overwriteImports(importObject) {
|
|
34
|
+
importObject.env = {
|
|
35
|
+
...importObject.env,
|
|
36
|
+
...importObject.napi,
|
|
37
|
+
...importObject.emnapi,
|
|
38
|
+
memory: wasmMemory,
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
})
|
|
42
|
+
},
|
|
43
|
+
onError(error) {
|
|
44
|
+
postMessage({ type: 'error', error, errorOutputs })
|
|
45
|
+
errorOutputs.length = 0
|
|
46
|
+
}
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
globalThis.onmessage = function (e) {
|
|
50
|
+
handler.handle(e)
|
|
51
|
+
}
|
package/wasi-worker.mjs
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import { parse } from "node:path";
|
|
4
|
+
import { WASI } from "node:wasi";
|
|
5
|
+
import { parentPort, Worker } from "node:worker_threads";
|
|
6
|
+
|
|
7
|
+
const require = createRequire(import.meta.url);
|
|
8
|
+
|
|
9
|
+
const {
|
|
10
|
+
instantiateNapiModuleSync,
|
|
11
|
+
MessageHandler,
|
|
12
|
+
getDefaultContext,
|
|
13
|
+
emnapiAsyncWorkPlugin,
|
|
14
|
+
emnapiTSFNPlugin,
|
|
15
|
+
} = require("@napi-rs/wasm-runtime");
|
|
16
|
+
|
|
17
|
+
if (parentPort) {
|
|
18
|
+
parentPort.on("message", (data) => {
|
|
19
|
+
globalThis.onmessage({ data });
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
Object.assign(globalThis, {
|
|
24
|
+
self: globalThis,
|
|
25
|
+
require,
|
|
26
|
+
Worker,
|
|
27
|
+
importScripts: function (f) {
|
|
28
|
+
;(0, eval)(fs.readFileSync(f, "utf8") + "//# sourceURL=" + f);
|
|
29
|
+
},
|
|
30
|
+
postMessage: function (msg) {
|
|
31
|
+
if (parentPort) {
|
|
32
|
+
parentPort.postMessage(msg);
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const emnapiContext = getDefaultContext();
|
|
38
|
+
|
|
39
|
+
const __rootDir = parse(process.cwd()).root;
|
|
40
|
+
|
|
41
|
+
const handler = new MessageHandler({
|
|
42
|
+
onLoad({ wasmModule, wasmMemory }) {
|
|
43
|
+
const wasi = new WASI({
|
|
44
|
+
version: 'preview1',
|
|
45
|
+
env: process.env,
|
|
46
|
+
preopens: {
|
|
47
|
+
[__rootDir]: __rootDir,
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
return instantiateNapiModuleSync(wasmModule, {
|
|
52
|
+
childThread: true,
|
|
53
|
+
wasi,
|
|
54
|
+
context: emnapiContext,
|
|
55
|
+
// The wasm links a "basic" emnapi archive (no C async-work /
|
|
56
|
+
// threadsafe-function implementations), so every thread that
|
|
57
|
+
// instantiates it must provide the JavaScript implementations
|
|
58
|
+
// through the emnapi plugins.
|
|
59
|
+
plugins: [emnapiAsyncWorkPlugin, emnapiTSFNPlugin],
|
|
60
|
+
overwriteImports(importObject) {
|
|
61
|
+
importObject.env = {
|
|
62
|
+
...importObject.env,
|
|
63
|
+
...importObject.napi,
|
|
64
|
+
...importObject.emnapi,
|
|
65
|
+
memory: wasmMemory
|
|
66
|
+
};
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
globalThis.onmessage = function (e) {
|
|
73
|
+
handler.handle(e);
|
|
74
|
+
};
|