Skip to content

Commit 8b1713a

Browse files
authored
fix wasm feature gating (#122)
* update ci workflow - expect build fail * typo * fix workflow * gate Plot::show on wasm targets * mutually exclusive wasm and kaleio * update changelog * update workflow * clippy
1 parent 211d092 commit 8b1713a

File tree

6 files changed

+41
-14
lines changed

6 files changed

+41
-14
lines changed

.github/workflows/ci.yml

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,15 @@ jobs:
3636
- uses: dtolnay/rust-toolchain@stable
3737
with:
3838
components: clippy
39-
- run: cargo clippy -- -D warnings
40-
- run: cd ${{ github.workspace }}/examples && cargo clippy -- -D warnings
39+
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
44+
# lint the non-wasm examples
45+
- run: cd ${{ github.workspace }}/examples && cargo clippy --workspace --exclude "wasm*" -- -D warnings
46+
# lint the wasm examples
47+
- run: cd ${{ github.workspace }}/examples && cargo clippy --target wasm32-unknown-unknown --package "wasm*"
4148

4249
test:
4350
name: Tests
@@ -49,7 +56,7 @@ jobs:
4956
steps:
5057
- uses: actions/checkout@v3
5158
- uses: dtolnay/rust-toolchain@stable
52-
- run: cargo test --features=plotly_ndarray,kaleido
59+
- run: cargo test --features plotly_ndarray,plotly_image,kaleido
5360

5461
code-coverage:
5562
name: Code Coverage
@@ -60,15 +67,16 @@ jobs:
6067
with:
6168
components: llvm-tools-preview
6269
- uses: taiki-e/install-action@cargo-llvm-cov
63-
- run: cargo llvm-cov --workspace --features=plotly_ndarray,plotly_image,kaleido --lcov --output-path lcov.info
70+
# we are skipping anything to do with wasm here
71+
- run: cargo llvm-cov --workspace --features plotly_ndarray,plotly_image,kaleido --lcov --output-path lcov.info
6472
- uses: codecov/codecov-action@v3
6573

6674
build_examples:
6775
name: Build Examples
6876
strategy:
6977
fail-fast: false
7078
matrix:
71-
example: [ # missing jupyter and wasm-yew-minimal
79+
example: [ # missing jupyter
7280
3d_charts,
7381
basic_charts,
7482
custom_controls,
@@ -86,4 +94,18 @@ jobs:
8694
- uses: actions/checkout@v3
8795
- uses: dtolnay/rust-toolchain@stable
8896
- run: cd ${{ github.workspace }}/examples/${{ matrix.example }} && cargo build
97+
98+
build_wasm_examples:
99+
name: Build Wasm Examples
100+
strategy:
101+
fail-fast: false
102+
matrix:
103+
example: [wasm-yew-minimal]
104+
runs-on: ubuntu-latest
105+
steps:
106+
- uses: actions/checkout@v3
107+
- uses: dtolnay/rust-toolchain@stable
108+
with:
109+
targets: wasm32-unknown-unknown
110+
- run: cd ${{ github.workspace }}/examples/${{ matrix.example }} && cargo build --target wasm32-unknown-unknown
89111

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
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.8.3] - 2022-11-04
7+
### Fixed
8+
- [[#122](https://github.com/igiagkiozis/plotly/pull/122)] Compilation error for the `wasm` feature.
9+
610
## [0.8.2] - 2022-11-03
711
### Added
812
- [[#110](https://github.com/igiagkiozis/plotly/pull/110)] `LegendGroupTitle` to existing traces.

plotly/src/bindings.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ pub async fn new_plot(id: &str, plot: &Plot) {
2828
// This will only fail if the Rust Plotly library has produced
2929
// plotly-incompatible JSON. An error here should have been handled by the
3030
// library, rather than down here.
31-
new_plot_(id, &plot_obj)
32-
.await
33-
.expect("Error plotting chart");
31+
new_plot_(id, plot_obj).await.expect("Error plotting chart");
3432
}
3533

3634
/// A wrapper around the plotly.js [react](https://plotly.com/javascript/plotlyjs-function-reference/#react)
@@ -45,5 +43,5 @@ pub async fn react(id: &str, plot: &Plot) {
4543
// This will only fail if the Rust Plotly library has produced
4644
// plotly-incompatible JSON. An error here should have been handled by the
4745
// library, rather than down here.
48-
react_(id, &plot_obj).await.expect("Error plotting chart");
46+
react_(id, plot_obj).await.expect("Error plotting chart");
4947
}

plotly/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ extern crate askama;
66
extern crate rand;
77
extern crate serde;
88

9+
#[cfg(all(feature = "kaleido", feature = "wasm"))]
10+
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."#
12+
);
13+
914
#[cfg(feature = "plotly_ndarray")]
1015
pub mod ndarray;
1116
#[cfg(feature = "plotly_ndarray")]

plotly/src/plot.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ impl Plot {
247247
///
248248
/// The HTML file is saved in a temp file, from which it is read and
249249
/// displayed by the browser.
250+
#[cfg(not(target_family = "wasm"))]
250251
pub fn show(&self) {
251252
use std::env;
252253

@@ -405,6 +406,7 @@ impl Plot {
405406
tmpl.render().unwrap()
406407
}
407408

409+
#[cfg(not(target_family = "wasm"))]
408410
fn render_static(&self, format: ImageFormat, width: usize, height: usize) -> String {
409411
let tmpl = StaticPlotTemplate {
410412
plot: self,

plotly/src/private.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,7 @@ where
108108
T: Clone,
109109
{
110110
let mut traces: Vec<Vec<T>> = Vec::new();
111-
let dim_index = if array_traces == ArrayTraces::OverColumns {
112-
1
113-
} else {
114-
0
115-
} as usize;
111+
let dim_index = usize::from(array_traces == ArrayTraces::OverColumns);
116112
let traces_count = traces_matrix.shape()[dim_index];
117113
let get_trace = |index| {
118114
if array_traces == ArrayTraces::OverColumns {

0 commit comments

Comments
 (0)