Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions .github/workflows/main-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,13 @@ jobs:
name: js-generated-tests
path: packages/jco-transpile/test/fixtures/generated

- name: Build jco-transpile
run: pnpm --filter '@bytecodealliance/jco-transpile' run build

- name: Upload jco-transpile vendor
- name: Upload jco-transpile build output
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: jco-transpile-vendor
name: jco-transpile-build
path: |
packages/jco-transpile/vendor
packages/jco-transpile/dist

- name: Build preview2-shim
run: pnpm --filter '@bytecodealliance/preview2-shim' run build
Expand Down Expand Up @@ -236,11 +234,11 @@ jobs:
path: packages/preview2-shim/dist

# The runtime integration tests exercise the local transpiler through the API and CLI.
- name: Restore jco-transpile vendor
- name: Restore jco-transpile build output
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: jco-transpile-vendor
path: packages/jco-transpile/vendor
name: jco-transpile-build
path: packages/jco-transpile

- name: Build workspace jco-transpile
run: pnpm --filter '@bytecodealliance/jco-transpile' run build:ts
Expand Down Expand Up @@ -318,6 +316,12 @@ jobs:
with:
name: jco-build-ts
path: packages/jco/dist

- name: Restore jco-transpile build output
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: jco-transpile-build
path: packages/jco-transpile
- name: Restore Component Model runtime build output
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
Expand Down
55 changes: 35 additions & 20 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,13 @@ jobs:
name: js-generated-tests
path: packages/jco-transpile/test/fixtures/generated

- name: Build jco-transpile
run: pnpm --filter '@bytecodealliance/jco-transpile' run build

- name: Upload jco-transpile vendor
- name: Upload jco-transpile build output
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: jco-transpile-vendor
name: jco-transpile-build
path: |
packages/jco-transpile/vendor
packages/jco-transpile/dist

- name: Build preview2-shim
run: pnpm --filter '@bytecodealliance/preview2-shim' run build
Expand Down Expand Up @@ -211,11 +209,11 @@ jobs:
path: packages/preview2-shim/dist

# The runtime integration tests exercise the local transpiler through the API and CLI.
- name: Restore jco-transpile vendor
- name: Restore jco-transpile build output
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: jco-transpile-vendor
path: packages/jco-transpile/vendor
name: jco-transpile-build
path: packages/jco-transpile

- name: Build workspace jco-transpile
run: pnpm --filter '@bytecodealliance/jco-transpile' run build:ts
Expand Down Expand Up @@ -294,8 +292,8 @@ jobs:
- name: Restore jco-transpile build output
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: jco-transpile-vendor
path: packages/jco-transpile/vendor
name: jco-transpile-build
path: packages/jco-transpile
- name: Restore Component Model runtime build output
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
Expand Down Expand Up @@ -375,6 +373,12 @@ jobs:
with:
name: jco-build-ts
path: packages/jco/dist

- name: Restore jco-transpile build output
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: jco-transpile-build
path: packages/jco-transpile
- name: Restore Component Model runtime build output
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
Expand Down Expand Up @@ -457,6 +461,12 @@ jobs:
with:
name: jco-build-ts
path: packages/jco/dist

- name: Restore jco-transpile build output
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: jco-transpile-build
path: packages/jco-transpile
- name: Restore Component Model runtime build output
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
Expand Down Expand Up @@ -623,11 +633,11 @@ jobs:
name: jco-build-ts
path: packages/jco/dist

- name: Restore jco-transpile vendor
- name: Restore jco-transpile build output
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: jco-transpile-vendor
path: packages/jco-transpile/vendor
name: jco-transpile-build
path: packages/jco-transpile

- name: Bundle browser entry against packed tarballs
run: node scripts/build-browser-bundle.mjs
Expand Down Expand Up @@ -871,12 +881,11 @@ jobs:
name: js-generated-tests
path: packages/jco-transpile/test/fixtures/generated

- name: Restore jco-transpile vendor
- name: Restore jco-transpile build output
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: jco-transpile-vendor
path: |
packages/jco-transpile/vendor
name: jco-transpile-build
path: packages/jco-transpile

- name: Install Rust
if: ${{ matrix.project.uses-webidl2wit }}
Expand Down Expand Up @@ -978,6 +987,12 @@ jobs:
name: jco-build-ts
path: packages/jco/dist

- name: Restore jco-transpile build output
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: jco-transpile-build
path: packages/jco-transpile

- name: Restore jco build transpilation output
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
Expand Down Expand Up @@ -1125,11 +1140,11 @@ jobs:
name: jco-cm-runtime-dist
path: packages/jco-cm-runtime/dist

- name: Restore jco-transpile vendor
- name: Restore jco-transpile build output
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: jco-transpile-vendor
path: packages/jco-transpile/vendor
name: jco-transpile-build
path: packages/jco-transpile

- name: Build extended component tree
working-directory: test/components
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 43 additions & 0 deletions crates/js-component-bindgen-component/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ mod bindings {
});
export!(JsComponentBindgenComponent);
}
use bindings::exports::local::js_component_bindgen::scripts::{
self, ScriptComponentOpts, ScriptEngineBackend, ScriptEngineWitInput, ScriptEngineWorld,
};
use bindings::{
AsyncImportsExports, AsyncMode, BindingsMode, EnabledFeatureSet, ExportType, GenerateOptions,
InstantiationMode, PackageMismatch, Transpiled, TypeGenerationOptions, UnpackError, Wit,
Expand Down Expand Up @@ -264,6 +267,46 @@ impl bindings::Guest for JsComponentBindgenComponent {
}
}

/// Implementation of the `local:js-component-bindgen/scripts` interface
impl scripts::Guest for JsComponentBindgenComponent {
fn script_engine_world_new(
inputs: Vec<ScriptEngineWitInput>,
backend: ScriptEngineBackend,
) -> Result<ScriptEngineWorld, String> {
use js_component_bindgen::script;
let inputs: Vec<script::WitInput> = inputs
.into_iter()
.map(|input| script::WitInput {
path: PathBuf::from(input.path),
world: input.world,
})
.collect();
let backend = match backend {
ScriptEngineBackend::Starlingmonkey => script::Backend::StarlingMonkey,
ScriptEngineBackend::Quickjs => script::Backend::QuickJs,
};
let engine = script::engine_world(&inputs, backend).map_err(|e| format!("{e:#}"))?;
Ok(ScriptEngineWorld {
wit: engine.wit,
world_name: engine.world_name,
bootstrap: engine.bootstrap,
imports: engine.imports,
exports: engine.exports,
})
}

fn script_component_new(opts: ScriptComponentOpts) -> Result<Vec<u8>, String> {
use js_component_bindgen::script;
script::script_component(&script::ScriptComponent {
name: opts.name,
source: opts.source,
engine_world: opts.engine_world,
exports: opts.exports,
})
.map_err(|e| format!("{e:#}"))
}
}

fn parse_package_spec(spec: &str) -> Option<String> {
let source = format!("package {spec}; world validate {{}}");
UnresolvedPackageGroup::parse("package-spec.wit", &source)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,62 @@
package local:js-component-bindgen;

/// Script engines and the script-only components that run on them
///
/// A script engine is a JavaScript engine componentized against the union of several WIT
/// worlds, with an extra `jco:script-engine/script-loader` export through which a host feeds it
/// scripts at runtime. A script-only component packages one script's source as a component
/// exporting `jco:script/script`.
interface scripts {
/// A WIT world a script engine must support
record script-engine-wit-input {
/// Path to a WIT file or directory
path: string,
/// World to select within the package (the package's only world if omitted)
%world: option<string>,
}

/// JavaScript engine a script engine bootstrap will be componentized with
enum script-engine-backend {
starlingmonkey,
quickjs,
}

/// A merged script engine world and the bootstrap module that implements it
record script-engine-world {
/// Single WIT document (with nested packages) defining the engine world
wit: string,
/// Name of the engine world within `wit`
world-name: string,
/// JavaScript module to componentize as the engine
bootstrap: string,
/// Specifiers scripts may import
imports: list<string>,
/// JavaScript export names of the engine world, excluding the script loader
exports: list<string>,
}

/// A script to package as a script-only component
record script-component-opts {
/// Name the script is packaged under
name: string,
/// Script source, a bundled ES module
source: string,
/// Fully-qualified engine world the script was bundled against
engine-world: string,
/// JavaScript export names of the script
exports: list<string>,
}

/// Merge WIT worlds into a script engine world and generate the engine's bootstrap module
script-engine-world-new: func(
inputs: list<script-engine-wit-input>,
backend: script-engine-backend,
) -> result<script-engine-world, string>;

/// Package a bundled ES module as a component exporting `jco:script/script`
script-component-new: func(opts: script-component-opts) -> result<list<u8>, string>;
}

world js-component-bindgen {
type files = list<tuple<string, list<u8>>>;
type maps = list<tuple<string, string>>;
Expand Down Expand Up @@ -221,4 +278,6 @@ world js-component-bindgen {

/// Expand an encoded WIT package into a conventional WIT directory file map.
export unpack-wit: func(expected: option<package-spec>, binary: list<u8>) -> result<wit-files, unpack-error>;

export scripts;
}
1 change: 1 addition & 0 deletions crates/js-component-bindgen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ heck = { workspace = true }
log = { workspace = true }
semver = { workspace = true }
wasm-encoder = { workspace = true, features = [ "wasmparser" ] }
wasm-metadata = { workspace = true }
wasmparser = { workspace = true, features = [ "features", "component-model" ] }
wasmtime-environ = { workspace = true, features = ['component-model'] }
wit-bindgen-core = { workspace = true }
Expand Down
1 change: 1 addition & 0 deletions crates/js-component-bindgen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ mod ts_bindgen;
pub mod esm_bindgen;
pub mod function_bindgen;
pub mod names;
pub mod script;
pub mod source;

pub mod intrinsics;
Expand Down
Loading
Loading