@swiftbrowser/wasm-compiler 0.9.0 → 0.9.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.
@@ -1,7 +1,12 @@
1
1
  import { Directory, OpenFile } from '@bjorn3/browser_wasi_shim';
2
2
  import { type ToolName } from './driver.js';
3
3
  import type { Host, RunResult } from './host.js';
4
- /** A Directory holding `files`, keyed by `/`-separated paths relative to it. */
4
+ /**
5
+ * A Directory holding `files`, keyed by `/`-separated paths relative to it.
6
+ * A file whose bytes are all of their buffer keeps them rather than a copy
7
+ * (a File copies a view it is given): the inputs of a compile are hundreds
8
+ * of megabytes, which a phone's browser has not got twice.
9
+ */
5
10
  export declare function memoryDirectory(files: Iterable<readonly [string, Uint8Array]>): Directory;
6
11
  /** The files under `dir`, as `memoryDirectory` takes them: the inverse of it. */
7
12
  export declare function directoryFiles(dir: Directory, prefix?: string): [string, Uint8Array][];
@@ -11,7 +11,12 @@
11
11
  import { ConsoleStdout, Directory, File, Inode, OpenFile, PreopenDirectory, WASI, wasi as wasiDefs } from '@bjorn3/browser_wasi_shim';
12
12
  import { sdkPaths } from './driver.js';
13
13
  import { pluginHost } from './plugins.js';
14
- /** A Directory holding `files`, keyed by `/`-separated paths relative to it. */
14
+ /**
15
+ * A Directory holding `files`, keyed by `/`-separated paths relative to it.
16
+ * A file whose bytes are all of their buffer keeps them rather than a copy
17
+ * (a File copies a view it is given): the inputs of a compile are hundreds
18
+ * of megabytes, which a phone's browser has not got twice.
19
+ */
15
20
  export function memoryDirectory(files) {
16
21
  const root = new Directory(new Map());
17
22
  for (const [file, data] of files) {
@@ -27,7 +32,8 @@ export function memoryDirectory(files) {
27
32
  throw new Error(`${file}: ${part} is a file`);
28
33
  dir = next;
29
34
  }
30
- dir.contents.set(parts[parts.length - 1], new File(data));
35
+ const whole = data.byteOffset === 0 && data.byteLength === data.buffer.byteLength;
36
+ dir.contents.set(parts[parts.length - 1], new File(whole ? data.buffer : data));
31
37
  }
32
38
  return root;
33
39
  }
@@ -158,7 +164,9 @@ export async function runMemoryCommand(command) {
158
164
  output += decoder.decode();
159
165
  return { exitCode: 1, output: `${output}${error instanceof Error ? (error.stack ?? error.message) : String(error)}\n` };
160
166
  }
161
- return { exitCode, output: output + decoder.decode() };
167
+ // The tool's linear memory at its end, its peak: what a browser has to give it.
168
+ const memory = instance.exports['memory'];
169
+ return { exitCode, output: output + decoder.decode(), ...(memory ? { memoryBytes: memory.buffer.byteLength } : {}) };
162
170
  }
163
171
  /** The module cache's directory under the host's /tmp. */
164
172
  const MODULE_CACHE = 'module-cache';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swiftbrowser/wasm-compiler",
3
- "version": "0.9.0",
3
+ "version": "0.9.2",
4
4
  "description": "Compiles Swift with the Swift compiler built as WebAssembly: a driver, WASI hosts and a CLI. See docs/in-browser-compiler.md.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -39,7 +39,7 @@
39
39
  },
40
40
  "dependencies": {
41
41
  "@bjorn3/browser_wasi_shim": "^0.4.2",
42
- "@swiftbrowser/wasm-tools": "0.9.0"
42
+ "@swiftbrowser/wasm-tools": "0.9.2"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@types/node": "^26.6.4",