Make cfg=web_sys_unstable_apis optional, fixing cargo check
This commit is contained in:
parent
46471f930d
commit
650450bc3a
5 changed files with 27 additions and 12 deletions
3
.github/workflows/rust.yml
vendored
3
.github/workflows/rust.yml
vendored
|
@ -3,6 +3,9 @@ on: [push, pull_request]
|
|||
name: CI
|
||||
|
||||
env:
|
||||
# This is required to enable the web_sys clipboard API which egui_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
|
||||
RUSTFLAGS: --cfg=web_sys_unstable_apis
|
||||
|
||||
jobs:
|
||||
|
|
|
@ -3,20 +3,23 @@ set -eu
|
|||
|
||||
CRATE_NAME="egui_demo"
|
||||
|
||||
export RUSTFLAGS=--cfg=web_sys_unstable_apis # required for the clipboard API
|
||||
# This is required to enable the web_sys clipboard API which egui_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
|
||||
|
||||
# Clear output from old stuff:
|
||||
rm -rf docs/$CRATE_NAME.wasm
|
||||
rm -f docs/${CRATE_NAME}_bg.wasm
|
||||
|
||||
echo "Building rust…"
|
||||
BUILD=release
|
||||
cargo build --release -p $CRATE_NAME --lib --target wasm32-unknown-unknown
|
||||
cargo build --release -p ${CRATE_NAME} --lib --target wasm32-unknown-unknown
|
||||
|
||||
echo "Generating JS bindings for wasm…"
|
||||
TARGET_NAME="$CRATE_NAME.wasm"
|
||||
TARGET_NAME="${CRATE_NAME}.wasm"
|
||||
wasm-bindgen "target/wasm32-unknown-unknown/$BUILD/$TARGET_NAME" \
|
||||
--out-dir docs --no-modules --no-typescript
|
||||
|
||||
echo "Finished: docs/$CRATE_NAME.wasm"
|
||||
echo "Finished: docs/${CRATE_NAME}.wasm"
|
||||
|
||||
open http://localhost:8888/index.html
|
||||
|
|
|
@ -3,20 +3,23 @@ set -eu
|
|||
|
||||
CRATE_NAME="example_web"
|
||||
|
||||
export RUSTFLAGS=--cfg=web_sys_unstable_apis # required for the clipboard API
|
||||
# This is required to enable the web_sys clipboard API which egui_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
|
||||
|
||||
# Clear output from old stuff:
|
||||
rm -rf docs/$CRATE_NAME.wasm
|
||||
rm -f docs/${CRATE_NAME}_bg.wasm
|
||||
|
||||
echo "Building rust…"
|
||||
BUILD=release
|
||||
cargo build --release -p $CRATE_NAME --lib --target wasm32-unknown-unknown
|
||||
cargo build --release -p ${CRATE_NAME} --lib --target wasm32-unknown-unknown
|
||||
|
||||
echo "Generating JS bindings for wasm…"
|
||||
TARGET_NAME="$CRATE_NAME.wasm"
|
||||
TARGET_NAME="${CRATE_NAME}.wasm"
|
||||
wasm-bindgen "target/wasm32-unknown-unknown/$BUILD/$TARGET_NAME" \
|
||||
--out-dir docs --no-modules --no-typescript
|
||||
|
||||
echo "Finished: docs/$CRATE_NAME.wasm"
|
||||
echo "Finished: docs/${CRATE_NAME}.wasm"
|
||||
|
||||
open http://localhost:8888/example.html
|
||||
|
|
2
check.sh
2
check.sh
|
@ -1,8 +1,6 @@
|
|||
#!/bin/bash
|
||||
set -eu
|
||||
|
||||
export RUSTFLAGS=--cfg=web_sys_unstable_apis # required for the clipboard API
|
||||
|
||||
cargo check --workspace --all-targets --all-features --release
|
||||
cargo fmt --all -- --check
|
||||
CARGO_INCREMENTAL=0 cargo clippy --workspace --all-targets --all-features -- -D warnings -W clippy::all #-W clippy::pedantic -W clippy::restriction -W clippy::nursery
|
||||
|
|
|
@ -197,9 +197,13 @@ pub fn handle_output(output: &egui::Output) {
|
|||
crate::open_url(url);
|
||||
}
|
||||
|
||||
#[cfg(web_sys_unstable_apis)]
|
||||
if !copied_text.is_empty() {
|
||||
set_clipboard_text(copied_text);
|
||||
}
|
||||
|
||||
#[cfg(not(web_sys_unstable_apis))]
|
||||
let _ = copied_text;
|
||||
}
|
||||
|
||||
pub fn set_cursor_icon(cursor: egui::CursorIcon) -> Option<()> {
|
||||
|
@ -211,6 +215,7 @@ pub fn set_cursor_icon(cursor: egui::CursorIcon) -> Option<()> {
|
|||
.ok()
|
||||
}
|
||||
|
||||
#[cfg(web_sys_unstable_apis)]
|
||||
pub fn set_clipboard_text(s: &str) {
|
||||
if let Some(window) = web_sys::window() {
|
||||
let clipboard = window.navigator().clipboard();
|
||||
|
@ -436,6 +441,7 @@ fn install_document_events(runner_ref: &AppRunnerRef) -> Result<(), JsValue> {
|
|||
closure.forget();
|
||||
}
|
||||
|
||||
#[cfg(web_sys_unstable_apis)]
|
||||
{
|
||||
// paste
|
||||
let runner_ref = runner_ref.clone();
|
||||
|
@ -452,6 +458,7 @@ fn install_document_events(runner_ref: &AppRunnerRef) -> Result<(), JsValue> {
|
|||
closure.forget();
|
||||
}
|
||||
|
||||
#[cfg(web_sys_unstable_apis)]
|
||||
{
|
||||
// cut
|
||||
let runner_ref = runner_ref.clone();
|
||||
|
@ -464,6 +471,7 @@ fn install_document_events(runner_ref: &AppRunnerRef) -> Result<(), JsValue> {
|
|||
closure.forget();
|
||||
}
|
||||
|
||||
#[cfg(web_sys_unstable_apis)]
|
||||
{
|
||||
// copy
|
||||
let runner_ref = runner_ref.clone();
|
||||
|
|
Loading…
Reference in a new issue