CI: Run cargo clippy for wasm32-unknown-unknown (#2200)
* CI: Run cargo clippy for wasm32-unknown-unknown * wasm32 clippy fixes * Document when AppRunner::new can fail
This commit is contained in:
parent
53b800502a
commit
2b1341095d
10 changed files with 39 additions and 24 deletions
18
.github/workflows/rust.yml
vendored
18
.github/workflows/rust.yml
vendored
|
@ -87,30 +87,48 @@ jobs:
|
||||||
toolchain: 1.61.0
|
toolchain: 1.61.0
|
||||||
target: wasm32-unknown-unknown
|
target: wasm32-unknown-unknown
|
||||||
override: true
|
override: true
|
||||||
|
|
||||||
- run: sudo apt-get update && sudo apt-get install libgtk-3-dev
|
- run: sudo apt-get update && sudo apt-get install libgtk-3-dev
|
||||||
|
|
||||||
- name: Set up cargo cache
|
- name: Set up cargo cache
|
||||||
uses: Swatinem/rust-cache@v2
|
uses: Swatinem/rust-cache@v2
|
||||||
|
|
||||||
|
- name: Install cargo-cranky
|
||||||
|
uses: baptiste0928/cargo-install@v1
|
||||||
|
with:
|
||||||
|
crate: cargo-cranky
|
||||||
|
|
||||||
- name: Check wasm32 egui_demo_app
|
- name: Check wasm32 egui_demo_app
|
||||||
uses: actions-rs/cargo@v1
|
uses: actions-rs/cargo@v1
|
||||||
with:
|
with:
|
||||||
command: check
|
command: check
|
||||||
args: -p egui_demo_app --lib --target wasm32-unknown-unknown
|
args: -p egui_demo_app --lib --target wasm32-unknown-unknown
|
||||||
|
|
||||||
- name: Check wasm32 egui_demo_app --all-features
|
- name: Check wasm32 egui_demo_app --all-features
|
||||||
uses: actions-rs/cargo@v1
|
uses: actions-rs/cargo@v1
|
||||||
with:
|
with:
|
||||||
command: check
|
command: check
|
||||||
args: -p egui_demo_app --lib --target wasm32-unknown-unknown --all-features
|
args: -p egui_demo_app --lib --target wasm32-unknown-unknown --all-features
|
||||||
|
|
||||||
- name: Check wasm32 eframe
|
- name: Check wasm32 eframe
|
||||||
uses: actions-rs/cargo@v1
|
uses: actions-rs/cargo@v1
|
||||||
with:
|
with:
|
||||||
command: check
|
command: check
|
||||||
args: -p eframe --lib --no-default-features --features glow,persistence --target wasm32-unknown-unknown
|
args: -p eframe --lib --no-default-features --features glow,persistence --target wasm32-unknown-unknown
|
||||||
|
|
||||||
- name: wasm-bindgen
|
- name: wasm-bindgen
|
||||||
uses: jetli/wasm-bindgen-action@v0.1.0
|
uses: jetli/wasm-bindgen-action@v0.1.0
|
||||||
with:
|
with:
|
||||||
version: "0.2.83"
|
version: "0.2.83"
|
||||||
|
|
||||||
- run: ./sh/wasm_bindgen_check.sh --skip-setup
|
- run: ./sh/wasm_bindgen_check.sh --skip-setup
|
||||||
|
|
||||||
|
- name: Cranky wasm32
|
||||||
|
uses: actions-rs/cargo@v1
|
||||||
|
with:
|
||||||
|
command: cranky
|
||||||
|
args: --target wasm32-unknown-unknown --all-features -p egui_demo_app --lib -- -D warnings
|
||||||
|
|
||||||
cargo-deny:
|
cargo-deny:
|
||||||
name: cargo deny
|
name: cargo deny
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
|
@ -75,7 +75,7 @@ pub trait App {
|
||||||
///
|
///
|
||||||
/// You need to implement this if you want to be able to access the application from JS using [`AppRunner::app_mut`].
|
/// You need to implement this if you want to be able to access the application from JS using [`AppRunner::app_mut`].
|
||||||
///
|
///
|
||||||
/// This is needed because downcasting Box<dyn App> -> Box<dyn Any> to get &ConcreteApp is not simple in current rust.
|
/// This is needed because downcasting `Box<dyn App>` -> `Box<dyn Any>` to get &`ConcreteApp` is not simple in current rust.
|
||||||
///
|
///
|
||||||
/// Just copy-paste this as your implementation:
|
/// Just copy-paste this as your implementation:
|
||||||
/// ```ignore
|
/// ```ignore
|
||||||
|
|
|
@ -108,6 +108,9 @@ pub use web_sys;
|
||||||
/// eframe::start_web(canvas_id, web_options, Box::new(|cc| Box::new(MyEguiApp::new(cc)))).await
|
/// eframe::start_web(canvas_id, web_options, Box::new(|cc| Box::new(MyEguiApp::new(cc)))).await
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
/// Failing to initialize WebGL graphics.
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
pub async fn start_web(
|
pub async fn start_web(
|
||||||
canvas_id: &str,
|
canvas_id: &str,
|
||||||
|
|
|
@ -101,7 +101,7 @@ fn web_location() -> epi::Location {
|
||||||
|
|
||||||
let query_map = parse_query_map(&query)
|
let query_map = parse_query_map(&query)
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(k, v)| ((*k).to_string(), (*v).to_string()))
|
.map(|(k, v)| ((*k).to_owned(), (*v).to_owned()))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
epi::Location {
|
epi::Location {
|
||||||
|
@ -181,14 +181,14 @@ impl Drop for AppRunner {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AppRunner {
|
impl AppRunner {
|
||||||
|
/// # Errors
|
||||||
|
/// Failure to initialize WebGL renderer.
|
||||||
pub async fn new(
|
pub async fn new(
|
||||||
canvas_id: &str,
|
canvas_id: &str,
|
||||||
web_options: crate::WebOptions,
|
web_options: crate::WebOptions,
|
||||||
app_creator: epi::AppCreator,
|
app_creator: epi::AppCreator,
|
||||||
) -> Result<Self, JsValue> {
|
) -> Result<Self, String> {
|
||||||
let painter = ActiveWebPainter::new(canvas_id, &web_options)
|
let painter = ActiveWebPainter::new(canvas_id, &web_options).await?;
|
||||||
.await
|
|
||||||
.map_err(JsValue::from)?;
|
|
||||||
|
|
||||||
let system_theme = if web_options.follow_system_theme {
|
let system_theme = if web_options.follow_system_theme {
|
||||||
super::system_theme()
|
super::system_theme()
|
||||||
|
@ -469,9 +469,6 @@ pub struct AppRunnerContainer {
|
||||||
impl AppRunnerContainer {
|
impl AppRunnerContainer {
|
||||||
/// Convenience function to reduce boilerplate and ensure that all event handlers
|
/// Convenience function to reduce boilerplate and ensure that all event handlers
|
||||||
/// are dealt with in the same way
|
/// are dealt with in the same way
|
||||||
///
|
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
pub fn add_event_listener<E: wasm_bindgen::JsCast>(
|
pub fn add_event_listener<E: wasm_bindgen::JsCast>(
|
||||||
&mut self,
|
&mut self,
|
||||||
target: &EventTarget,
|
target: &EventTarget,
|
||||||
|
@ -502,7 +499,7 @@ impl AppRunnerContainer {
|
||||||
|
|
||||||
let handle = TargetEvent {
|
let handle = TargetEvent {
|
||||||
target: target.clone(),
|
target: target.clone(),
|
||||||
event_name: event_name.to_string(),
|
event_name: event_name.to_owned(),
|
||||||
closure,
|
closure,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -203,7 +203,7 @@ pub fn install_canvas_events(runner_container: &mut AppRunnerContainer) -> Resul
|
||||||
|
|
||||||
let closure =
|
let closure =
|
||||||
move |event: web_sys::MouseEvent,
|
move |event: web_sys::MouseEvent,
|
||||||
mut _runner_lock: egui::mutex::MutexGuard<AppRunner>| {
|
mut _runner_lock: egui::mutex::MutexGuard<'_, AppRunner>| {
|
||||||
event.prevent_default();
|
event.prevent_default();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -213,7 +213,7 @@ pub fn install_canvas_events(runner_container: &mut AppRunnerContainer) -> Resul
|
||||||
runner_container.add_event_listener(
|
runner_container.add_event_listener(
|
||||||
&canvas,
|
&canvas,
|
||||||
"mousedown",
|
"mousedown",
|
||||||
|event: web_sys::MouseEvent, mut runner_lock: egui::mutex::MutexGuard<AppRunner>| {
|
|event: web_sys::MouseEvent, mut runner_lock: egui::mutex::MutexGuard<'_, AppRunner>| {
|
||||||
if let Some(button) = button_from_mouse_event(&event) {
|
if let Some(button) = button_from_mouse_event(&event) {
|
||||||
let pos = pos_from_mouse_event(runner_lock.canvas_id(), &event);
|
let pos = pos_from_mouse_event(runner_lock.canvas_id(), &event);
|
||||||
let modifiers = runner_lock.input.raw.modifiers;
|
let modifiers = runner_lock.input.raw.modifiers;
|
||||||
|
|
|
@ -54,8 +54,8 @@ pub fn pos_from_touch_event(
|
||||||
|
|
||||||
fn pos_from_touch(canvas_origin: egui::Pos2, touch: &web_sys::Touch) -> egui::Pos2 {
|
fn pos_from_touch(canvas_origin: egui::Pos2, touch: &web_sys::Touch) -> egui::Pos2 {
|
||||||
egui::Pos2 {
|
egui::Pos2 {
|
||||||
x: touch.page_x() as f32 - canvas_origin.x as f32,
|
x: touch.page_x() as f32 - canvas_origin.x,
|
||||||
y: touch.page_y() as f32 - canvas_origin.y as f32,
|
y: touch.page_y() as f32 - canvas_origin.y,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -72,7 +72,7 @@ impl WebPainter for WebPainterGlow {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn destroy(&mut self) {
|
fn destroy(&mut self) {
|
||||||
self.painter.destroy()
|
self.painter.destroy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -116,7 +116,7 @@ impl WebPainter for WebPainterWgpu {
|
||||||
alpha_mode: wgpu::CompositeAlphaMode::Auto,
|
alpha_mode: wgpu::CompositeAlphaMode::Auto,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
self.surface_size = canvas_size.clone();
|
self.surface_size = canvas_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
let frame = self.surface.get_current_texture().map_err(|err| {
|
let frame = self.surface.get_current_texture().map_err(|err| {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
//! Demo app for egui
|
//! Demo app for egui
|
||||||
|
#![allow(clippy::missing_errors_doc)]
|
||||||
|
|
||||||
mod apps;
|
mod apps;
|
||||||
mod backend_panel;
|
mod backend_panel;
|
||||||
|
@ -34,13 +35,7 @@ impl WebHandle {
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub fn stop_web(&self) -> Result<(), wasm_bindgen::JsValue> {
|
pub fn stop_web(&self) -> Result<(), wasm_bindgen::JsValue> {
|
||||||
let mut app = self.handle.lock();
|
let mut app = self.handle.lock();
|
||||||
let res = app.destroy();
|
app.destroy()
|
||||||
|
|
||||||
// let numw = Arc::weak_count(&app);
|
|
||||||
// let nums = Arc::strong_count(&app);
|
|
||||||
// tracing::debug!("runner ref {:?}, {:?}", numw, nums);
|
|
||||||
|
|
||||||
res
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
|
|
|
@ -55,6 +55,8 @@ cargo doc --document-private-items --no-deps --all-features
|
||||||
|
|
||||||
./sh/wasm_bindgen_check.sh
|
./sh/wasm_bindgen_check.sh
|
||||||
|
|
||||||
|
cargo cranky --target wasm32-unknown-unknown --all-features -p egui_demo_app --lib -- -D warnings
|
||||||
|
|
||||||
# cargo install cargo-deny
|
# cargo install cargo-deny
|
||||||
cargo deny check
|
cargo deny check
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue