diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index eaeda052..f681cc8e 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -3,7 +3,8 @@ on: [push, pull_request] name: CI env: - # web_sys_unstable_apis is required to enable the web_sys clipboard API which eframe web uses + # web_sys_unstable_apis is required to enable the web_sys clipboard API which eframe web uses, + # as well as by the wasm32-backend of the wgpu crate. # https://rustwasm.github.io/wasm-bindgen/api/web_sys/struct.Clipboard.html # https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html RUSTFLAGS: --cfg=web_sys_unstable_apis -D warnings diff --git a/Cargo.lock b/Cargo.lock index 09602b9b..1aa47587 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1257,12 +1257,10 @@ dependencies = [ "ehttp", "image", "poll-promise", - "pollster", "serde", "tracing", "tracing-subscriber", "tracing-wasm", - "wgpu", ] [[package]] @@ -4260,9 +4258,9 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.59" +version = "0.3.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed055ab27f941423197eb86b2035720b1a3ce40504df082cac2ecc6ed73335a1" +checksum = "2fed94beee57daf8dd7d51f2b15dc2bcde92d7a72304cdf662a4371008b71b90" dependencies = [ "js-sys", "wasm-bindgen", diff --git a/crates/eframe/Cargo.toml b/crates/eframe/Cargo.toml index b2104cc8..59eed0d8 100644 --- a/crates/eframe/Cargo.toml +++ b/crates/eframe/Cargo.toml @@ -99,7 +99,7 @@ js-sys = "0.3" percent-encoding = "2.1" wasm-bindgen = "0.2" wasm-bindgen-futures = "0.4" -web-sys = { version = "0.3.52", features = [ +web-sys = { version = "0.3.58", features = [ "BinaryType", "Blob", "Clipboard", diff --git a/crates/eframe/src/web/backend.rs b/crates/eframe/src/web/backend.rs index aed3a81d..ba657615 100644 --- a/crates/eframe/src/web/backend.rs +++ b/crates/eframe/src/web/backend.rs @@ -1,4 +1,4 @@ -use super::{glow_wrapping::WrappedGlowPainter, *}; +use super::{WebPainter, *}; use crate::epi; @@ -162,7 +162,7 @@ fn test_parse_query() { pub struct AppRunner { pub(crate) frame: epi::Frame, egui_ctx: egui::Context, - painter: WrappedGlowPainter, + painter: WebPainter, pub(crate) input: WebInput, app: Box, pub(crate) needs_repaint: std::sync::Arc, @@ -187,8 +187,8 @@ impl AppRunner { web_options: crate::WebOptions, app_creator: epi::AppCreator, ) -> Result { - let painter = WrappedGlowPainter::new(canvas_id, web_options.webgl_context_option) - .map_err(JsValue::from)?; // fail early + let painter = + WebPainter::new(canvas_id, web_options.webgl_context_option).map_err(JsValue::from)?; // fail early let system_theme = if web_options.follow_system_theme { super::system_theme() diff --git a/crates/eframe/src/web/mod.rs b/crates/eframe/src/web/mod.rs index 76a89079..fbd2028f 100644 --- a/crates/eframe/src/web/mod.rs +++ b/crates/eframe/src/web/mod.rs @@ -4,15 +4,16 @@ pub mod backend; mod events; -mod glow_wrapping; mod input; pub mod screen_reader; pub mod storage; mod text_agent; +mod web_glow_painter; pub use backend::*; pub use events::*; pub use storage::*; +pub(crate) use web_glow_painter::WebPainter; use std::collections::BTreeMap; use std::sync::{ diff --git a/crates/eframe/src/web/glow_wrapping.rs b/crates/eframe/src/web/web_glow_painter.rs similarity index 94% rename from crates/eframe/src/web/glow_wrapping.rs rename to crates/eframe/src/web/web_glow_painter.rs index b0ac5c2c..61094928 100644 --- a/crates/eframe/src/web/glow_wrapping.rs +++ b/crates/eframe/src/web/web_glow_painter.rs @@ -1,19 +1,21 @@ -use crate::WebGlContextOption; -use egui::{ClippedPrimitive, Rgba}; -use egui_glow::glow; use wasm_bindgen::JsCast; use wasm_bindgen::JsValue; use web_sys::HtmlCanvasElement; #[cfg(not(target_arch = "wasm32"))] use web_sys::{WebGl2RenderingContext, WebGlRenderingContext}; -pub(crate) struct WrappedGlowPainter { +use egui::{ClippedPrimitive, Rgba}; +use egui_glow::glow; + +use crate::WebGlContextOption; + +pub(crate) struct WebPainter { pub(crate) canvas: HtmlCanvasElement, pub(crate) canvas_id: String, pub(crate) painter: egui_glow::Painter, } -impl WrappedGlowPainter { +impl WebPainter { pub fn new(canvas_id: &str, options: WebGlContextOption) -> Result { let canvas = super::canvas_element_or_die(canvas_id); @@ -32,7 +34,7 @@ impl WrappedGlowPainter { } } -impl WrappedGlowPainter { +impl WebPainter { pub fn gl(&self) -> &std::sync::Arc { self.painter.gl() } @@ -158,9 +160,3 @@ fn init_webgl2(canvas: &HtmlCanvasElement) -> Option<(glow::Context, &'static st Some((gl, shader_prefix)) } - -trait DummyWebGLConstructor { - fn from_webgl1_context(context: web_sys::WebGlRenderingContext) -> Self; - - fn from_webgl2_context(context: web_sys::WebGl2RenderingContext) -> Self; -} diff --git a/crates/egui_demo_app/Cargo.toml b/crates/egui_demo_app/Cargo.toml index 572b722b..af43c763 100644 --- a/crates/egui_demo_app/Cargo.toml +++ b/crates/egui_demo_app/Cargo.toml @@ -34,7 +34,7 @@ serde = [ syntax_highlighting = ["egui_demo_lib/syntax_highlighting"] glow = ["eframe/glow"] -wgpu = ["eframe/wgpu", "bytemuck", "pollster", "dep:wgpu"] +wgpu = ["eframe/wgpu", "bytemuck"] [dependencies] @@ -48,7 +48,6 @@ tracing = "0.1" bytemuck = { version = "1.7.1", optional = true } egui_extras = { version = "0.19.0", optional = true, path = "../egui_extras" } -wgpu = { version = "0.13", optional = true, features = ["webgl"] } # feature "http": ehttp = { version = "0.2.0", optional = true } @@ -57,7 +56,6 @@ image = { version = "0.24", optional = true, default-features = false, features "png", ] } poll-promise = { version = "0.1", optional = true, default-features = false } -pollster = { version = "0.2.5", optional = true } # feature "persistence": serde = { version = "1", optional = true, features = ["derive"] } diff --git a/sh/check.sh b/sh/check.sh index 3370f027..239afd9f 100755 --- a/sh/check.sh +++ b/sh/check.sh @@ -11,7 +11,9 @@ set -x cargo install cargo-cranky # Uses lints defined in Cranky.toml. See https://github.com/ericseppanen/cargo-cranky -export RUSTFLAGS="-D warnings" +# web_sys_unstable_apis is required to enable the web_sys clipboard API which eframe web uses, +# as well as by the wasm32-backend of the wgpu crate. +export RUSTFLAGS="--cfg=web_sys_unstable_apis -D warnings" export RUSTDOCFLAGS="-D warnings" # https://github.com/emilk/egui/pull/1454 cargo check --all-targets