From 35b550375ed83641d3b5f967a0d8867a97f640a3 Mon Sep 17 00:00:00 2001 From: Till Schneidereit Date: Thu, 20 Feb 2025 21:35:07 -0600 Subject: [PATCH 1/3] Support passing arguments to the StarlingMonkey runtime StarlingMonkey supports a growing number of arguments in addition to the filename of the script to run. This commit adds support for passing those arguments through when componentizing. I think it'll eventually make sense to expose some of these arguments more explicitly, but providing this option allows us to evolve the interfaces separately, similar to how e.g. clang supports passing linker arguments, or cargo supports passing rustc arguments. --- src/componentize.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/componentize.js b/src/componentize.js index 17b4acb6..06fa5c3b 100644 --- a/src/componentize.js +++ b/src/componentize.js @@ -50,6 +50,7 @@ export async function componentize(jsSource, witWorld, opts) { new URL(`../lib/starlingmonkey_ics.wevalcache`, import.meta.url) ), } = opts; + let runtimeArgs = opts.runtimeArgs; const engine = opts.engine || @@ -222,6 +223,10 @@ export async function componentize(jsSource, witWorld, opts) { console.log('--- Wizer Env ---'); console.log(env); } + + let sourcePath = maybeWindowsPath(join(sourceDir, sourceName.slice(0, -3) + '.bindings.js')); + runtimeArgs = runtimeArgs ? `${runtimeArgs} ${sourcePath}` : sourcePath; + if (opts.enableAot) { // Determine the weval bin path, possibly using a pre-downloaded version let wevalBin; @@ -247,9 +252,7 @@ export async function componentize(jsSource, witWorld, opts) { { stdio: [null, stdout, stderr], env, - input: maybeWindowsPath( - join(sourceDir, sourceName.slice(0, -3) + '.bindings.js') - ), + input: runtimeArgs, shell: true, encoding: 'utf-8', } @@ -284,9 +287,7 @@ export async function componentize(jsSource, witWorld, opts) { { stdio: [null, stdout, stderr], env, - input: maybeWindowsPath( - join(sourceDir, sourceName.slice(0, -3) + '.bindings.js') - ), + input: runtimeArgs, shell: true, encoding: 'utf-8', } From dd1557817833d8bbaeda6d02ae8af903a1493136 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Fri, 21 Feb 2025 11:58:59 -0800 Subject: [PATCH 2/3] tweaks --- src/componentize.js | 4 ++-- types.d.ts | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/componentize.js b/src/componentize.js index 06fa5c3b..bc29860d 100644 --- a/src/componentize.js +++ b/src/componentize.js @@ -39,18 +39,18 @@ export async function componentize(jsSource, witWorld, opts) { witWorld = opts?.witWorld; } opts = opts || {}; - const { + let { sourceName = 'source.js', preview2Adapter = preview1AdapterReactorPath(), witPath, worldName, disableFeatures = [], enableFeatures = [], + runtimeArgs, aotCache = fileURLToPath( new URL(`../lib/starlingmonkey_ics.wevalcache`, import.meta.url) ), } = opts; - let runtimeArgs = opts.runtimeArgs; const engine = opts.engine || diff --git a/types.d.ts b/types.d.ts index cb391a75..2d2d9201 100644 --- a/types.d.ts +++ b/types.d.ts @@ -53,6 +53,11 @@ interface ComponentizeOptions { * To pass only a subset, provide an object with the desired variables */ env?: boolean | Record, + /** + * Runtime arguments to provide to the StarlingMonkey engine initialization + * (see https://github.com/bytecodealliance/StarlingMonkey/blob/main/include/config-parser.h) + */ + runtimeArgs?: string, } /** From b60a130d0df3d389e4ad15ffafd7f4622dfb7664 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Fri, 21 Feb 2025 12:00:35 -0800 Subject: [PATCH 3/3] readme fix --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 6659b85b..392d2d78 100644 --- a/README.md +++ b/README.md @@ -182,6 +182,7 @@ export function componentize(jsSource: string, opts: { engine?: string, preview2Adapter?: string, disableFeatures?: ('stdio' | 'random' | 'clocks' | 'http')[], + runtimeArgs?: string, }): { component: Uint8Array, imports: string[]