Skip to content

Commit c284639

Browse files
tschneidereitGuy Bedford
andauthored
Support passing arguments to the StarlingMonkey runtime (#187)
* 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 <gbedford@fastly.com>
1 parent 3081f96 commit c284639

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

src/componentize.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,14 @@ export async function componentize(jsSource, witWorld, opts) {
3939
witWorld = opts?.witWorld;
4040
}
4141
opts = opts || {};
42-
const {
42+
let {
4343
sourceName = 'source.js',
4444
preview2Adapter = preview1AdapterReactorPath(),
4545
witPath,
4646
worldName,
4747
disableFeatures = [],
4848
enableFeatures = [],
49+
runtimeArgs,
4950
aotCache = fileURLToPath(
5051
new URL(`../lib/starlingmonkey_ics.wevalcache`, import.meta.url)
5152
),
@@ -222,6 +223,10 @@ export async function componentize(jsSource, witWorld, opts) {
222223
console.log('--- Wizer Env ---');
223224
console.log(env);
224225
}
226+
227+
let sourcePath = maybeWindowsPath(join(sourceDir, sourceName.slice(0, -3) + '.bindings.js'));
228+
runtimeArgs = runtimeArgs ? `${runtimeArgs} ${sourcePath}` : sourcePath;
229+
225230
if (opts.enableAot) {
226231
// Determine the weval bin path, possibly using a pre-downloaded version
227232
let wevalBin;
@@ -247,9 +252,7 @@ export async function componentize(jsSource, witWorld, opts) {
247252
{
248253
stdio: [null, stdout, stderr],
249254
env,
250-
input: maybeWindowsPath(
251-
join(sourceDir, sourceName.slice(0, -3) + '.bindings.js')
252-
),
255+
input: runtimeArgs,
253256
shell: true,
254257
encoding: 'utf-8',
255258
}
@@ -284,9 +287,7 @@ export async function componentize(jsSource, witWorld, opts) {
284287
{
285288
stdio: [null, stdout, stderr],
286289
env,
287-
input: maybeWindowsPath(
288-
join(sourceDir, sourceName.slice(0, -3) + '.bindings.js')
289-
),
290+
input: runtimeArgs,
290291
shell: true,
291292
encoding: 'utf-8',
292293
}

types.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ interface ComponentizeOptions {
5353
* To pass only a subset, provide an object with the desired variables
5454
*/
5555
env?: boolean | Record<string, string>,
56+
/**
57+
* Runtime arguments to provide to the StarlingMonkey engine initialization
58+
* (see https://github.com/bytecodealliance/StarlingMonkey/blob/main/include/config-parser.h)
59+
*/
60+
runtimeArgs?: string,
5661
}
5762

5863
/**

0 commit comments

Comments
 (0)