Skip to content

Commit

Permalink
Support passing arguments to the StarlingMonkey runtime (#187)
Browse files Browse the repository at this point in the history
* 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.

* tweaks

---------

Co-authored-by: Guy Bedford <[email protected]>
  • Loading branch information
tschneidereit and guybedford authored Feb 21, 2025
1 parent 3081f96 commit c284639
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/componentize.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@ 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)
),
Expand Down Expand Up @@ -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;
Expand All @@ -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',
}
Expand Down Expand Up @@ -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',
}
Expand Down
5 changes: 5 additions & 0 deletions types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ interface ComponentizeOptions {
* To pass only a subset, provide an object with the desired variables
*/
env?: boolean | Record<string, string>,
/**
* Runtime arguments to provide to the StarlingMonkey engine initialization
* (see https://github.com/bytecodealliance/StarlingMonkey/blob/main/include/config-parser.h)
*/
runtimeArgs?: string,
}

/**
Expand Down

0 comments on commit c284639

Please sign in to comment.