diff --git a/Cargo.lock b/Cargo.lock index da9a496d..9069ad95 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1482,7 +1482,6 @@ version = "0.1.0" dependencies = [ "serde_json", "worker", - "worker-kv", ] [[package]] @@ -2040,7 +2039,6 @@ dependencies = [ name = "queue-on-workers" version = "0.1.0" dependencies = [ - "js-sys", "serde", "worker", ] diff --git a/examples/axum/Cargo.lock b/examples/axum/Cargo.lock index 295ef18b..0a8c9f20 100644 --- a/examples/axum/Cargo.lock +++ b/examples/axum/Cargo.lock @@ -34,40 +34,13 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" -[[package]] -name = "axum" -version = "0.7.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "edca88bc138befd0323b20752846e6587272d3b03b0343c8ea28a6f819e6e71f" -dependencies = [ - "async-trait", - "axum-core 0.4.5", - "bytes", - "futures-util", - "http", - "http-body", - "http-body-util", - "itoa", - "matchit 0.7.3", - "memchr", - "mime", - "percent-encoding", - "pin-project-lite", - "rustversion", - "serde", - "sync_wrapper", - "tower", - "tower-layer", - "tower-service", -] - [[package]] name = "axum" version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "021e862c184ae977658b36c4500f7feac3221ca5da43e3f25bd04ab6c79a29b5" dependencies = [ - "axum-core 0.5.2", + "axum-core", "bytes", "futures-util", "http", @@ -87,26 +60,6 @@ dependencies = [ "tower-service", ] -[[package]] -name = "axum-core" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09f2bd6146b97ae3359fa0cc6d6b376d9539582c7b4220f041a33ec24c226199" -dependencies = [ - "async-trait", - "bytes", - "futures-util", - "http", - "http-body", - "http-body-util", - "mime", - "pin-project-lite", - "rustversion", - "sync_wrapper", - "tower-layer", - "tower-service", -] - [[package]] name = "axum-core" version = "0.5.2" @@ -130,7 +83,7 @@ dependencies = [ name = "axum-on-workers" version = "0.1.0" dependencies = [ - "axum 0.8.4", + "axum", "tower-service", "wasm-bindgen-futures", "worker", @@ -592,17 +545,6 @@ dependencies = [ "serde_derive", ] -[[package]] -name = "serde-wasm-bindgen" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3b143e2833c57ab9ad3ea280d21fd34e285a42837aeb0ee301f4f41890fa00e" -dependencies = [ - "js-sys", - "serde", - "wasm-bindgen", -] - [[package]] name = "serde-wasm-bindgen" version = "0.6.5" @@ -698,26 +640,6 @@ dependencies = [ "syn", ] -[[package]] -name = "thiserror" -version = "1.0.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "tinystr" version = "0.8.1" @@ -934,12 +856,12 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "worker" -version = "0.5.0" +version = "0.6.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "727789ca7eff9733efbea9d0e97779edc1cf1926e98aee7d7d8afe32805458aa" +checksum = "d9320293035d2074f1fb84baf7d79d7932c183dd04a7e0c143dc75db0d0037ac" dependencies = [ "async-trait", - "axum 0.7.9", + "axum", "bytes", "chrono", "futures-channel", @@ -950,7 +872,7 @@ dependencies = [ "matchit 0.7.3", "pin-project", "serde", - "serde-wasm-bindgen 0.6.5", + "serde-wasm-bindgen", "serde_json", "serde_urlencoded", "tokio", @@ -959,31 +881,15 @@ dependencies = [ "wasm-bindgen-futures", "wasm-streams", "web-sys", - "worker-kv", "worker-macros", "worker-sys", ] -[[package]] -name = "worker-kv" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f06d4d1416a9f8346ee9123b0d9a11b3cfa38e6cfb5a139698017d1597c4d41" -dependencies = [ - "js-sys", - "serde", - "serde-wasm-bindgen 0.5.0", - "serde_json", - "thiserror", - "wasm-bindgen", - "wasm-bindgen-futures", -] - [[package]] name = "worker-macros" -version = "0.5.0" +version = "0.6.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d625c24570ba9207a2617476013335f28a95cbe513e59bb814ffba092a18058" +checksum = "eb37d4f9d99921836a1e4dc21e6041df9b0c2c5fe3c230edddd172a8ef9e251e" dependencies = [ "async-trait", "proc-macro2", @@ -997,9 +903,9 @@ dependencies = [ [[package]] name = "worker-sys" -version = "0.5.0" +version = "0.6.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34563340d41016b4381257c5a16b0d2bc590dbe00500ecfbebcaa16f5f85ce90" +checksum = "07b4e2ca5d405247a986d533bba78c396c941835747977631168b8b05304f1b6" dependencies = [ "cfg-if", "js-sys", diff --git a/examples/axum/Cargo.toml b/examples/axum/Cargo.toml index 7f67fdee..dc8dc32e 100644 --- a/examples/axum/Cargo.toml +++ b/examples/axum/Cargo.toml @@ -10,8 +10,8 @@ release = false crate-type = ["cdylib"] [dependencies] -worker = { version = "0.6.7", features = ['http', 'axum'] } -worker-macros = { version = "0.6.7", features = ['http'] } +worker = { version = "0.7", features = ['http', 'axum'] } +worker-macros = { version = "0.7", features = ['http'] } axum = { version = "0.8", default-features = false } tower-service = "0.3.3" wasm-bindgen-futures = "0.4" diff --git a/examples/axum/wrangler.toml b/examples/axum/wrangler.toml index 8e7d841e..1d6f8e0c 100644 --- a/examples/axum/wrangler.toml +++ b/examples/axum/wrangler.toml @@ -2,4 +2,4 @@ name = "axum-on-workers" main = "build/index.js" [build] -command = "cargo install worker-build && worker-build --release" +command = "cargo install worker-build && worker-build@0.7 --release" diff --git a/examples/custom-req/wrangler.toml b/examples/custom-req/wrangler.toml index fe338654..e08c6ef3 100644 --- a/examples/custom-req/wrangler.toml +++ b/examples/custom-req/wrangler.toml @@ -2,4 +2,4 @@ name = "custom-req-workers" main = "build/index.js" [build] -command = "cargo install worker-build && worker-build --release" +command = "cargo install worker-build@0.7 && worker-build --release" diff --git a/examples/digest/Cargo.toml b/examples/digest/Cargo.toml index 7bb4ee3d..b1785d40 100644 --- a/examples/digest/Cargo.toml +++ b/examples/digest/Cargo.toml @@ -10,5 +10,5 @@ release = false crate-type = ["cdylib"] [dependencies] -worker = { workspace = true } +worker.workspace = true hex = "0.4" diff --git a/examples/digest/wrangler.toml b/examples/digest/wrangler.toml index 151239e6..59eec672 100644 --- a/examples/digest/wrangler.toml +++ b/examples/digest/wrangler.toml @@ -2,4 +2,4 @@ name = "digest-stream-on-workers" main = "build/index.js" [build] -command = "cargo install worker-build && worker-build --release" +command = "cargo install worker-build@0.7 && worker-build --release" diff --git a/examples/fetcher/Cargo.toml b/examples/fetcher/Cargo.toml index 9b375aa0..6a0d87c1 100644 --- a/examples/fetcher/Cargo.toml +++ b/examples/fetcher/Cargo.toml @@ -10,6 +10,6 @@ release = false crate-type = ["cdylib"] [dependencies] -worker = { workspace = true } +worker.workspace = true serde = "1.0.188" serde_json = "1.0.108" diff --git a/examples/fetcher/wrangler.toml b/examples/fetcher/wrangler.toml index 7d04b407..fcf60ef6 100644 --- a/examples/fetcher/wrangler.toml +++ b/examples/fetcher/wrangler.toml @@ -3,4 +3,4 @@ main = "build/worker/shim.mjs" compatibility_date = "2023-03-22" [build] -command = "cargo install worker-build && worker-build --release" +command = "cargo install worker-build@0.7 && worker-build --release" diff --git a/examples/kv/Cargo.toml b/examples/kv/Cargo.toml index f3b35987..5d62174d 100644 --- a/examples/kv/Cargo.toml +++ b/examples/kv/Cargo.toml @@ -11,6 +11,5 @@ release = false crate-type = ["cdylib", "rlib"] [dependencies] -serde_json.workspace = true +serde_json = "1.0" worker.workspace = true -worker-kv.workspace = true diff --git a/examples/kv/src/lib.rs b/examples/kv/src/lib.rs index 2a545ad3..da2d40ab 100644 --- a/examples/kv/src/lib.rs +++ b/examples/kv/src/lib.rs @@ -1,5 +1,5 @@ use worker::{event, Env, Request, Response, Result}; -use worker_kv::KvError; +use worker::kv::KvError; #[event(fetch)] async fn main(_req: Request, env: Env, _: worker::Context) -> Result { diff --git a/examples/queue/Cargo.toml b/examples/queue/Cargo.toml index 21c4308e..e1d3f3b7 100644 --- a/examples/queue/Cargo.toml +++ b/examples/queue/Cargo.toml @@ -12,4 +12,3 @@ crate-type = ["cdylib"] [dependencies] serde = "1" worker = { workspace = true, features = ["queue"] } -js-sys.workspace = true diff --git a/examples/queue/wrangler.toml b/examples/queue/wrangler.toml index d3029c65..d01bdcb7 100644 --- a/examples/queue/wrangler.toml +++ b/examples/queue/wrangler.toml @@ -2,7 +2,7 @@ name = "queue-on-workers" main = "build/index.js" [build] -command = "cargo install worker-build && worker-build --release" +command = "cargo install worker-build@0.7 && worker-build --release" [[queues.consumers]] queue = "mymessages" diff --git a/examples/router/wrangler.toml b/examples/router/wrangler.toml index 0d3d960e..f2d3ac28 100644 --- a/examples/router/wrangler.toml +++ b/examples/router/wrangler.toml @@ -2,4 +2,4 @@ name = "router-on-workers" main = "build/index.js" [build] -command = "cargo install worker-build && worker-build --release" +command = "cargo install worker-build@0.7 && worker-build --release" diff --git a/examples/rpc-client/wrangler.toml b/examples/rpc-client/wrangler.toml index df2fabde..ae6c2bbc 100644 --- a/examples/rpc-client/wrangler.toml +++ b/examples/rpc-client/wrangler.toml @@ -7,4 +7,4 @@ services = [ ] [build] -command = "cargo install worker-build && worker-build --release" \ No newline at end of file +command = "cargo install worker-build@0.7 && worker-build --release" \ No newline at end of file diff --git a/examples/rpc-server/wrangler.toml b/examples/rpc-server/wrangler.toml index 7c13dc27..60a8bfc2 100644 --- a/examples/rpc-server/wrangler.toml +++ b/examples/rpc-server/wrangler.toml @@ -3,4 +3,4 @@ main = "build/index.js" compatibility_date = "2024-04-05" [build] -command = "cargo install worker-build && worker-build --release" +command = "cargo install worker-build@0.7 && worker-build --release" diff --git a/examples/tokio-postgres/wrangler.toml b/examples/tokio-postgres/wrangler.toml index 1894c2cf..746a984a 100644 --- a/examples/tokio-postgres/wrangler.toml +++ b/examples/tokio-postgres/wrangler.toml @@ -6,4 +6,4 @@ binding = "DB" id = "" [build] -command = "cargo install worker-build && worker-build --release" +command = "cargo install worker-build@0.7 && worker-build --release" diff --git a/examples/tracing/Cargo.toml b/examples/tracing/Cargo.toml index 9108ecfb..c0a9bb25 100644 --- a/examples/tracing/Cargo.toml +++ b/examples/tracing/Cargo.toml @@ -10,8 +10,8 @@ release = false crate-type = ["cdylib"] [dependencies] -worker.workspace = true tracing = "0.1" tracing-web = "0.1" tracing-subscriber = { version = "0.3", features = ['time', 'json'] } time = { version = "0.3", features = ['wasm-bindgen'] } +worker.workspace = true diff --git a/examples/tracing/wrangler.toml b/examples/tracing/wrangler.toml index e65e32b5..16d17738 100644 --- a/examples/tracing/wrangler.toml +++ b/examples/tracing/wrangler.toml @@ -2,4 +2,4 @@ name = "tracing-on-workers" main = "build/index.js" [build] -command = "cargo install worker-build && worker-build --release" +command = "cargo install worker-build@0.7 && worker-build --release" diff --git a/templates/axum/Cargo.toml b/templates/axum/Cargo.toml index 5646f7a1..c85d343a 100644 --- a/templates/axum/Cargo.toml +++ b/templates/axum/Cargo.toml @@ -8,7 +8,7 @@ authors = ["{{authors}}"] crate-type = ["cdylib"] [dependencies] -worker = { version = "0.6", features = ['http', 'axum'] } -worker-macros = { version = "0.6", features = ['http'] } +worker = { version = "0.7", features = ['http', 'axum'] } +worker-macros = { version = "0.7", features = ['http'] } axum = { version = "0.8", default-features = false } tower-service = "0.3.3" diff --git a/templates/axum/wrangler.toml b/templates/axum/wrangler.toml index e383bdff..f0defb94 100644 --- a/templates/axum/wrangler.toml +++ b/templates/axum/wrangler.toml @@ -3,4 +3,4 @@ main = "build/index.js" compatibility_date = "{{ "now" | date: "%Y-%m-%d" }}" [build] -command = "cargo install -q worker-build && worker-build --release" \ No newline at end of file +command = "cargo install -q worker-build@0.7 && worker-build --release" \ No newline at end of file diff --git a/templates/hello-world-http/Cargo.toml b/templates/hello-world-http/Cargo.toml index 69109fa5..e8f68204 100644 --- a/templates/hello-world-http/Cargo.toml +++ b/templates/hello-world-http/Cargo.toml @@ -8,6 +8,6 @@ authors = ["{{authors}}"] crate-type = ["cdylib"] [dependencies] -worker = { version = "0.6", features = ['http'] } -worker-macros = { version = "0.6", features = ['http'] } +worker = { version = "0.7", features = ['http'] } +worker-macros = { version = "0.7", features = ['http'] } http = "1.3" diff --git a/templates/hello-world-http/wrangler.toml b/templates/hello-world-http/wrangler.toml index e383bdff..f0defb94 100644 --- a/templates/hello-world-http/wrangler.toml +++ b/templates/hello-world-http/wrangler.toml @@ -3,4 +3,4 @@ main = "build/index.js" compatibility_date = "{{ "now" | date: "%Y-%m-%d" }}" [build] -command = "cargo install -q worker-build && worker-build --release" \ No newline at end of file +command = "cargo install -q worker-build@0.7 && worker-build --release" \ No newline at end of file diff --git a/templates/hello-world/Cargo.toml b/templates/hello-world/Cargo.toml index 0d035948..721ff1b7 100644 --- a/templates/hello-world/Cargo.toml +++ b/templates/hello-world/Cargo.toml @@ -8,5 +8,5 @@ authors = ["{{authors}}"] crate-type = ["cdylib"] [dependencies] -worker = { version = "0.6" } -worker-macros = { version = "0.6" } +worker = { version = "0.7" } +worker-macros = { version = "0.7" } diff --git a/templates/hello-world/wrangler.toml b/templates/hello-world/wrangler.toml index e383bdff..f0defb94 100644 --- a/templates/hello-world/wrangler.toml +++ b/templates/hello-world/wrangler.toml @@ -3,4 +3,4 @@ main = "build/index.js" compatibility_date = "{{ "now" | date: "%Y-%m-%d" }}" [build] -command = "cargo install -q worker-build && worker-build --release" \ No newline at end of file +command = "cargo install -q worker-build@0.7 && worker-build --release" \ No newline at end of file diff --git a/templates/leptos/Cargo.toml b/templates/leptos/Cargo.toml index c82af767..e56da22f 100644 --- a/templates/leptos/Cargo.toml +++ b/templates/leptos/Cargo.toml @@ -22,7 +22,7 @@ leptos_meta = { version = "0.8" } leptos_router = { version = "0.8"{% if use_nightly %}, features = ["nightly"]{% endif %} } tower-service = "0.3" wasm-bindgen = "0.2" -worker = { version = "0.6", features = ["http", "axum", "d1"], optional = true } +worker = { version = "0.7", features = ["http", "axum", "d1"], optional = true } [features] hydrate = ["leptos/hydrate"] diff --git a/templates/leptos/wrangler.toml b/templates/leptos/wrangler.toml index 4536049d..f50e2ed8 100644 --- a/templates/leptos/wrangler.toml +++ b/templates/leptos/wrangler.toml @@ -3,7 +3,7 @@ main = "build/index.js" compatibility_date = "{{ "now" | date: "%Y-%m-%d" }}" [build] -command = "cargo leptos build --release && cargo install -q worker-build && LEPTOS_OUTPUT_NAME={{project-name}} worker-build --release --features ssr" +command = "cargo leptos build --release && cargo install -q worker-build@0.7 && LEPTOS_OUTPUT_NAME={{project-name}} worker-build --release --features ssr" [assets] directory = "./target/site" \ No newline at end of file diff --git a/worker-build/src/build/mod.rs b/worker-build/src/build/mod.rs index 587e3518..4c429e62 100644 --- a/worker-build/src/build/mod.rs +++ b/worker-build/src/build/mod.rs @@ -1,6 +1,6 @@ use crate::binary::{GetBinary, WasmOpt}; use crate::emoji; -use crate::lockfile::Lockfile; +use crate::lockfile::{DepCheckError, Lockfile}; use crate::versions::{ CUR_WASM_BINDGEN_VERSION, CUR_WORKER_VERSION, MIN_WASM_BINDGEN_LIB_VERSION, MIN_WORKER_LIB_VERSION, @@ -11,6 +11,7 @@ mod progressbar; mod target; mod utils; +use console::style; use progressbar::ProgressOutput; /// The global progress bar and user-facing message output. @@ -359,12 +360,39 @@ impl Build { fn step_check_lib_versions(&mut self) -> Result<()> { let lockfile = Lockfile::new(&self.crate_data.data)?; - lockfile.require_lib("worker", &MIN_WORKER_LIB_VERSION, &CUR_WORKER_VERSION)?; - lockfile.require_lib( - "wasm-bindgen", - &MIN_WASM_BINDGEN_LIB_VERSION, - &CUR_WASM_BINDGEN_VERSION, - )?; + + lockfile.require_lib("worker", &MIN_WORKER_LIB_VERSION, &CUR_WORKER_VERSION).map_err(|err| match err { + DepCheckError::VersionError(msg, Some(version)) => { + anyhow!( + "{msg}\n\nEither upgrade to worker@{}, or use an older worker-build toolchain (e.g. by updating wrangler.toml to use `{}`).", + *MIN_WORKER_LIB_VERSION, + style(format!("cargo install worker-build@{}", + // Prior to worker@0.6 toolchain was 0.1 with no lock + if version.major == 0 && version.minor <= 6 { + "0.1".to_string() + // 0.x semver lock + } else if version.major == 0 { + format!("{}.{}", version.major, version.minor) + // N.x semver lock + } else { + version.major.to_string() + })).bold() + ) + }, + DepCheckError::VersionError(msg, None) => anyhow!(msg), + DepCheckError::Error(err) => err, + })?; + + lockfile + .require_lib( + "wasm-bindgen", + &MIN_WASM_BINDGEN_LIB_VERSION, + &CUR_WASM_BINDGEN_VERSION, + ) + .map_err(|err| match err { + DepCheckError::VersionError(msg, _) => anyhow!(msg), + DepCheckError::Error(err) => anyhow!(err), + })?; Ok(()) } diff --git a/worker-build/src/lockfile.rs b/worker-build/src/lockfile.rs index b8b2a13b..887e5347 100644 --- a/worker-build/src/lockfile.rs +++ b/worker-build/src/lockfile.rs @@ -5,7 +5,6 @@ use std::fs; use std::path::PathBuf; -use crate::versions::CUR_WORKER_VERSION; use anyhow::{anyhow, bail, Context, Result}; use cargo_metadata::Metadata; use console::style; @@ -27,6 +26,11 @@ struct Package { dependencies: Option>, } +pub(crate) enum DepCheckError { + VersionError(String, Option), + Error(anyhow::Error), +} + impl Lockfile { /// Read the `Cargo.lock` file for the crate at the given path. pub fn new(crate_data: &Metadata) -> Result { @@ -42,27 +46,36 @@ impl Lockfile { /// Obtains and verifies the given library matches the given semver version /// Min version is used for the semver comparison check /// Cur version is only used for help text + /// Errors with the wrong version if incorrect. pub fn require_lib( &self, lib_name: &str, min_version: &Version, cur_version: &Version, - ) -> Result<()> { - let req = VersionReq::parse(&format!("^{min_version}"))?; - if let Some(version) = self.get_package_version(lib_name)? { + ) -> Result<(), DepCheckError> { + let req = VersionReq::parse(&format!("^{min_version}")).unwrap(); + if let Some(version) = self + .get_package_version(lib_name) + .map_err(|e| DepCheckError::Error(e))? + { if !req.matches(&version) { - anyhow::bail!( - "Unsupported version {}, you must ensure {}\n\nAlternatively, use a different version of worker-build (currently running {}) that supports this {lib_name} version.", - style(format!("{lib_name}@{version}")).bold().red(), - cargo_dep_error(lib_name, cur_version), - *CUR_WORKER_VERSION - ); + return Err(DepCheckError::VersionError( + format!( + "Unsupported version {}, expected {}.", + style(format!("{lib_name}@{version}")).bold().red(), + cargo_dep_error(lib_name, cur_version) + ), + Some(version), + )); } } else { - anyhow::bail!( - "Ensure that you have dependency {}", - cargo_dep_error(lib_name, cur_version) - ); + return Err(DepCheckError::VersionError( + format!( + "Ensure that you have dependency {}", + cargo_dep_error(lib_name, cur_version) + ), + None, + )); } Ok(()) } diff --git a/worker-build/src/main.rs b/worker-build/src/main.rs index c671b331..4f1ac27a 100644 --- a/worker-build/src/main.rs +++ b/worker-build/src/main.rs @@ -56,10 +56,7 @@ pub fn main() -> Result<()> { env_logger::init(); let args: Vec<_> = env::args().collect(); - if matches!( - args.first().map(String::as_str), - Some("--version") | Some("-v") - ) { + if args.len() > 1 && (args[1].as_str() == "--version" || args[1].as_str() == "-v") { println!("{}", VERSION); return Ok(()); } diff --git a/worker-build/src/versions.rs b/worker-build/src/versions.rs index a989246d..9b25c52b 100644 --- a/worker-build/src/versions.rs +++ b/worker-build/src/versions.rs @@ -8,7 +8,7 @@ macro_rules! version { // Current build toolchain, always used exactly for builds, unless overridden by {}_BIN env vars pub(crate) static CUR_WASM_BINDGEN_VERSION: LazyLock = version!("0.2.105"); -pub(crate) static CUR_WASM_OPT_VERSION: &str = "124"; +pub(crate) static CUR_WASM_OPT_VERSION: &str = "125"; pub(crate) static CUR_ESBUILD_VERSION: LazyLock = version!("0.27.0"); // Minimum required libraries, validated before build