Skip to content

Commit 4aae84b

Browse files
emilk486c
authored andcommitted
Remove the need for setting web_sys_unstable_apis (emilk#5000)
* No longer required since emilk#4980 And despite some outdated comments, wgpu/WebGPU doesn't need it either
1 parent 8f4a5bc commit 4aae84b

13 files changed

+3
-49
lines changed

.cargo/config.toml

-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,2 @@
1-
# clipboard api is still unstable, so web-sys requires the below flag to be passed for copy (ctrl + c) to work
2-
# https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html
3-
# check status at https://developer.mozilla.org/en-US/docs/Web/API/Clipboard#browser_compatibility
4-
# we don't use `[build]` because of rust analyzer's build cache invalidation https://github.com/emilk/eframe_template/issues/93
5-
[target.wasm32-unknown-unknown]
6-
rustflags = ["--cfg=web_sys_unstable_apis"]
7-
81
[alias]
92
xtask = "run --quiet --package xtask --"

.github/workflows/deploy_web_demo.yml

+1-5
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,7 @@ concurrency:
2222
cancel-in-progress: false
2323

2424
env:
25-
# web_sys_unstable_apis is required to enable the web_sys clipboard API which eframe web uses,
26-
# as well as by the wasm32-backend of the wgpu crate.
27-
# https://rustwasm.github.io/wasm-bindgen/api/web_sys/struct.Clipboard.html
28-
# https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html
29-
RUSTFLAGS: --cfg=web_sys_unstable_apis -D warnings
25+
RUSTFLAGS: -D warnings
3026
RUSTDOCFLAGS: -D warnings
3127

3228
jobs:

.github/workflows/rust.yml

+1-5
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@ on: [ push, pull_request ]
33
name: Rust
44

55
env:
6-
# web_sys_unstable_apis is required to enable the web_sys clipboard API which eframe web uses,
7-
# as well as by the wasm32-backend of the wgpu crate.
8-
# https://rustwasm.github.io/wasm-bindgen/api/web_sys/struct.Clipboard.html
9-
# https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html
10-
RUSTFLAGS: --cfg=web_sys_unstable_apis -D warnings
6+
RUSTFLAGS: -D warnings
117
RUSTDOCFLAGS: -D warnings
128

139
jobs:

crates/eframe/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ include = [
2121

2222
[package.metadata.docs.rs]
2323
all-features = true
24-
rustc-args = ["--cfg=web_sys_unstable_apis"]
2524
targets = ["x86_64-unknown-linux-gnu", "wasm32-unknown-unknown"]
2625

2726
[lints]

crates/eframe/README.md

-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ You need to either use `edition = "2021"`, or set `resolver = "2"` in the `[work
2828

2929
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`.
3030

31-
To get copy-paste working on web, you need to compile with `export RUSTFLAGS=--cfg=web_sys_unstable_apis`.
32-
3331
## Alternatives
3432
`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.
3533

crates/eframe/src/lib.rs

-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
//! call [`crate::run_native`] from your `main.rs`, and/or use `eframe::WebRunner` from your `lib.rs`.
1111
//!
1212
//! ## Compiling for web
13-
//! To get copy-paste working on web, you need to compile with
14-
//! `export RUSTFLAGS=--cfg=web_sys_unstable_apis`.
15-
//!
1613
//! You need to install the `wasm32` target with `rustup target add wasm32-unknown-unknown`.
1714
//!
1815
//! Build the `.wasm` using `cargo build --target wasm32-unknown-unknown`

crates/eframe/src/web/app_runner.rs

-4
Original file line numberDiff line numberDiff line change
@@ -276,14 +276,10 @@ impl AppRunner {
276276
super::open_url(&open.url, open.new_tab);
277277
}
278278

279-
#[cfg(web_sys_unstable_apis)]
280279
if !copied_text.is_empty() {
281280
super::set_clipboard_text(&copied_text);
282281
}
283282

284-
#[cfg(not(web_sys_unstable_apis))]
285-
let _ = copied_text;
286-
287283
if self.has_focus() {
288284
// The eframe app has focus.
289285
if ime.is_some() {

crates/eframe/src/web/events.rs

-3
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,6 @@ pub(crate) fn on_keyup(event: web_sys::KeyboardEvent, runner: &mut AppRunner) {
279279
}
280280

281281
fn install_copy_cut_paste(runner_ref: &WebRunner, target: &EventTarget) -> Result<(), JsValue> {
282-
#[cfg(web_sys_unstable_apis)]
283282
runner_ref.add_event_listener(target, "paste", |event: web_sys::ClipboardEvent, runner| {
284283
if let Some(data) = event.clipboard_data() {
285284
if let Ok(text) = data.get_data("text") {
@@ -294,7 +293,6 @@ fn install_copy_cut_paste(runner_ref: &WebRunner, target: &EventTarget) -> Resul
294293
}
295294
})?;
296295

297-
#[cfg(web_sys_unstable_apis)]
298296
runner_ref.add_event_listener(target, "cut", |event: web_sys::ClipboardEvent, runner| {
299297
if runner.input.raw.focused {
300298
runner.input.raw.events.push(egui::Event::Cut);
@@ -311,7 +309,6 @@ fn install_copy_cut_paste(runner_ref: &WebRunner, target: &EventTarget) -> Resul
311309
event.prevent_default();
312310
})?;
313311

314-
#[cfg(web_sys_unstable_apis)]
315312
runner_ref.add_event_listener(target, "copy", |event: web_sys::ClipboardEvent, runner| {
316313
if runner.input.raw.focused {
317314
runner.input.raw.events.push(egui::Event::Copy);

crates/eframe/src/web/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,6 @@ fn set_cursor_icon(cursor: egui::CursorIcon) -> Option<()> {
168168
}
169169

170170
/// Set the clipboard text.
171-
#[cfg(web_sys_unstable_apis)]
172171
fn set_clipboard_text(s: &str) {
173172
if let Some(window) = web_sys::window() {
174173
let promise = window.navigator().clipboard().write_text(s);

crates/eframe/src/web/web_runner.rs

-5
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,6 @@ impl WebRunner {
3535
/// Will install a panic handler that will catch and log any panics
3636
#[allow(clippy::new_without_default)]
3737
pub fn new() -> Self {
38-
#[cfg(not(web_sys_unstable_apis))]
39-
log::warn!(
40-
"eframe compiled without RUSTFLAGS='--cfg=web_sys_unstable_apis'. Copying text won't work."
41-
);
42-
4338
let panic_handler = PanicHandler::install();
4439

4540
Self {

scripts/build_demo_web.sh

-5
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@ cd "$script_path/.."
55

66
./scripts/setup_web.sh
77

8-
# This is required to enable the web_sys clipboard API which eframe web uses
9-
# https://rustwasm.github.io/wasm-bindgen/api/web_sys/struct.Clipboard.html
10-
# https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html
11-
export RUSTFLAGS=--cfg=web_sys_unstable_apis
12-
138
CRATE_NAME="egui_demo_app"
149

1510
FEATURES="web_app"

scripts/check.sh

+1-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ set -x
1111

1212
cargo +1.75.0 install --quiet typos-cli
1313

14-
# web_sys_unstable_apis is required to enable the web_sys clipboard API which eframe web uses,
15-
# as well as by the wasm32-backend of the wgpu crate.
16-
export RUSTFLAGS="--cfg=web_sys_unstable_apis -D warnings"
14+
export RUSTFLAGS="-D warnings"
1715
export RUSTDOCFLAGS="-D warnings" # https://github.com/emilk/egui/pull/1454
1816

1917
# Fast checks first:

scripts/wasm_bindgen_check.sh

-5
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@ fi
1414
CRATE_NAME="egui_demo_app"
1515
FEATURES="glow,http,persistence"
1616

17-
# This is required to enable the web_sys clipboard API which eframe web uses
18-
# https://rustwasm.github.io/wasm-bindgen/api/web_sys/struct.Clipboard.html
19-
# https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html
20-
export RUSTFLAGS=--cfg=web_sys_unstable_apis
21-
2217
echo "Building rust…"
2318
BUILD=debug # debug builds are faster
2419

0 commit comments

Comments
 (0)