@swiftbrowser/wasm-compiler 0.8.0 → 0.9.1
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/README.md +2 -1
- package/dist/memory-host.d.ts +6 -1
- package/dist/memory-host.js +11 -3
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -99,7 +99,8 @@ module this size runs under WASI; `src/node/wasi-host.ts` turns them off
|
|
|
99
99
|
makes the CLI (`packages/cli`) build an app with these tools instead of
|
|
100
100
|
`swift build`, for `build` and `dev` alike, and type-check it for `check`
|
|
101
101
|
(`packages/cli/src/wasmCompiler.ts`), with no Swift install: the CLI
|
|
102
|
-
|
|
102
|
+
lays out the Swift SDK for WebAssembly itself, from its npm packages
|
|
103
|
+
(`packages/cli/src/sdkPackages.ts`), and uses the released kit,
|
|
103
104
|
whose macros come built as WebAssembly. It reproduces SwiftPM's release build
|
|
104
105
|
of the staged package: one whole-module `-O` frontend job against the kit's
|
|
105
106
|
modules, Foundation's trimmed ICU data as an object written in TypeScript
|
package/dist/memory-host.d.ts
CHANGED
|
@@ -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
|
-
/**
|
|
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][];
|
package/dist/memory-host.js
CHANGED
|
@@ -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
|
-
/**
|
|
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
|
-
|
|
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
|
-
|
|
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.
|
|
3
|
+
"version": "0.9.1",
|
|
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.
|
|
42
|
+
"@swiftbrowser/wasm-tools": "0.9.1"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@types/node": "^26.6.4",
|