Skip to content

Commit f286203

Browse files
Fix test harness for the latest main XCTest
The latest XCTest bundled in Swift SDK for Wasm requires `Bundle.main` access to minimize behavior difference from other platforms. `Bundle.main` requires `argv[0]` and file system access to get the main bundle path.
1 parent 8bd1d02 commit f286203

File tree

4 files changed

+21
-12
lines changed

4 files changed

+21
-12
lines changed

Sources/CartonKit/Server/StaticArchive.swift

Lines changed: 9 additions & 9 deletions
Large diffs are not rendered by default.

entrypoint/common.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import { WASI } from "@wasmer/wasi";
1616
import { WasmFs } from "@wasmer/wasmfs";
17+
import * as path from "path-browserify";
1718

1819
export const WasmRunner = (rawOptions, SwiftRuntime) => {
1920
const options = defaultRunnerOptions(rawOptions);
@@ -34,12 +35,18 @@ export const WasmRunner = (rawOptions, SwiftRuntime) => {
3435
}
3536
);
3637

38+
wasmFs.fs.mkdirSync("/sandbox");
39+
3740
const wasi = new WASI({
3841
args: options.args,
3942
env: {},
43+
preopenDirectories: {
44+
"/": "/sandbox",
45+
},
4046
bindings: {
4147
...WASI.defaultBindings,
4248
fs: wasmFs.fs,
49+
path: path,
4350
},
4451
});
4552

@@ -100,13 +107,13 @@ export const WasmRunner = (rawOptions, SwiftRuntime) => {
100107
const defaultRunnerOptions = (options) => {
101108
if (!options) return defaultRunnerOptions({});
102109
if (!options.onStdout) {
103-
options.onStdout = () => {};
110+
options.onStdout = () => { };
104111
}
105112
if (!options.onStderr) {
106-
options.onStderr = () => {};
113+
options.onStderr = () => { };
107114
}
108115
if (!options.args) {
109-
options.args = [];
116+
options.args = ["main.wasm"];
110117
}
111118
return options;
112119
};

package-lock.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"devDependencies": {
2323
"@wasmer/wasi": "^0.12.0",
2424
"@wasmer/wasmfs": "^0.12.0",
25+
"path-browserify": "^1.0.1",
2526
"esbuild": "^0.14.38",
2627
"npm-run-all": "^4.1.5",
2728
"reconnecting-websocket": "^4.4.0"

0 commit comments

Comments
 (0)