From ce08d8dc2d1f82a6a95cdd3c6bcee25c3aebc126 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Mon, 26 Aug 2024 16:31:38 +0200 Subject: [PATCH] Remove the need for setting `web_sys_unstable_apis` (#5000) * No longer required since https://github.com/emilk/egui/pull/4980 And despite some outdated comments, wgpu/WebGPU doesn't need it either --- .cargo/config.toml | 7 ------- .github/workflows/deploy_web_demo.yml | 6 +----- .github/workflows/rust.yml | 6 +----- crates/eframe/Cargo.toml | 1 - crates/eframe/README.md | 2 -- crates/eframe/src/lib.rs | 3 --- crates/eframe/src/web/app_runner.rs | 4 ---- crates/eframe/src/web/events.rs | 3 --- crates/eframe/src/web/mod.rs | 1 - crates/eframe/src/web/web_runner.rs | 5 ----- scripts/build_demo_web.sh | 5 ----- scripts/check.sh | 4 +--- scripts/wasm_bindgen_check.sh | 5 ----- 13 files changed, 3 insertions(+), 49 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index b18b6ce735d..9741f113e7d 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,9 +1,2 @@ -# clipboard api is still unstable, so web-sys requires the below flag to be passed for copy (ctrl + c) to work -# https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html -# check status at https://developer.mozilla.org/en-US/docs/Web/API/Clipboard#browser_compatibility -# we don't use `[build]` because of rust analyzer's build cache invalidation https://github.com/emilk/eframe_template/issues/93 -[target.wasm32-unknown-unknown] -rustflags = ["--cfg=web_sys_unstable_apis"] - [alias] xtask = "run --quiet --package xtask --" diff --git a/.github/workflows/deploy_web_demo.yml b/.github/workflows/deploy_web_demo.yml index 41203da390b..717266d6362 100644 --- a/.github/workflows/deploy_web_demo.yml +++ b/.github/workflows/deploy_web_demo.yml @@ -22,11 +22,7 @@ concurrency: cancel-in-progress: false env: - # 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 + RUSTFLAGS: -D warnings RUSTDOCFLAGS: -D warnings jobs: diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 73bc00297ec..53b314da862 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -3,11 +3,7 @@ on: [ push, pull_request ] name: Rust env: - # 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 + RUSTFLAGS: -D warnings RUSTDOCFLAGS: -D warnings jobs: diff --git a/crates/eframe/Cargo.toml b/crates/eframe/Cargo.toml index 0b18845c34a..b438bdea7cc 100644 --- a/crates/eframe/Cargo.toml +++ b/crates/eframe/Cargo.toml @@ -21,7 +21,6 @@ include = [ [package.metadata.docs.rs] all-features = true -rustc-args = ["--cfg=web_sys_unstable_apis"] targets = ["x86_64-unknown-linux-gnu", "wasm32-unknown-unknown"] [lints] diff --git a/crates/eframe/README.md b/crates/eframe/README.md index ac57d999844..5ffd427d038 100644 --- a/crates/eframe/README.md +++ b/crates/eframe/README.md @@ -28,8 +28,6 @@ You need to either use `edition = "2021"`, or set `resolver = "2"` in the `[work You can opt-in to the using [`egui_wgpu`](https://github.com/emilk/egui/tree/master/crates/egui_wgpu) for rendering by enabling the `wgpu` feature and setting `NativeOptions::renderer` to `Renderer::Wgpu`. -To get copy-paste working on web, you need to compile with `export RUSTFLAGS=--cfg=web_sys_unstable_apis`. - ## Alternatives `eframe` is not the only way to write an app using `egui`! You can also try [`egui-miniquad`](https://github.com/not-fl3/egui-miniquad), [`bevy_egui`](https://github.com/mvlabat/bevy_egui), [`egui_sdl2_gl`](https://github.com/ArjunNair/egui_sdl2_gl), and others. diff --git a/crates/eframe/src/lib.rs b/crates/eframe/src/lib.rs index fa0e75d2aa6..09f77d743e5 100644 --- a/crates/eframe/src/lib.rs +++ b/crates/eframe/src/lib.rs @@ -10,9 +10,6 @@ //! call [`crate::run_native`] from your `main.rs`, and/or use `eframe::WebRunner` from your `lib.rs`. //! //! ## Compiling for web -//! To get copy-paste working on web, you need to compile with -//! `export RUSTFLAGS=--cfg=web_sys_unstable_apis`. -//! //! You need to install the `wasm32` target with `rustup target add wasm32-unknown-unknown`. //! //! Build the `.wasm` using `cargo build --target wasm32-unknown-unknown` diff --git a/crates/eframe/src/web/app_runner.rs b/crates/eframe/src/web/app_runner.rs index 216fa16ecce..c99f27f073e 100644 --- a/crates/eframe/src/web/app_runner.rs +++ b/crates/eframe/src/web/app_runner.rs @@ -276,14 +276,10 @@ impl AppRunner { super::open_url(&open.url, open.new_tab); } - #[cfg(web_sys_unstable_apis)] if !copied_text.is_empty() { super::set_clipboard_text(&copied_text); } - #[cfg(not(web_sys_unstable_apis))] - let _ = copied_text; - if self.has_focus() { // The eframe app has focus. if ime.is_some() { diff --git a/crates/eframe/src/web/events.rs b/crates/eframe/src/web/events.rs index ad37ef7c0a5..af1cf81a4e8 100644 --- a/crates/eframe/src/web/events.rs +++ b/crates/eframe/src/web/events.rs @@ -279,7 +279,6 @@ pub(crate) fn on_keyup(event: web_sys::KeyboardEvent, runner: &mut AppRunner) { } fn install_copy_cut_paste(runner_ref: &WebRunner, target: &EventTarget) -> Result<(), JsValue> { - #[cfg(web_sys_unstable_apis)] runner_ref.add_event_listener(target, "paste", |event: web_sys::ClipboardEvent, runner| { if let Some(data) = event.clipboard_data() { if let Ok(text) = data.get_data("text") { @@ -294,7 +293,6 @@ fn install_copy_cut_paste(runner_ref: &WebRunner, target: &EventTarget) -> Resul } })?; - #[cfg(web_sys_unstable_apis)] runner_ref.add_event_listener(target, "cut", |event: web_sys::ClipboardEvent, runner| { if runner.input.raw.focused { runner.input.raw.events.push(egui::Event::Cut); @@ -311,7 +309,6 @@ fn install_copy_cut_paste(runner_ref: &WebRunner, target: &EventTarget) -> Resul event.prevent_default(); })?; - #[cfg(web_sys_unstable_apis)] runner_ref.add_event_listener(target, "copy", |event: web_sys::ClipboardEvent, runner| { if runner.input.raw.focused { runner.input.raw.events.push(egui::Event::Copy); diff --git a/crates/eframe/src/web/mod.rs b/crates/eframe/src/web/mod.rs index 7403b54cc14..73ecb540559 100644 --- a/crates/eframe/src/web/mod.rs +++ b/crates/eframe/src/web/mod.rs @@ -168,7 +168,6 @@ fn set_cursor_icon(cursor: egui::CursorIcon) -> Option<()> { } /// Set the clipboard text. -#[cfg(web_sys_unstable_apis)] fn set_clipboard_text(s: &str) { if let Some(window) = web_sys::window() { let promise = window.navigator().clipboard().write_text(s); diff --git a/crates/eframe/src/web/web_runner.rs b/crates/eframe/src/web/web_runner.rs index 0e10a10826e..86b61b2a9c4 100644 --- a/crates/eframe/src/web/web_runner.rs +++ b/crates/eframe/src/web/web_runner.rs @@ -35,11 +35,6 @@ impl WebRunner { /// Will install a panic handler that will catch and log any panics #[allow(clippy::new_without_default)] pub fn new() -> Self { - #[cfg(not(web_sys_unstable_apis))] - log::warn!( - "eframe compiled without RUSTFLAGS='--cfg=web_sys_unstable_apis'. Copying text won't work." - ); - let panic_handler = PanicHandler::install(); Self { diff --git a/scripts/build_demo_web.sh b/scripts/build_demo_web.sh index 3bc33d225c7..282d493e6bc 100755 --- a/scripts/build_demo_web.sh +++ b/scripts/build_demo_web.sh @@ -5,11 +5,6 @@ cd "$script_path/.." ./scripts/setup_web.sh -# This is required to enable the web_sys clipboard API which eframe web uses -# https://rustwasm.github.io/wasm-bindgen/api/web_sys/struct.Clipboard.html -# https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html -export RUSTFLAGS=--cfg=web_sys_unstable_apis - CRATE_NAME="egui_demo_app" FEATURES="web_app" diff --git a/scripts/check.sh b/scripts/check.sh index 5b802f6c606..a7108fa0a20 100755 --- a/scripts/check.sh +++ b/scripts/check.sh @@ -11,9 +11,7 @@ set -x cargo +1.75.0 install --quiet typos-cli -# 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 RUSTFLAGS="-D warnings" export RUSTDOCFLAGS="-D warnings" # https://github.com/emilk/egui/pull/1454 # Fast checks first: diff --git a/scripts/wasm_bindgen_check.sh b/scripts/wasm_bindgen_check.sh index d241cf2065c..5f90c99c662 100755 --- a/scripts/wasm_bindgen_check.sh +++ b/scripts/wasm_bindgen_check.sh @@ -14,11 +14,6 @@ fi CRATE_NAME="egui_demo_app" FEATURES="glow,http,persistence" -# This is required to enable the web_sys clipboard API which eframe web uses -# https://rustwasm.github.io/wasm-bindgen/api/web_sys/struct.Clipboard.html -# https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html -export RUSTFLAGS=--cfg=web_sys_unstable_apis - echo "Building rust…" BUILD=debug # debug builds are faster