Skip to content

Commit 2973656

Browse files
authored
Fix building on windows when using new syntax (#217)
The new sytax uses cwd() to strip the prefix when building using original source location. We were not running it through maybeWindowsPath which led to file not being found during initialization. This PR fixes that and thus enables building on windows using the new syntax.
1 parent e5bb0da commit 2973656

File tree

3 files changed

+56
-8
lines changed

3 files changed

+56
-8
lines changed

src/componentize.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ function isNumeric(n) {
8585
}
8686

8787
export async function componentize(opts,
88-
_deprecatedWitWorldOrOpts = undefined,
89-
_deprecatedOpts = undefined) {
88+
_deprecatedWitWorldOrOpts = undefined,
89+
_deprecatedOpts = undefined) {
9090
let useOriginalSourceFile = true;
9191
let jsSource;
9292

@@ -246,8 +246,9 @@ export async function componentize(opts,
246246
workspacePrefix = sourceDir;
247247
sourcePath = sourceName;
248248
}
249-
if (workspacePrefix.startsWith(cwd())) {
250-
workspacePrefix = cwd();
249+
let currentDir = maybeWindowsPath(cwd());
250+
if (workspacePrefix.startsWith(currentDir)) {
251+
workspacePrefix = currentDir;
251252
sourcePath = sourcePath.slice(workspacePrefix.length + 1);
252253
}
253254
}

test/api/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { now } from 'wasi:clocks/[email protected]';
2+
import { getRandomBytes } from 'wasi:random/[email protected]';
3+
4+
let result;
5+
export const run = {
6+
run() {
7+
result = `NOW: ${now().seconds}, RANDOM: ${getRandomBytes(2n)}`;
8+
}
9+
};
10+
11+
export const getResult = () => result;

test/test.js

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ suite('Builtins', () => {
109109
reject(
110110
new Error(
111111
'test timed out with output:\n' +
112-
stdout +
113-
'\n\nstderr:\n' +
114-
stderr
112+
stdout +
113+
'\n\nstderr:\n' +
114+
stderr
115115
)
116116
);
117117
}, 10_000);
@@ -254,7 +254,7 @@ suite('Bindings', () => {
254254
});
255255

256256
suite('WASI', () => {
257-
test('basic app', async () => {
257+
test('basic app (old API)', async () => {
258258
const { component } = await componentize(
259259
`
260260
import { now } from 'wasi:clocks/[email protected]';
@@ -301,4 +301,40 @@ suite('WASI', () => {
301301
strictEqual(result.slice(0, 10), `NOW: ${String(Date.now()).slice(0, 5)}`);
302302
strictEqual(result.split(',').length, 3);
303303
});
304+
305+
test('basic app (OriginalSourceFile API)', async () => {
306+
const { component } = await componentize(
307+
{
308+
sourcePath: "./test/api/index.js",
309+
witPath: fileURLToPath(new URL('./wit', import.meta.url)),
310+
worldName: 'test1',
311+
enableAot,
312+
debugBuild,
313+
}
314+
);
315+
316+
await writeFile(
317+
new URL(`./output/wasi.component.wasm`, import.meta.url),
318+
component
319+
);
320+
321+
const { files } = await transpile(component, { tracing: DEBUG_TRACING });
322+
323+
await mkdir(new URL(`./output/wasi/interfaces`, import.meta.url), {
324+
recursive: true,
325+
});
326+
327+
for (const file of Object.keys(files)) {
328+
await writeFile(
329+
new URL(`./output/wasi/${file}`, import.meta.url),
330+
files[file]
331+
);
332+
}
333+
334+
var instance = await import(`./output/wasi/component.js`);
335+
instance.run.run();
336+
const result = instance.getResult();
337+
strictEqual(result.slice(0, 10), `NOW: ${String(Date.now()).slice(0, 5)}`);
338+
strictEqual(result.split(',').length, 3);
339+
});
304340
});

0 commit comments

Comments
 (0)