Skip to content

Commit

Permalink
Remove support for stdweb (#1941)
Browse files Browse the repository at this point in the history
* Remove support for `stdweb`

* Expunge `stdweb`; make `web-sys` the default

* Mark this change as a breaking change

* Re-insert accidental removal of space

* Use the correct cargo feature syntax

* Re-add some `cfg` attributes

* Remove `web-sys` feature from CI
  • Loading branch information
maroider authored May 24, 2021
1 parent b371b40 commit 657b4fd
Show file tree
Hide file tree
Showing 14 changed files with 13 additions and 815 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ jobs:
- { target: aarch64-apple-ios, os: macos-latest, }
# We're using Windows rather than Ubuntu to run the wasm tests because caching cargo-web
# doesn't currently work on Linux.
- { target: wasm32-unknown-unknown, os: windows-latest, features: stdweb, cmd: web }
- { target: wasm32-unknown-unknown, os: windows-latest, features: web-sys, cmd: web }
- { target: wasm32-unknown-unknown, os: windows-latest, cmd: web }

env:
RUST_BACKTRACE: 1
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Unreleased

- **Breaking:** On Web, remove the `stdweb` backend.
- Added `Window::focus_window`to bring the window to the front and set input focus.

# 0.25.0 (2021-05-15)
Expand Down
14 changes: 2 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,17 @@ documentation = "https://docs.rs/winit"
categories = ["gui"]

[package.metadata.docs.rs]
features = ["serde", "web-sys"]
features = ["serde"]
default-target = "x86_64-unknown-linux-gnu"
targets = ["i686-pc-windows-msvc", "x86_64-pc-windows-msvc", "i686-unknown-linux-gnu", "x86_64-unknown-linux-gnu", "x86_64-apple-darwin", "wasm32-unknown-unknown"]

[features]
default = ["x11", "wayland"]
web-sys = ["web_sys", "wasm-bindgen", "instant/wasm-bindgen"]
stdweb = ["std_web", "instant/stdweb"]
x11 = ["x11-dl", "mio", "mio-misc", "percent-encoding", "parking_lot"]
wayland = ["wayland-client", "sctk"]

[dependencies]
instant = "0.1"
instant = { version = "0.1", features = ["wasm-bindgen"] }
lazy_static = "1"
libc = "0.2.64"
log = "0.4"
Expand Down Expand Up @@ -97,7 +95,6 @@ parking_lot = { version = "0.11.0", optional = true }
[target.'cfg(target_arch = "wasm32")'.dependencies.web_sys]
package = "web-sys"
version = "0.3.22"
optional = true
features = [
'console',
"AddEventListenerOptions",
Expand All @@ -123,13 +120,6 @@ features = [

[target.'cfg(target_arch = "wasm32")'.dependencies.wasm-bindgen]
version = "0.2.45"
optional = true

[target.'cfg(target_arch = "wasm32")'.dependencies.std_web]
package = "stdweb"
version = "=0.4.20"
optional = true
features = ["experimental_features_which_may_break_on_minor_version_bumps"]

[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
console_log = "0.2"
4 changes: 1 addition & 3 deletions FEATURES.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,9 @@ Legend:
|Fullscreen |✔️ |✔️ |✔️ |✔️ |**N/A**|✔️ |✔️ |
|Fullscreen toggle |✔️ |✔️ |✔️ |✔️ |**N/A**|✔️ |✔️ |
|Exclusive fullscreen |✔️ |✔️ |✔️ |**N/A** ||✔️ |**N/A**|
|HiDPI support |✔️ |✔️ |✔️ |✔️ |[#721]|✔️ |✔️ \*1|
|HiDPI support |✔️ |✔️ |✔️ |✔️ |[#721]|✔️ |✔️ |
|Popup windows |||||||**N/A**|

\*1: `WindowEvent::ScaleFactorChanged` is not sent on `stdweb` backend.

### System information
|Feature |Windows|MacOS |Linux x11|Linux Wayland|Android|iOS |WASM |
|---------------- | ----- | ---- | ------- | ----------- | ----- | ------- | -------- |
Expand Down
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,7 @@ Winit provides the following features, which can be enabled in your `Cargo.toml`

#### WebAssembly

Winit supports compiling to the `wasm32-unknown-unknown` target with either a
`stdweb` or a `web-sys` backend for use on web browsers. However, please note
that **the `stdweb` backend is being deprecated and may be removed in a future
release of Winit**. The `web-sys` backend is also more feature complete.
Winit supports compiling to the `wasm32-unknown-unknown` target with `web-sys`.

On the web platform, a Winit window is backed by a `<canvas>` element. You can
either [provide Winit with a `<canvas>` element][web with_canvas], or [let Winit
Expand Down
22 changes: 3 additions & 19 deletions examples/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub fn main() {
.build(&event_loop)
.unwrap();

#[cfg(feature = "web-sys")]
#[cfg(target_arch = "wasm32")]
{
use winit::platform::web::WindowExtWebSys;

Expand All @@ -26,28 +26,12 @@ pub fn main() {
.expect("Append canvas to HTML body");
}

#[cfg(feature = "stdweb")]
{
use std_web::web::INode;
use winit::platform::web::WindowExtStdweb;

let canvas = window.canvas();

let document = std_web::web::document();
let body: std_web::web::Node = document.body().expect("Get HTML body").into();

body.append_child(&canvas);
}

event_loop.run(move |event, _, control_flow| {
*control_flow = ControlFlow::Wait;

#[cfg(feature = "web-sys")]
#[cfg(target_arch = "wasm32")]
log::debug!("{:?}", event);

#[cfg(feature = "stdweb")]
std_web::console!(log, "%s", format!("{:?}", event));

match event {
Event::WindowEvent {
event: WindowEvent::CloseRequested,
Expand All @@ -61,7 +45,7 @@ pub fn main() {
});
}

#[cfg(feature = "web-sys")]
#[cfg(target_arch = "wasm32")]
mod wasm {
use wasm_bindgen::prelude::*;

Expand Down
2 changes: 0 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,6 @@ extern crate bitflags;
#[cfg(any(target_os = "macos", target_os = "ios"))]
#[macro_use]
extern crate objc;
#[cfg(all(target_arch = "wasm32", feature = "std_web"))]
extern crate std_web as stdweb;

pub mod dpi;
#[macro_use]
Expand Down
36 changes: 3 additions & 33 deletions src/platform/web.rs
Original file line number Diff line number Diff line change
@@ -1,55 +1,25 @@
#![cfg(target_arch = "wasm32")]

//! The web target does not automatically insert the canvas element object into the web page, to
//! allow end users to determine how the page should be laid out. Use the `WindowExtStdweb` or
//! `WindowExtWebSys` traits (depending on your web backend) to retrieve the canvas from the
//! Window. Alternatively, use the `WindowBuilderExtStdweb` or `WindowBuilderExtWebSys` to provide
//! your own canvas.
//! allow end users to determine how the page should be laid out. Use the `WindowExtWebSys` trait
//! to retrieve the canvas from the Window. Alternatively, use the `WindowBuilderExtWebSys` trait
//! to provide your own canvas.

use crate::window::WindowBuilder;

#[cfg(feature = "stdweb")]
use stdweb::web::html_element::CanvasElement;

#[cfg(feature = "stdweb")]
pub trait WindowExtStdweb {
fn canvas(&self) -> CanvasElement;

/// Whether the browser reports the preferred color scheme to be "dark".
fn is_dark_mode(&self) -> bool;
}

#[cfg(feature = "web-sys")]
use web_sys::HtmlCanvasElement;

#[cfg(feature = "web-sys")]
pub trait WindowExtWebSys {
fn canvas(&self) -> HtmlCanvasElement;

/// Whether the browser reports the preferred color scheme to be "dark".
fn is_dark_mode(&self) -> bool;
}

#[cfg(feature = "stdweb")]
pub trait WindowBuilderExtStdweb {
fn with_canvas(self, canvas: Option<CanvasElement>) -> Self;
}

#[cfg(feature = "stdweb")]
impl WindowBuilderExtStdweb for WindowBuilder {
fn with_canvas(mut self, canvas: Option<CanvasElement>) -> Self {
self.platform_specific.canvas = canvas;

self
}
}

#[cfg(feature = "web-sys")]
pub trait WindowBuilderExtWebSys {
fn with_canvas(self, canvas: Option<HtmlCanvasElement>) -> Self;
}

#[cfg(feature = "web-sys")]
impl WindowBuilderExtWebSys for WindowBuilder {
fn with_canvas(mut self, canvas: Option<HtmlCanvasElement>) -> Self {
self.platform_specific.canvas = canvas;
Expand Down
13 changes: 1 addition & 12 deletions src/platform_impl/web/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Brief introduction to the internals of the web backend:
// Currently, the web backend supports both wasm-bindgen and stdweb as methods of binding to the
// The web backend used to support both wasm-bindgen and stdweb as methods of binding to the
// environment. Because they are both supporting the same underlying APIs, the actual web bindings
// are cordoned off into backend abstractions, which present the thinnest unifying layer possible.
//
Expand All @@ -17,26 +17,15 @@
// incoming events (from the registered handlers) and ensuring they are passed to the user in a
// compliant way.

// Silence warnings from use of deprecated stdweb backend
#![allow(deprecated)]

mod device;
mod error;
mod event_loop;
mod monitor;
mod window;

#[cfg(feature = "web-sys")]
#[path = "web_sys/mod.rs"]
mod backend;

#[cfg(feature = "stdweb")]
#[path = "stdweb/mod.rs"]
mod backend;

#[cfg(not(any(feature = "web-sys", feature = "stdweb")))]
compile_error!("Please select a feature to build for web: `web-sys`, `stdweb`");

pub use self::device::Id as DeviceId;
pub use self::error::OsError;
pub use self::event_loop::{
Expand Down
Loading

0 comments on commit 657b4fd

Please sign in to comment.