emilk / eframe_template

The easy way to make a Rust app with a GUI
Apache License 2.0
785 stars 176 forks source link

`web-sys` 0.3.70 breaking change in unstable Clipboard API causes compilation failure with `wgpu` backend #158

Closed BGR360 closed 1 month ago

BGR360 commented 1 month ago

Repro steps

Clone the template and apply the following change:

--- a/Cargo.toml
+++ b/Cargo.toml
@@ -15,7 +15,7 @@ egui = "0.28"
 eframe = { version = "0.28", default-features = false, features = [
     "accesskit",     # Make egui compatible with screen readers. NOTE: adds a lot of dependencies.
     "default_fonts", # Embed the default egui fonts.
-    "glow",          # Use the glow rendering backend. Alternative: "wgpu".
+    "wgpu",          # Use the glow rendering backend. Alternative: "wgpu".
     "persistence",   # Enable restoring app state when restarting the app.
 ] }
 log = "0.4"

Regenerate Cargo.lock and compile for web:

$ rm Cargo.lock
$ trunk serve
<...>
2024-09-02T05:27:37.357232Z  INFO 📦 starting build
    Blocking waiting for file lock on build directory
   Compiling eframe v0.28.1
error[E0308]: mismatched types
   --> /Users/ben/.cargo/registry/src/index.crates.io-6f17d22bba15001f/eframe-0.28.1/src/web/mod.rs:187:16
    |
187 |         if let Some(clipboard) = window.navigator().clipboard() {
    |                ^^^^^^^^^^^^^^^   ------------------------------ this expression has type `Clipboard`
    |                |
    |                expected `Clipboard`, found `Option<_>`
    |
    = note: expected struct `Clipboard`
                 found enum `std::option::Option<_>`

For more information about this error, try `rustc --explain E0308`.
error: could not compile `eframe` (lib) due to 1 previous error
2024-09-02T05:27:46.561988Z ERROR ❌ error
error from build pipeline

Caused by:
    0: HTML build pipeline failed (1 errors), showing first
    1: error from asset pipeline
    2: running cargo build
    3: error during cargo build execution
    4: cargo call to executable 'cargo' with args: '["build", "--target=wasm32-unknown-unknown", "--manifest-path", "/Users/ben/Documents/Fractals/eframe_template/Cargo.toml"]' returned a bad status: exit status: 101

This has been fixed in eframe on mainline, but not yet released as a new patch version: https://github.com/emilk/egui/pull/4980

I'll send a PR for a stopgap solution until a new eframe is released.