Skip to content

Commit c882537

Browse files
committed
feat: support using older wasm bindgen versions
1 parent 3cf4a3b commit c882537

File tree

5 files changed

+32
-26
lines changed

5 files changed

+32
-26
lines changed

Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ serde-wasm-bindgen = "0.6.5"
3333
syn = "2.0.17"
3434
proc-macro2 = "1.0.60"
3535
quote = "1.0.28"
36-
wasm-bindgen = { version = "0.2.108" }
37-
wasm-bindgen-cli-support = { version = "0.2.108" }
38-
wasm-bindgen-futures = { version = "0.4.57" }
39-
wasm-bindgen-macro-support = { version = "0.2.108" }
40-
wasm-bindgen-shared = { version = "0.2.108" }
36+
wasm-bindgen = { version = "0.2.106" }
37+
wasm-bindgen-cli-support = { version = "0.2.106" }
38+
wasm-bindgen-futures = { version = "0.4.56" }
39+
wasm-bindgen-macro-support = { version = "0.2.106" }
40+
wasm-bindgen-shared = { version = "0.2.106" }
4141
wasm-bindgen-test = { version = "0.3.58" }
4242
web-sys = { version = "0.3.85", features = [
4343
"AbortController",

worker-build/src/binary.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::build::PBAR;
22
use crate::emoji::{CONFIG, DOWN_ARROW};
3-
use crate::versions::{CUR_ESBUILD_VERSION, CUR_WASM_BINDGEN_VERSION, CUR_WASM_OPT_VERSION};
3+
use crate::versions::{CUR_ESBUILD_VERSION, CUR_WASM_OPT_VERSION};
44
use anyhow::{bail, Context, Result};
55
use flate2::read::GzDecoder;
66
use heck::ToShoutySnakeCase;
@@ -260,17 +260,17 @@ impl BinaryDep for WasmOpt {
260260
}
261261
}
262262

263-
pub struct WasmBindgen;
263+
pub struct WasmBindgen<'a>(pub &'a str);
264264

265-
impl BinaryDep for WasmBindgen {
265+
impl<'a> BinaryDep for WasmBindgen<'a> {
266266
fn full_name(&self) -> &'static str {
267267
"Wasm Bindgen"
268268
}
269269
fn name(&self) -> &'static str {
270270
"wasm-bindgen"
271271
}
272272
fn version(&self) -> String {
273-
CUR_WASM_BINDGEN_VERSION.to_string()
273+
self.0.to_owned()
274274
}
275275
fn target(&self) -> &'static str {
276276
match (std::env::consts::OS, std::env::consts::ARCH) {

worker-build/src/build/mod.rs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::binary::{GetBinary, WasmOpt};
22
use crate::emoji;
33
use crate::lockfile::{DepCheckError, Lockfile};
44
use crate::versions::{
5-
CUR_WASM_BINDGEN_VERSION, CUR_WORKER_VERSION, MIN_WASM_BINDGEN_LIB_VERSION,
5+
CUR_WORKER_VERSION, LATEST_WASM_BINDGEN_VERSION, MIN_WASM_BINDGEN_LIB_VERSION,
66
MIN_WORKER_LIB_VERSION,
77
};
88

@@ -47,6 +47,7 @@ pub struct Build {
4747
pub bindgen_override: bool,
4848
pub extra_args: Vec<String>,
4949
pub extra_options: Vec<String>,
50+
pub wasm_bindgen_version: Option<String>,
5051
}
5152

5253
/// What sort of output we're going to be generating and flags we're invoking
@@ -206,6 +207,7 @@ impl Build {
206207
bindgen_override: false,
207208
extra_args: Vec::new(),
208209
extra_options: build_opts.extra_options,
210+
wasm_bindgen_version: None,
209211
})
210212
}
211213

@@ -372,23 +374,27 @@ impl Build {
372374
DepCheckError::Error(err) => err,
373375
})?;
374376

375-
lockfile
376-
.require_lib(
377-
"wasm-bindgen",
378-
&MIN_WASM_BINDGEN_LIB_VERSION,
379-
&CUR_WASM_BINDGEN_VERSION,
380-
)
381-
.map_err(|err| match err {
382-
DepCheckError::VersionError(msg, _) => anyhow!(msg),
383-
DepCheckError::Error(err) => anyhow!(err),
384-
})?;
377+
self.wasm_bindgen_version = Some(
378+
lockfile
379+
.require_lib(
380+
"wasm-bindgen",
381+
&MIN_WASM_BINDGEN_LIB_VERSION,
382+
&LATEST_WASM_BINDGEN_VERSION,
383+
)
384+
.map_err(|err| match err {
385+
DepCheckError::VersionError(msg, _) => anyhow!(msg),
386+
DepCheckError::Error(err) => anyhow!(err),
387+
})?
388+
.to_string(),
389+
);
385390
Ok(())
386391
}
387392

388393
fn step_install_wasm_bindgen(&mut self) -> Result<()> {
389394
info!("Installing wasm-bindgen-cli...");
390395
use crate::binary::{GetBinary, WasmBindgen};
391-
let (bindgen, bindgen_override) = WasmBindgen.get_binary(None)?;
396+
let (bindgen, bindgen_override) =
397+
WasmBindgen(&self.wasm_bindgen_version.as_ref().unwrap()).get_binary(None)?;
392398
self.bindgen = Some(bindgen);
393399
self.bindgen_override = bindgen_override;
394400
info!("Installing wasm-bindgen-cli was successful.");

worker-build/src/lockfile.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use serde::Deserialize;
1515
#[derive(Clone, Debug, Default, Deserialize)]
1616
pub struct Lockfile {
1717
package: Vec<Package>,
18-
root_package_name: Option<String>,
18+
root_package_name: Option<String>
1919
}
2020

2121
/// This struct represents a single package entry in `Cargo.lock`
@@ -52,7 +52,7 @@ impl Lockfile {
5252
lib_name: &str,
5353
min_version: &Version,
5454
cur_version: &Version,
55-
) -> Result<(), DepCheckError> {
55+
) -> Result<Version, DepCheckError> {
5656
let req = VersionReq::parse(&format!("^{min_version}")).unwrap();
5757
if let Some(version) = self
5858
.get_package_version(lib_name)
@@ -68,6 +68,7 @@ impl Lockfile {
6868
Some(version),
6969
));
7070
}
71+
Ok(version)
7172
} else {
7273
return Err(DepCheckError::VersionError(
7374
format!(
@@ -77,7 +78,6 @@ impl Lockfile {
7778
None,
7879
));
7980
}
80-
Ok(())
8181
}
8282

8383
/// Obtains the package version for the given package

worker-build/src/versions.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ macro_rules! version {
77
}
88

99
// Current build toolchain, always used exactly for builds, unless overridden by {}_BIN env vars
10-
pub(crate) static CUR_WASM_BINDGEN_VERSION: LazyLock<semver::Version> = version!("0.2.108");
10+
pub(crate) static LATEST_WASM_BINDGEN_VERSION: LazyLock<semver::Version> = version!("0.2.108");
1111
pub(crate) static CUR_WASM_OPT_VERSION: &str = "125";
1212
pub(crate) static CUR_ESBUILD_VERSION: LazyLock<semver::Version> = version!("0.27.2");
1313

1414
// Minimum required libraries, validated before build
15-
pub(crate) static MIN_WASM_BINDGEN_LIB_VERSION: LazyLock<semver::Version> = version!("0.2.108"); // 0.2.108 schema version
15+
pub(crate) static MIN_WASM_BINDGEN_LIB_VERSION: LazyLock<semver::Version> = version!("0.2.106");
1616
pub(crate) static MIN_RUSTC_VERSION: LazyLock<semver::Version> = version!("1.71.0"); // wasm-bindgen MSRV
1717

1818
pub(crate) static MIN_WORKER_LIB_VERSION: LazyLock<semver::Version> = version!(&format!(

0 commit comments

Comments
 (0)