Skip to content

Commit 72f0ce2

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 72f0ce2

File tree

10 files changed

+31
-26
lines changed

10 files changed

+31
-26
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:

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file.
33

44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
55

6+
## [0.13.0] - 2025-02-xx
7+
### Changed
8+
- [[#277](https://github.com/plotly/plotly.rs/pull/277)] Removed `wasm` feature flag and put evrything behind target specific dependencies. Added `.cargo/config.toml` for configuration flags needed by `getrandom` version 0.3 on `wasm` targets.
9+
610
## [0.12.1] - 2025-01-02
711
### Fixed
812
- [[#269](https://github.com/plotly/plotly.rs/pull/269)] Fix publishing to crates.io issue

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,15 @@ Enable the `kaleido` feature and opt in for automatic downloading of the `kaleid
116116
# Cargo.toml
117117

118118
[dependencies]
119-
plotly = { version = "0.12", features = ["kaleido", "kaleido_download"] }
119+
plotly = { version = "0.13", features = ["kaleido", "kaleido_download"] }
120120
```
121121

122122
Alternatively, enable only the `kaleido` feature and manually install Kaleido.
123123
```toml
124124
# Cargo.toml
125125

126126
[dependencies]
127-
plotly = { version = "0.12", features = ["kaleido"] }
127+
plotly = { version = "0.13", features = ["kaleido"] }
128128
```
129129

130130
With the feature enabled, plots can be saved as any of `png`, `jpeg`, `webp`, `svg`, `pdf` and `eps`. Note that the plot will be a static image, i.e. they will be non-interactive.
@@ -149,7 +149,7 @@ Using `Plotly.rs` in a Wasm-based frontend framework is possible by enabling the
149149
# Cargo.toml
150150

151151
[dependencies]
152-
plotly = { version = "0.12", features = ["wasm"] }
152+
plotly = { version = "0.13", features = ["wasm"] }
153153
```
154154

155155
First, make sure that you have the Plotly JavaScript library in your base HTML template:

docs/book/src/getting_started.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ To add the ability to save plots in the following formats: png, jpeg, webp, svg,
9797

9898
```toml
9999
[dependencies]
100-
plotly = { version = "0.12", features = ["kaleido"] }
100+
plotly = { version = "0.13", features = ["kaleido"] }
101101
```
102102

103103
## WebAssembly Support

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

+7-7
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,28 @@ 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 }
35-
plotly_derive = { version = "0.12", path = "../plotly_derive" }
36-
plotly_kaleido = { version = "0.12", path = "../plotly_kaleido", optional = true }
32+
plotly_derive = { version = "0.13", path = "../plotly_derive" }
33+
plotly_kaleido = { version = "0.13", path = "../plotly_kaleido", optional = true }
3734
ndarray = { version = "0.16", optional = true }
3835
once_cell = "1"
3936
serde = { version = "1.0", features = ["derive"] }
4037
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)