Skip to content

Commit 4f387af

Browse files
committed
Update to ComponentizeJS 0.18 and enable debugging support
The update itself just works, but I changed a bunch of code to enable debugging. This mainly involves adding a `--debug` / `-d` CLI option and passing that through to StarlingMonkey, but also merging in a world containing the interfaces needed to actually make debugging work at runtime. Signed-off-by: Till Schneidereit <[email protected]>
1 parent 988f844 commit 4f387af

File tree

8 files changed

+65
-28
lines changed

8 files changed

+65
-28
lines changed

packages/build-tools/package-lock.json

Lines changed: 21 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/build-tools/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"typescript": "^5.7.3"
2929
},
3030
"dependencies": {
31-
"@bytecodealliance/componentize-js": "^0.17.0",
31+
"@bytecodealliance/componentize-js": "^0.18.0",
3232
"@bytecodealliance/jco": "^1.10.2",
3333
"@types/yargs": "^17.0.33",
3434
"yargs": "^17.7.2"

packages/build-tools/src/build.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,15 @@ export function getBuildDataPath(src: string): string {
99
}
1010

1111
export async function ShouldComponentize(
12-
src: string,
13-
outputPath: string,
14-
componentizeVersion: string,
12+
src: string, outputPath: string, componentizeVersion: string, runtimeArgs: string,
1513
) {
1614
const sourceChecksum = await calculateChecksum(src);
1715
const existingBuildData = await getExistingBuildData(getBuildDataPath(src));
1816

1917
if (
2018
existingBuildData?.version == componentizeVersion &&
2119
existingBuildData?.checksum === sourceChecksum &&
20+
existingBuildData?.runtimeArgs === runtimeArgs &&
2221
(await fileExists(outputPath))
2322
) {
2423
return false;

packages/build-tools/src/cli.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export interface CliArgs {
88
triggerType: string;
99
witPath?: string;
1010
aot?: boolean;
11+
debug?: boolean;
1112
}
1213

1314
export function getCliArgs(): CliArgs {
@@ -18,7 +19,7 @@ export function getCliArgs(): CliArgs {
1819
demandOption: true,
1920
})
2021
.option('wit-path', {
21-
alias: 'd',
22+
alias: 'w',
2223
describe: 'Path to wit file or folder',
2324
})
2425
.option('output', {
@@ -27,14 +28,20 @@ export function getCliArgs(): CliArgs {
2728
default: 'component.wasm',
2829
})
2930
.option('trigger-type', {
30-
alias: '-n',
31+
alias: '-t',
3132
describe: 'Spin trigger to target',
3233
demandOption: true,
3334
})
3435
.option('aot', {
3536
describe: 'Enable Ahead of Time compilation',
3637
type: 'boolean',
37-
}).argv as CliArgs;
38+
})
39+
.option('debug', {
40+
alias: 'd',
41+
describe: 'Enable JavaScript debugging',
42+
type: 'boolean',
43+
})
44+
.argv as CliArgs;
3845

3946
return args;
4047
}

packages/build-tools/src/index.ts

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#!/usr/bin/env node
22

33
import { componentize } from '@bytecodealliance/componentize-js';
4-
//@ts-ignore https://github.com/bytecodealliance/ComponentizeJS/pull/198
5-
import { version } from '@bytecodealliance/componentize-js';
4+
import { version as componentizeVersion } from '@bytecodealliance/componentize-js';
65
import { getPackagesWithWasiDeps, processWasiDeps } from './wasiDepsParser.js';
76
import { basename } from 'node:path';
87

@@ -22,12 +21,10 @@ async function main() {
2221
let CliArgs = getCliArgs();
2322
let src = CliArgs.input;
2423
let outputPath = CliArgs.output;
25-
26-
// Can remove the explicit typing once https://github.com/bytecodealliance/ComponentizeJS/pull/198 is merged and released
27-
let componentizeVersion = version as string;
24+
let runtimeArgs = CliArgs.debug ? '--enable-script-debugging' : '';
2825

2926
// Small optimization to skip componentization if the source file hasn't changed
30-
if (!(await ShouldComponentize(src, outputPath, componentizeVersion))) {
27+
if (!(await ShouldComponentize(src, outputPath, componentizeVersion, runtimeArgs))) {
3128
console.log(
3229
'No changes detected in source file. Skipping componentization.',
3330
);
@@ -40,6 +37,15 @@ async function main() {
4037

4138
let { witPaths, targetWorlds } = processWasiDeps(wasiDeps);
4239

40+
// Debugging requires some interfaces around reading env vars and making
41+
// socket connections to be available.
42+
if (CliArgs.debug) {
43+
targetWorlds.push({
44+
packageName: 'spinframework:[email protected]',
45+
worldName: 'debugging-support',
46+
});
47+
}
48+
4349
// Get inline wit by merging the wits specified by all the dependencies
4450
let inlineWit = mergeWit(
4551
witPaths,
@@ -48,13 +54,11 @@ async function main() {
4854
'combined-wit:[email protected]',
4955
);
5056

51-
const source = await readFile(src, 'utf8');
52-
53-
const { component } = await componentize(source, inlineWit, {
54-
sourceName: basename(src),
55-
// TODO: CHeck if we need to enable http
56-
//@ts-ignore
57-
enableFeatures: ['http'],
57+
const { component } = await componentize({
58+
sourcePath: src,
59+
// @ts-ignore
60+
witWorld: inlineWit,
61+
runtimeArgs,
5862
});
5963

6064
await writeFile(outputPath, component);
@@ -64,6 +68,7 @@ async function main() {
6468
getBuildDataPath(src),
6569
await calculateChecksum(src),
6670
componentizeVersion,
71+
runtimeArgs,
6772
);
6873

6974
console.log('Component successfully written.');

packages/build-tools/src/utils.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,13 @@ export async function getExistingBuildData(buildDataPath: string) {
7676
}
7777

7878
export async function saveBuildData(
79-
buildDataPath: string,
80-
checksum: string,
81-
version: string,
79+
buildDataPath: string, checksum: string, version: string, runtimeArgs: string,
8280
) {
8381
try {
8482
const checksumData = {
8583
version,
8684
checksum,
85+
runtimeArgs,
8786
};
8887
await writeFile(buildDataPath, JSON.stringify(checksumData, null, 2));
8988
} catch (error) {

packages/http-trigger/wit/[email protected]

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ world http-trigger {
99

1010
export wasi:http/incoming-handler@0.2.3;
1111
}
12+
13+
/// The set of interfaces required for JS source debugging to work.
14+
world debugging-support {
15+
import wasi:cli/environment@0.2.3;
16+
import wasi:sockets/network@0.2.3;
17+
import wasi:sockets/instance-network@0.2.3;
18+
import wasi:sockets/tcp@0.2.3;
19+
import wasi:sockets/tcp-create-socket@0.2.3;
20+
}
21+
1222
package wasi:io@0.2.3 {
1323
@since(version = 0.2.0)
1424
interface error {

test/test-app/package-lock.json

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

0 commit comments

Comments
 (0)