Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
beeb7f4
feat(runtime): trace guarded built-in calls in the debug profile
vados-cosmonic Dec 2, 2026
131befe
feat(runtime): start export tasks from static descriptors
vados-cosmonic Dec 2, 2026
fd0f318
chore(bindgen): update the embedded jco-cm-runtime
vados-cosmonic Dec 2, 2026
4716dd2
perf(bindgen): share export task and lift/lower metadata per instance
vados-cosmonic Dec 2, 2026
ea4830d
feat(bindgen): report why generated bindings need JSPI
vados-cosmonic Dec 2, 2026
816fb3a
feat(transpile): return the JSPI requirement of transpiled bindings
vados-cosmonic Dec 2, 2026
d0fa5e1
feat(jco): warn when transpiled bindings need JSPI
vados-cosmonic Dec 2, 2026
b5cd5b6
fix(bindgen): declare interfaces without items as modules
vados-cosmonic Dec 2, 2026
3cc9ad4
test(transpile): type-check fixture declarations with strict settings
vados-cosmonic Dec 2, 2026
5af6f86
test(transpile): add absolute size budgets for bundled bindings
vados-cosmonic Dec 2, 2026
ab7a965
docs(bindgen): deprecate generating inline intrinsics
vados-cosmonic Dec 2, 2026
96a4310
ci: fail pull requests whose embedded runtime is out of date
vados-cosmonic Dec 2, 2026
814d7a4
feat(bindgen): share synchronous export adapters across bindings
vados-cosmonic Dec 2, 2026
b2b62e9
test(transpile): cover installed adapters and measure export growth
vados-cosmonic Dec 2, 2026
19c3edd
perf(bindgen): emit and compile a repeated core module once
vados-cosmonic Dec 2, 2026
88f9353
test(transpile): cover a core module embedded twice
vados-cosmonic Dec 2, 2026
7b0de4f
perf(transpile): use the sync fast path by default
vados-cosmonic Dec 2, 2026
dee33ed
perf(jco): transpile with the sync fast path by default
vados-cosmonic Dec 2, 2026
442ef92
docs(docs): document the sync fast path as the default
vados-cosmonic Dec 2, 2026
dee4fb8
test(transpile): exercise the shared adapter with task creation
vados-cosmonic Dec 2, 2026
e35634d
chore(bindgen): record the embedded adapter source revision
vados-cosmonic Dec 2, 2026
9cc50d1
refactor(bindgen): iterate over deduplicated module entries
vados-cosmonic Dec 2, 2026
48b8db8
chore(bindgen): refresh the embedded synchronous export runner
vados-cosmonic Dec 2, 2026
3997209
fix(bindgen): match the CLI fast-path default in Rust presets
vados-cosmonic Dec 2, 2026
2b60f19
test(transpile): check the string fixture uses its UTF-16 decoder
vados-cosmonic Dec 2, 2026
6f55efc
style(jco): format runtime target options
vados-cosmonic Dec 2, 2026
54b3284
perf(bindgen): keep per-call stream metadata on shared getters
vados-cosmonic Dec 2, 2026
6384d48
test(transpile): exercise component errors on hosts without JSPI
vados-cosmonic Dec 2, 2026
439ad50
test(p2-shim): load the built filesystem for Windows directory checks
vados-cosmonic Dec 2, 2026
2070720
test(transpile): check task elimination with shared export adapters
vados-cosmonic Dec 2, 2026
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
10 changes: 9 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,21 @@ jobs:
- name: Install node modules
run: pnpm install

# The embedded runtime must match the runtime package, except on a crate
# release pull request, which may deliberately ship an older runtime.
- name: Build and test Component Model runtime
env:
HEAD_REF: ${{ github.head_ref }}
run: |
pnpm --filter '@bytecodealliance/jco-cm-runtime' run build
pnpm --filter '@bytecodealliance/jco-cm-runtime' run types:check
pnpm --filter '@bytecodealliance/jco-cm-runtime' run test
pnpm --filter '@bytecodealliance/jco-cm-runtime' run test:checked
pnpm --filter '@bytecodealliance/jco-transpile' run check:embedded-runtime --advisory
if [[ "$HEAD_REF" == prep-release-js-component-bindgen-v* ]]; then
pnpm --filter '@bytecodealliance/jco-transpile' run check:embedded-runtime --advisory
else
pnpm --filter '@bytecodealliance/jco-transpile' run check:embedded-runtime
fi

- name: Test bindgen runtime configurations
run: |
Expand Down
14 changes: 13 additions & 1 deletion crates/js-component-bindgen-component/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ mod bindings {
"js-component-bindgen/bindings-mode": [#[cfg_attr(test, derive(serde::Deserialize), serde(tag = "tag", rename_all = "kebab-case"))]],
"js-component-bindgen/async-mode": [#[cfg_attr(test, derive(serde::Deserialize), serde(tag = "tag", content = "val", rename_all = "lowercase"))]],
"js-component-bindgen/async-imports-exports": [#[cfg_attr(test, derive(serde::Deserialize))]],
"js-component-bindgen/runtime-target": [#[cfg_attr(test, derive(serde::Deserialize), serde(rename_all = "lowercase"))]],
"js-component-bindgen/runtime-profile": [#[cfg_attr(test, derive(serde::Deserialize), serde(rename_all = "lowercase"))]],
}
});
Expand Down Expand Up @@ -93,6 +94,7 @@ impl bindings::Guest for JsComponentBindgenComponent {
})
.collect(),
sync_fast_path_blocker: diagnostics.sync_fast_path_blocker,
jspi_requirement: diagnostics.jspi_requirement,
})
}

Expand Down Expand Up @@ -363,8 +365,14 @@ impl From<GenerateOptions> for TranspileConfig {
)
.maybe_cm_runtime_es_module(options.cm_runtime_es_module)
.maybe_cm_runtime_sync_imports(options.cm_runtime_sync_imports)
.maybe_cm_runtime_target(options.cm_runtime_target.map(|target| match target {
bindings::RuntimeTarget::Current => js_component_bindgen::RuntimeTarget::Current,
bindings::RuntimeTarget::Compatible => {
js_component_bindgen::RuntimeTarget::Compatible
}
}))
.runtime_profile(options.runtime_profile.map(Into::into).unwrap_or_default())
.perf_sync_fast_path(options.perf_sync_fast_path.unwrap_or(false))
.perf_sync_fast_path(options.perf_sync_fast_path.unwrap_or(true))
.build()
}
}
Expand Down Expand Up @@ -435,6 +443,10 @@ mod tests {

for (flags, config) in [
(&[][..], jco_transpile(name).build()),
(
&["--no-perf-sync-fast-path"],
jco_transpile(name).perf_sync_fast_path(false).build(),
),
(
&["--instantiation"],
instantiation(InstantiationMode::Async),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ world js-component-bindgen {
print-error(error-message),
}

/// Which runtime operations generated adapters can call.
enum runtime-target { current, compatible }

/// Which removable statements a runtime bundled into the bindings keeps.
enum runtime-profile {
/// Remove diagnostics.
Expand Down Expand Up @@ -175,7 +178,7 @@ world js-component-bindgen {
perf-strings-skip-copy-utf16-validation: option<bool>,

/// Call synchronous exports and imports without creating a task for each
/// call (they create one by default).
/// call. Defaults to true; set it to false to create a task for every call.
///
/// Applies only to a component in which that cannot be observed: one
/// component instance, with no asynchronous function, lift or lower, no
Expand All @@ -190,6 +193,8 @@ world js-component-bindgen {
cm-runtime-es-module: option<string>,
/// The external checked provider implements the intrinsics/sync operations.
cm-runtime-sync-imports: option<bool>,
/// Operations available from the selected provider.
cm-runtime-target: option<runtime-target>,

/// Which diagnostics and assertions the bundled Component Model runtime keeps
/// (defaults to `checked`).
Expand Down Expand Up @@ -335,8 +340,11 @@ world js-component-bindgen {
imports: list<string>,
exports: list<tuple<string, export-type>>,
/// Why the sync fast path is not used, set only when perf-sync-fast-path
/// was set and the component is not eligible.
/// was not disabled and the component is not eligible.
sync-fast-path-blocker: option<string>,
/// The boundary of the bindings that needs JavaScript Promise Integration
/// (`WebAssembly.Suspending` and `WebAssembly.promising`), if any.
jspi-requirement: option<string>,
}

/// Generate the file structure for the transpiled of a component
Expand Down
3 changes: 2 additions & 1 deletion crates/js-component-bindgen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ coop-threads = []
external-runtime = []
# Bundle the Component Model runtime under `runtime/` into generated bindings
# that select no external provider, in place of the inline intrinsics.
# Building without this feature, and so generating inline intrinsics, is deprecated.
# TODO(breaking): bundle the runtime unconditionally at the next major release,
# and remove this feature along with the inline intrinsics.
embedded-cm-runtime = [
Expand All @@ -50,7 +51,7 @@ all-features = true
[dependencies]
anyhow = { workspace = true }
base64 = { workspace = true, features = [ "alloc" ] }
bon = { workspace = true, features = [ "std", "alloc" ] }
bon = { workspace = true, features = [ "std", "alloc", "experimental-overwritable" ] }
heck = { workspace = true }
log = { workspace = true }
semver = { workspace = true }
Expand Down
25 changes: 16 additions & 9 deletions crates/js-component-bindgen/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@
$ cargo add js-component-bindgen
```

Generated JavaScript includes its runtime intrinsics inline by default. To
Generated JavaScript includes its runtime intrinsics inline by default.
Generating inline intrinsics is deprecated: enable the `embedded-cm-runtime`
Cargo feature, which jco itself uses, to bundle jco's runtime instead.
The next major release bundles the runtime unconditionally and removes the
inline intrinsics; see [Bundling the jco runtime](#bundling-the-jco-runtime).

To
select an external runtime, enable the opt-in `external-runtime` Cargo feature,
call `transpile_with_config`, and set `TranspileConfig::cm_runtime_es_module` to
`@bytecodealliance/jco-cm-runtime` or another package/directory base. Generated bindings
Expand Down Expand Up @@ -117,7 +123,8 @@ so each instance can take the `debug` option that turns its logging on or off.
Bundling uses Oxc directly in Rust, so it also runs inside the bindgen Wasm
component used by jco's JavaScript API and CLI, which enables the feature.
The feature brings in the Oxc dependencies and the runtime's source text;
without it the crate generates inline intrinsics as before.
without it the crate generates inline intrinsics as before,
which is deprecated and removed in the next major release.
Selecting an external provider works the same way with or without it.

The crate ships the runtime it bundles under `runtime/`:
Expand All @@ -130,20 +137,20 @@ The crate ships the runtime it bundles under `runtime/`:
Both are generated from `packages/jco-cm-runtime` and committed,
so the crate builds without a JavaScript toolchain.

Which runtime the crate embeds is an explicit decision, separate from changes
to either this crate or the runtime package:
The files are kept current with the runtime package:

- builds never regenerate the files, so work on `packages/jco-cm-runtime`
does not reach bundled bindings until the files are updated;
- builds never regenerate the files, so a change to `packages/jco-cm-runtime`
updates them in the same pull request;
- `cargo xtask update-embedded-runtime` updates them from the current runtime
package, and the result is committed like any other change;
- the `update-embedded-runtime` workflow does the same on demand
and opens a pull request with the result;
- `cargo xtask update-embedded-runtime --check` reports whether they differ.

Because the files may deliberately lag behind the runtime package,
CI only warns when they differ,
and comments on the crate's release pull request.
CI fails a pull request whose files differ from the runtime package.
A crate release may still deliberately ship an older runtime,
so on the crate's release pull request CI only warns when they differ,
and comments on it.
Rolldown runs only when the files are updated.

# License
Expand Down
13 changes: 12 additions & 1 deletion crates/js-component-bindgen/examples/transpile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ fn main() -> Result<()> {
let mut cm_runtime_es_module = None;
#[cfg(feature = "external-runtime")]
let mut cm_runtime_sync_imports = None;
#[cfg(feature = "external-runtime")]
let mut cm_runtime_target = None;

for arg in args {
match arg.split_once('=') {
Expand Down Expand Up @@ -73,6 +75,14 @@ fn main() -> Result<()> {
#[cfg(feature = "external-runtime")]
None if arg == "--cm-runtime-sync-imports" => cm_runtime_sync_imports = Some(true),
#[cfg(feature = "external-runtime")]
Some(("--cm-runtime-target", target)) => {
cm_runtime_target = Some(match target {
"current" => js_component_bindgen::RuntimeTarget::Current,
"compatible" => js_component_bindgen::RuntimeTarget::Compatible,
other => bail!("unknown runtime target [{other}]"),
});
}
#[cfg(feature = "external-runtime")]
Some(("--runtime", base)) => cm_runtime_es_module = Some(base.to_string()),
_ => bail!("unknown argument [{arg}]"),
}
Expand All @@ -96,7 +106,8 @@ fn main() -> Result<()> {
#[cfg(feature = "external-runtime")]
let config = config
.maybe_cm_runtime_es_module(cm_runtime_es_module)
.maybe_cm_runtime_sync_imports(cm_runtime_sync_imports);
.maybe_cm_runtime_sync_imports(cm_runtime_sync_imports)
.maybe_cm_runtime_target(cm_runtime_target);
let transpiled = transpile_with_config(&component, config.build())?;

for (path, contents) in transpiled.files {
Expand Down
Loading