@rspack/binding-wasm32-wasi 2.0.0-rc.0 → 2.0.0-rc.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspack/binding-wasm32-wasi",
3
- "version": "2.0.0-rc.0",
3
+ "version": "2.0.0-rc.2",
4
4
  "license": "MIT",
5
5
  "description": "Node binding for rspack",
6
6
  "main": "rspack.wasi.cjs",
@@ -23,7 +23,9 @@
23
23
  "wasi-worker-browser.mjs"
24
24
  ],
25
25
  "dependencies": {
26
- "@napi-rs/wasm-runtime": "1.1.2"
26
+ "@emnapi/core": "1.9.2",
27
+ "@emnapi/runtime": "1.9.2",
28
+ "@napi-rs/wasm-runtime": "1.1.3"
27
29
  },
28
30
  "cpu": [
29
31
  "wasm32"
@@ -21,9 +21,10 @@ const __wasmUrl = new URL('./rspack.wasm32-wasi.wasm', import.meta.url).href
21
21
  const __emnapiContext = __emnapiGetDefaultContext()
22
22
  __emnapiContext.feature.Buffer = Buffer
23
23
 
24
+ // Allocate 2GB fixed shared memory (initial == maximum to disable memory.grow).
24
25
  const __sharedMemory = new WebAssembly.Memory({
25
- initial: 16384,
26
- maximum: 65536,
26
+ initial: 32768,
27
+ maximum: 32768,
27
28
  shared: true,
28
29
  })
29
30
 
@@ -57,6 +58,10 @@ const {
57
58
  ...importObject.napi,
58
59
  ...importObject.emnapi,
59
60
  memory: __sharedMemory,
61
+ // Override emnapi's napi_adjust_external_memory to a no-op.
62
+ // emnapi implements this by calling memory.grow, but we've disabled memory.grow
63
+ // (initial == maximum).
64
+ napi_adjust_external_memory() { return 0 },
60
65
  }
61
66
  return importObject
62
67
  },
package/rspack.wasi.cjs CHANGED
@@ -26,18 +26,20 @@ const __wasi = new __nodeWASI({
26
26
 
27
27
  const __emnapiContext = __emnapiGetDefaultContext()
28
28
 
29
+ // Allocate 2GB fixed shared memory (initial == maximum to disable memory.grow).
29
30
  const __sharedMemory = new WebAssembly.Memory({
30
- initial: 16384,
31
- maximum: 65536,
31
+ initial: 32768,
32
+ maximum: 32768,
32
33
  shared: true,
33
34
  })
34
35
 
35
- let __wasmFilePath = __nodePath.join(__dirname, 'rspack.wasm32-wasi.wasm')
36
- const __wasmDebugFilePath = __nodePath.join(__dirname, 'rspack.wasm32-wasi.debug.wasm')
36
+ const localWasmFilePath = __nodePath.join(__dirname, 'rspack.wasm32-wasi.wasm')
37
37
 
38
- if (__nodeFs.existsSync(__wasmDebugFilePath)) {
39
- __wasmFilePath = __wasmDebugFilePath
40
- } else if (!__nodeFs.existsSync(__wasmFilePath)) {
38
+ let __wasmFilePath;
39
+
40
+ if (__nodeFs.existsSync(localWasmFilePath)) {
41
+ __wasmFilePath = localWasmFilePath
42
+ } else {
41
43
  try {
42
44
  __wasmFilePath = require.resolve('@rspack/binding-wasm32-wasi/rspack.wasm32-wasi.wasm')
43
45
  } catch {
@@ -47,7 +49,7 @@ if (__nodeFs.existsSync(__wasmDebugFilePath)) {
47
49
 
48
50
  const { instance: __napiInstance, module: __wasiModule, napiModule: __napiModule } = __emnapiInstantiateNapiModuleSync(__nodeFs.readFileSync(__wasmFilePath), {
49
51
  context: __emnapiContext,
50
- asyncWorkPoolSize: (function() {
52
+ asyncWorkPoolSize: (function () {
51
53
  const threadsSizeFromEnv = Number(process.env.NAPI_RS_ASYNC_WORK_POOL_SIZE ?? process.env.UV_THREADPOOL_SIZE)
52
54
  // NaN > 0 is false
53
55
  if (threadsSizeFromEnv > 0) {
@@ -76,14 +78,14 @@ const { instance: __napiInstance, module: __wasiModule, napiModule: __napiModule
76
78
  s.toString().includes("kPublicPort")
77
79
  );
78
80
  if (kPublicPort) {
79
- worker[kPublicPort].ref = () => {};
81
+ worker[kPublicPort].ref = () => { };
80
82
  }
81
83
 
82
84
  const kHandle = Object.getOwnPropertySymbols(worker).find(s =>
83
85
  s.toString().includes("kHandle")
84
86
  );
85
87
  if (kHandle) {
86
- worker[kHandle].ref = () => {};
88
+ worker[kHandle].ref = () => { };
87
89
  }
88
90
 
89
91
  worker.unref();
@@ -96,6 +98,10 @@ const { instance: __napiInstance, module: __wasiModule, napiModule: __napiModule
96
98
  ...importObject.napi,
97
99
  ...importObject.emnapi,
98
100
  memory: __sharedMemory,
101
+ // Override emnapi's napi_adjust_external_memory to a no-op.
102
+ // emnapi implements this by calling memory.grow, but we've disabled memory.grow
103
+ // (initial == maximum).
104
+ napi_adjust_external_memory() { return 0 },
99
105
  }
100
106
  return importObject
101
107
  },
Binary file
@@ -16,10 +16,10 @@ const handler = new MessageHandler({
16
16
  // eslint-disable-next-line no-console
17
17
  console.log.apply(console, arguments)
18
18
  },
19
- printErr: function() {
19
+ printErr: function () {
20
20
  // eslint-disable-next-line no-console
21
21
  console.error.apply(console, arguments)
22
-
22
+
23
23
  errorOutputs.push([...arguments])
24
24
  },
25
25
  })
@@ -32,6 +32,10 @@ const handler = new MessageHandler({
32
32
  ...importObject.napi,
33
33
  ...importObject.emnapi,
34
34
  memory: wasmMemory,
35
+ // Override emnapi's napi_adjust_external_memory to a no-op.
36
+ // emnapi implements this by calling memory.grow, but we've disabled memory.grow
37
+ // (initial == maximum).
38
+ napi_adjust_external_memory() { return 0 },
35
39
  }
36
40
  },
37
41
  })
package/wasi-worker.mjs CHANGED
@@ -19,7 +19,7 @@ Object.assign(globalThis, {
19
19
  require,
20
20
  Worker,
21
21
  importScripts: function (f) {
22
- ;(0, eval)(fs.readFileSync(f, "utf8") + "//# sourceURL=" + f);
22
+ ; (0, eval)(fs.readFileSync(f, "utf8") + "//# sourceURL=" + f);
23
23
  },
24
24
  postMessage: function (msg) {
25
25
  if (parentPort) {
@@ -51,7 +51,11 @@ const handler = new MessageHandler({
51
51
  ...importObject.env,
52
52
  ...importObject.napi,
53
53
  ...importObject.emnapi,
54
- memory: wasmMemory
54
+ memory: wasmMemory,
55
+ // Override emnapi's napi_adjust_external_memory to a no-op.
56
+ // emnapi implements this by calling memory.grow, but we've disabled memory.grow
57
+ // (initial == maximum).
58
+ napi_adjust_external_memory() { return 0 },
55
59
  };
56
60
  },
57
61
  });