Skip to content

Commit c6b1e3a

Browse files
committed
fix issues with latest getrandom 0.3 and wasm target
- reworked the wasm use case and removed the wasm feature flag, putting everything behind the target specific dependencies Signed-off-by: Andrei Gherghescu <[email protected]>
1 parent b9884f0 commit c6b1e3a

File tree

7 files changed

+21
-20
lines changed

7 files changed

+21
-20
lines changed

.cargo/config.toml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[target.wasm32-unknown-unknown]
2+
rustflags = ['--cfg', 'getrandom_backend="wasm_js"']

.github/workflows/ci.yml

+4-6
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ jobs:
3737
with:
3838
components: clippy
3939
targets: wasm32-unknown-unknown
40-
# lint the main library workspace excluding the wasm feature
41-
- run: cargo clippy --features plotly_ndarray,plotly_image,kaleido -- -D warnings
42-
# lint the plotly library with wasm enabled
43-
- run: cargo clippy --package plotly --features wasm --target wasm32-unknown-unknown -- -D warnings
40+
# lint the main library workspace for non-wasm target
41+
- run: cargo clippy --all-features -- -D warnings
4442
# lint the non-wasm examples
4543
- run: cd ${{ github.workspace }}/examples && cargo clippy --workspace --exclude "wasm*" -- -D warnings
44+
# lint the plotly library for wasm target
45+
- run: cargo clippy --package plotly --target wasm32-unknown-unknown -- -D warnings
4646
# lint the wasm examples
4747
- run: cd ${{ github.workspace }}/examples && cargo clippy --target wasm32-unknown-unknown --package "wasm*"
4848

@@ -83,8 +83,6 @@ jobs:
8383
with:
8484
components: llvm-tools-preview
8585
- uses: taiki-e/install-action@cargo-llvm-cov
86-
# we are skipping anything to do with wasm here
87-
- run: cargo llvm-cov --workspace --features plotly_ndarray,plotly_image,kaleido --lcov --output-path lcov.info
8886
- uses: codecov/codecov-action@v3
8987

9088
build_examples:

examples/wasm-yew-minimal/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ authors = [
88
edition = "2021"
99

1010
[dependencies]
11-
plotly = { path = "../../plotly", features = ["wasm"] }
11+
plotly = { path = "../../plotly" }
1212
yew = "0.21"
1313
yew-hooks = "0.3"
1414
log = "0.4"

plotly/Cargo.toml

+5-5
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,14 @@ plotly_ndarray = ["ndarray"]
2121
plotly_image = ["image"]
2222
plotly_embed_js = []
2323

24-
wasm = ["getrandom", "js-sys", "wasm-bindgen", "wasm-bindgen-futures"]
2524
with-axum = ["rinja/with-axum", "rinja_axum"]
2625

2726
[dependencies]
2827
rinja = { version = "0.3", features = ["serde_json"] }
2928
rinja_axum = { version = "0.3", optional = true }
3029
dyn-clone = "1"
3130
erased-serde = "0.4"
32-
getrandom = { version = "0.2", features = ["js"], optional = true }
3331
image = { version = "0.25", optional = true }
34-
js-sys = { version = "0.3", optional = true }
3532
plotly_derive = { version = "0.12", path = "../plotly_derive" }
3633
plotly_kaleido = { version = "0.12", path = "../plotly_kaleido", optional = true }
3734
ndarray = { version = "0.16", optional = true }
@@ -41,8 +38,11 @@ serde_json = "1.0"
4138
serde_repr = "0.1"
4239
serde_with = ">=2, <4"
4340
rand = "0.9"
44-
wasm-bindgen = { version = "0.2", optional = true }
45-
wasm-bindgen-futures = { version = "0.4", optional = true }
41+
42+
[target.'cfg(target_arch = "wasm32")'.dependencies]
43+
getrandom = { version = "0.3", features = ["wasm_js"] }
44+
wasm-bindgen-futures = { version = "0.4" }
45+
wasm-bindgen = { version = "0.2"}
4646

4747
[dev-dependencies]
4848
csv = "1.1"

plotly/src/bindings.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
//! context, where it is assumed that a remote copy of the Javascript Plotly
33
//! library is available, (i.e. via a CDN).
44
5-
use js_sys::Object;
65
use wasm_bindgen::prelude::*;
6+
use wasm_bindgen_futures::js_sys::Object;
77

88
use crate::Plot;
99

plotly/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ extern crate rand;
66
extern crate rinja;
77
extern crate serde;
88

9-
#[cfg(all(feature = "kaleido", feature = "wasm"))]
9+
#[cfg(all(feature = "kaleido", target_family = "wasm"))]
1010
compile_error!(
11-
r#"The "kaleido" and "wasm" features are mutually exclusive and cannot be activated at the same time. Please disable one or the other."#
11+
r#"The "kaleido" feature is not available on "wasm" targets. Please compile without this feature for the wasm target family."#
1212
);
1313

1414
#[cfg(feature = "plotly_ndarray")]
1515
pub mod ndarray;
1616
#[cfg(feature = "plotly_ndarray")]
1717
pub use crate::ndarray::ArrayTraces;
1818

19-
#[cfg(feature = "wasm")]
19+
#[cfg(target_family = "wasm")]
2020
pub mod bindings;
2121

2222
pub mod common;

plotly/src/plot.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -534,10 +534,11 @@ impl Plot {
534534
serde_json::to_string(self).unwrap()
535535
}
536536

537-
#[cfg(feature = "wasm")]
537+
#[cfg(target_family = "wasm")]
538538
/// Convert a `Plot` to a native Javasript `js_sys::Object`.
539-
pub fn to_js_object(&self) -> js_sys::Object {
540-
use wasm_bindgen::JsCast;
539+
pub fn to_js_object(&self) -> wasm_bindgen_futures::js_sys::Object {
540+
use wasm_bindgen_futures::js_sys;
541+
use wasm_bindgen_futures::wasm_bindgen::JsCast;
541542
// The only reason this could fail is if to_json() produces structurally
542543
// incorrect JSON. That would be a bug, and would require fixing in the
543544
// to_json()/serialization methods, rather than here
@@ -734,7 +735,7 @@ mod tests {
734735

735736
#[test]
736737
#[ignore] // Don't really want it to try and open a browser window every time we run a test.
737-
#[cfg(not(feature = "wasm"))]
738+
#[cfg(not(target_family = "wasm"))]
738739
fn show_image() {
739740
let plot = create_test_plot();
740741
plot.show_image(ImageFormat::PNG, 1024, 680);

0 commit comments

Comments
 (0)