Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
44 changes: 11 additions & 33 deletions Cargo.lock

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

32 changes: 16 additions & 16 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,21 @@ chrono = { version = "0.4.41", default-features = false, features = [
futures-channel = "0.3.31"
futures-util = { version = "0.3.31", default-features = false }
http = "1.3"
js-sys = { version = "0.3.90" }
js-sys = { version = "0.3.91" }
serde = { version = "1.0.164", features = ["derive"] }
serde_json = "1.0.140"
serde-wasm-bindgen = "0.6.5"
syn = "2.0.17"
proc-macro2 = "1.0.60"
quote = "1.0.28"
wasm-bindgen = { version = "0.2.113" }
wasm-bindgen-cli-support = { version = "0.2.113" }
wasm-bindgen-futures = { version = "0.4.63" }
wasm-bindgen-macro-support = { version = "0.2.113" }
wasm-bindgen-shared = { version = "0.2.113" }
wasm-bindgen-test = { version = "0.3.63" }
wasm-bindgen = { version = "0.2.114" }
wasm-bindgen-cli-support = { version = "0.2.114" }
wasm-bindgen-futures = { version = "0.4.64" }
wasm-bindgen-macro-support = { version = "0.2.114" }
wasm-bindgen-shared = { version = "0.2.114" }
wasm-bindgen-test = { version = "0.3.64" }
wasm-streams = { version = "0.5.0" }
web-sys = { version = "0.3.90", features = [
web-sys = { version = "0.3.91", features = [
"AbortController",
"AbortSignal",
"BinaryType",
Expand Down Expand Up @@ -103,11 +103,11 @@ opt-level = "z"
# These are local patches we use to test against local wasm bindgen
# We always align on the exact stable wasm bindgen version for releases
[patch.crates-io]
js-sys = { version = "0.3.90", path = './wasm-bindgen/crates/js-sys' }
wasm-bindgen = { version = "0.2.113", path = './wasm-bindgen' }
wasm-bindgen-cli-support = { version = "0.2.113", path = "./wasm-bindgen/crates/cli-support" }
wasm-bindgen-futures = { version = "0.4.63", path = './wasm-bindgen/crates/futures' }
wasm-bindgen-macro-support = { version = "0.2.113", path = "./wasm-bindgen/crates/macro-support" }
wasm-bindgen-shared = { version = "0.2.113", path = "./wasm-bindgen/crates/shared" }
wasm-bindgen-test = { version = "0.3.63", path = "./wasm-bindgen/crates/test" }
web-sys = { version = "0.3.90", path = './wasm-bindgen/crates/web-sys' }
js-sys = { version = "0.3.91", path = './wasm-bindgen/crates/js-sys' }
wasm-bindgen = { version = "0.2.114", path = './wasm-bindgen' }
wasm-bindgen-cli-support = { version = "0.2.114", path = "./wasm-bindgen/crates/cli-support" }
wasm-bindgen-futures = { version = "0.4.64", path = './wasm-bindgen/crates/futures' }
wasm-bindgen-macro-support = { version = "0.2.114", path = "./wasm-bindgen/crates/macro-support" }
wasm-bindgen-shared = { version = "0.2.114", path = "./wasm-bindgen/crates/shared" }
wasm-bindgen-test = { version = "0.3.64", path = "./wasm-bindgen/crates/test" }
web-sys = { version = "0.3.91", path = './wasm-bindgen/crates/web-sys' }
2 changes: 1 addition & 1 deletion wasm-bindgen
Submodule wasm-bindgen updated 143 files
19 changes: 19 additions & 0 deletions worker-build/src/js/shim-unwind.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { WorkerEntrypoint } from "cloudflare:workers";
import * as exports from "./index.js";

Error.stackTraceLimit = 100;

// Best-effort panic logging. Lost after wasm reinit since
// wasm-bindgen calls __wbg_reset_state internally and the
// shim has no hook to re-register.
if (exports.setPanicHook) {
exports.setPanicHook(function (message) {
console.error("Rust panic:", message);
});
}

class Entrypoint extends WorkerEntrypoint {}

$HANDLERS

export default Entrypoint;
2 changes: 1 addition & 1 deletion worker-build/src/js/shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function registerPanicHook() {
exports.setPanicHook(function (message) {
const panicError = new Error("Rust panic: " + message);
console.error('Critical', panicError);
$PANIC_CRITICAL_ERROR
criticalError = true;
});
}

Expand Down
40 changes: 24 additions & 16 deletions worker-build/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use clap::Parser;
const OUT_DIR: &str = "build";

const SHIM_FILE: &str = include_str!("./js/shim.js");
const SHIM_UNWIND_FILE: &str = include_str!("./js/shim-unwind.js");

pub(crate) mod binary;
mod build;
Expand Down Expand Up @@ -115,21 +116,20 @@ pub fn main() -> Result<()> {
}

if module_target {
let shim = SHIM_FILE
.replace("$HANDLERS", &generate_handlers(&staging_dir)?)
.replace(
"$PANIC_CRITICAL_ERROR",
if builder.panic_unwind {
""
} else {
"criticalError = true;"
},
);
let handlers = generate_handlers(&staging_dir)?;
let shim = if builder.panic_unwind {
// In panic=unwind mode, wasm-bindgen 0.2.114+ handles reinit
// natively via __wbg_termination_guard / __wbg_reset_state.
// The shim only provides the WorkerEntrypoint adapter layer.
SHIM_UNWIND_FILE.replace("$HANDLERS", &handlers)
} else {
SHIM_FILE.replace("$HANDLERS", &handlers)
};
let shim_path = output_path(&staging_dir, "shim.js");
fs::write(&shim_path, shim)
.with_context(|| format!("Failed to write {}", shim_path.display()))?;

add_export_wrappers(&staging_dir)?;
add_export_wrappers(&staging_dir, builder.panic_unwind)?;

update_package_json(&staging_dir)?;

Expand Down Expand Up @@ -212,7 +212,7 @@ fn generate_handlers(out_dir: &Path) -> Result<String> {

static SYSTEM_FNS: &[&str] = &["__wbg_reset_state", "setPanicHook"];

fn add_export_wrappers(out_dir: &Path) -> Result<()> {
fn add_export_wrappers(out_dir: &Path, panic_unwind: bool) -> Result<()> {
let index_path = output_path(out_dir, "index.js");
let content = fs::read_to_string(&index_path)
.with_context(|| format!("Failed to read {}", index_path.display()))?;
Expand All @@ -230,10 +230,18 @@ fn add_export_wrappers(out_dir: &Path) -> Result<()> {
let shim_path = output_path(out_dir, "shim.js");
let mut output = fs::read_to_string(&shim_path)
.with_context(|| format!("Failed to read {}", shim_path.display()))?;
for class_name in class_names {
output.push_str(&format!(
"export const {class_name} = new Proxy(exports.{class_name}, classProxyHooks);\n"
));
for class_name in &class_names {
if panic_unwind {
Comment thread
logan-gatlin marked this conversation as resolved.
Outdated
// In panic=unwind mode, wasm-bindgen handles reinit natively.
// Re-export classes directly without Proxy wrapping.
output.push_str(&format!(
"export const {class_name} = exports.{class_name};\n"
Comment thread
logan-gatlin marked this conversation as resolved.
Outdated
));
} else {
output.push_str(&format!(
"export const {class_name} = new Proxy(exports.{class_name}, classProxyHooks);\n"
));
}
}
fs::write(&shim_path, output)
.with_context(|| format!("Failed to write {}", shim_path.display()))?;
Expand Down
2 changes: 1 addition & 1 deletion worker-build/src/versions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ macro_rules! version {
}

// Current build toolchain, always used exactly for builds, unless overridden by {}_BIN env vars
pub(crate) static LATEST_WASM_BINDGEN_VERSION: LazyLock<semver::Version> = version!("0.2.113");
pub(crate) static LATEST_WASM_BINDGEN_VERSION: LazyLock<semver::Version> = version!("0.2.114");
pub(crate) static CUR_WASM_OPT_VERSION: &str = "126";
pub(crate) static CUR_ESBUILD_VERSION: LazyLock<semver::Version> = version!("0.27.3");

Expand Down
Loading