Support non-browser WASM (#1147, #1118)

- gate `js-sys` and `wasm-bindgen` behind `js` Cargo feature
This commit is contained in:
Kai Ren 2023-02-28 12:00:02 +02:00 committed by GitHub
parent b84621c3b3
commit 7e5c8819c2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 11 deletions

View file

@ -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'
|| '' }}

View file

@ -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

View file

@ -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 }