From 7e5c8819c2ec3b1bcef0fa3e0e582750dcecb6bf Mon Sep 17 00:00:00 2001 From: Kai Ren <tyranron@gmail.com> Date: Tue, 28 Feb 2023 12:00:02 +0200 Subject: [PATCH] Support non-browser WASM (#1147, #1118) - gate `js-sys` and `wasm-bindgen` behind `js` Cargo feature --- .github/workflows/ci.yml | 12 ++++++++---- juniper/CHANGELOG.md | 5 ++++- juniper/Cargo.toml | 17 +++++++++++------ 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 83260259..df18e58d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -125,7 +125,6 @@ jobs: - { feature: graphql-parser, crate: juniper } - { feature: rust_decimal, crate: juniper } - { feature: schema-language, crate: juniper } - - { feature: serde_json, crate: juniper } - { feature: time, crate: juniper } - { feature: url, crate: juniper } - { feature: uuid, crate: juniper } @@ -280,8 +279,10 @@ jobs: fail-fast: false matrix: crate: - - juniper_codegen - juniper + target: + - wasm32-unknown-unknown + - wasm32-wasi toolchain: - stable - beta @@ -292,9 +293,12 @@ jobs: - uses: dtolnay/rust-toolchain@v1 with: toolchain: ${{ matrix.toolchain }} - target: wasm32-unknown-unknown + target: ${{ matrix.target }} - - run: cargo check --target wasm32-unknown-unknown -p ${{ matrix.crate }} + - run: cargo check --target ${{ matrix.target }} -p ${{ matrix.crate }} + ${{ matrix.target == 'wasm32-unknown-unknown' + && '--features js' + || '' }} diff --git a/juniper/CHANGELOG.md b/juniper/CHANGELOG.md index fa547fdd..1a16e570 100644 --- a/juniper/CHANGELOG.md +++ b/juniper/CHANGELOG.md @@ -61,6 +61,7 @@ All user visible changes to `juniper` crate will be documented in this file. Thi - `#[derive(GraphQLInterface)]` macro allowing using structs as GraphQL interfaces. ([#1026]) - [`bigdecimal` crate] integration behind `bigdecimal` [Cargo feature]. ([#1060]) - [`rust_decimal` crate] integration behind `rust_decimal` [Cargo feature]. ([#1060]) +- `js` [Cargo feature] enabling `js-sys` and `wasm-bindgen` support for `wasm32-unknown-unknown` target. ([#1118], [#1147]) ### Changed @@ -112,7 +113,9 @@ All user visible changes to `juniper` crate will be documented in this file. Thi [#1081]: /../../pull/1081 [#1085]: /../../issues/1085 [#1086]: /../../pull/1086 -[#1114]: /../../pull/1119 +[#1118]: /../../issues/1118 +[#1119]: /../../pull/1119 +[#1147]: /../../pull/1147 [ba1ed85b]: /../../commit/ba1ed85b3c3dd77fbae7baf6bc4e693321a94083 [CVE-2022-31173]: /../../security/advisories/GHSA-4rx6-g5vg-5f3j diff --git a/juniper/Cargo.toml b/juniper/Cargo.toml index 5a017b14..d1e35e43 100644 --- a/juniper/Cargo.toml +++ b/juniper/Cargo.toml @@ -31,11 +31,19 @@ default = [ "url", "uuid", ] +bigdecimal = ["dep:bigdecimal"] +bson = ["dep:bson"] +chrono = ["dep:chrono"] chrono-clock = ["chrono", "chrono/clock"] chrono-tz = ["dep:chrono-tz", "dep:regex"] -expose-test-schema = ["anyhow", "serde_json"] +expose-test-schema = ["dep:anyhow", "dep:serde_json"] graphql-parser = ["dep:graphql-parser", "dep:void"] +js = ["chrono?/wasmbind", "time?/wasm-bindgen", "uuid?/js"] +rust_decimal = ["dep:rust_decimal"] schema-language = ["graphql-parser"] +time = ["dep:time"] +url = ["dep:url"] +uuid = ["dep:uuid"] [dependencies] anyhow = { version = "1.0.47", default-features = false, optional = true } @@ -57,17 +65,14 @@ smartstring = "1.0" static_assertions = "1.1" time = { version = "0.3", features = ["formatting", "macros", "parsing"], optional = true } url = { version = "2.0", optional = true } -uuid = { version = "1.0", default-features = false, optional = true } +uuid = { version = "1.3", default-features = false, optional = true } # Fixes for MSRV check. # TODO: Try remove on upgrade of `chrono-tz` crate. regex = { version = "1.6", default-features = false, optional = true } -# TODO: Remove on upgrade to 4.0.1 version of `graphql-parser`. +# TODO: Remove on upgrade to 0.4.1 version of `graphql-parser`. void = { version = "1.0.2", optional = true } -[target.'cfg(target_arch = "wasm32")'.dependencies] -getrandom = { version = "0.2", features = ["js"] } - [dev-dependencies] bencher = "0.1.2" chrono = { version = "0.4.20", features = ["alloc"], default-features = false }