Skip to content

Commit

Permalink
Combine demo_glium and demo_web into one egui_demo crate
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Dec 19, 2020
1 parent fb941cf commit d0f6954
Show file tree
Hide file tree
Showing 19 changed files with 93 additions and 111 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ jobs:
with:
command: check

check_demo_web:
name: Check demo_web
check_egui_demo_web:
name: Check egui_demo (web)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand All @@ -34,7 +34,7 @@ jobs:
- uses: actions-rs/cargo@v1
with:
command: check
args: -p demo_web --target wasm32-unknown-unknown
args: -p egui_demo --lib --target wasm32-unknown-unknown

test:
name: Test Suite
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
**/target
/.*.json
/.vscode
/media/*
33 changes: 12 additions & 21 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
[workspace]
members = [
"demo_glium",
"demo_web",
"egui_demo",
"egui_glium",
"egui_web",
"egui",
"example_web",
]


[patch.crates-io]
egui = { path = 'egui' }
egui_glium = { path = 'egui_glium' }
Expand Down
4 changes: 4 additions & 0 deletions build_demo_native.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
set -eu

cargo run --bin egui_demo --release
26 changes: 9 additions & 17 deletions build_demo_web.sh
Original file line number Diff line number Diff line change
@@ -1,30 +1,22 @@
#!/bin/bash
set -eu

# Pre-requisites:
rustup target add wasm32-unknown-unknown
if ! wasm-bindgen --version; then
cargo clean
cargo install -f wasm-bindgen-cli
cargo update
fi

# BUILD=debug
BUILD=release
CRATE_NAME="egui_demo"

export RUSTFLAGS=--cfg=web_sys_unstable_apis # required for the clipboard API

# Clear output from old stuff:
rm -rf docs/demo_web.wasm
rm -rf docs/$CRATE_NAME.wasm

echo "Build rust:"
# cargo build -p demo_web --target wasm32-unknown-unknown
cargo build --release -p demo_web --target wasm32-unknown-unknown
echo "Building rust"
BUILD=release
cargo build --release -p $CRATE_NAME --lib --target wasm32-unknown-unknown

echo "Generate JS bindings for wasm:"
FOLDER_NAME=${PWD##*/}
TARGET_NAME="demo_web.wasm"
echo "Generating JS bindings for 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"

open http://localhost:8888/index.html
26 changes: 9 additions & 17 deletions build_example_web.sh
Original file line number Diff line number Diff line change
@@ -1,30 +1,22 @@
#!/bin/bash
set -eu

# Pre-requisites:
rustup target add wasm32-unknown-unknown
if ! wasm-bindgen --version; then
cargo clean
cargo install -f wasm-bindgen-cli
cargo update
fi

# BUILD=debug
BUILD=release
CRATE_NAME="example_web"

export RUSTFLAGS=--cfg=web_sys_unstable_apis # required for the clipboard API

# Clear output from old stuff:
rm -rf docs/example_web.wasm
rm -rf docs/$CRATE_NAME.wasm

echo "Build rust:"
# cargo build -p example_web --target wasm32-unknown-unknown
cargo build --release -p example_web --target wasm32-unknown-unknown
echo "Building rust"
BUILD=release
cargo build --release -p $CRATE_NAME --lib --target wasm32-unknown-unknown

echo "Generate JS bindings for wasm:"
FOLDER_NAME=${PWD##*/}
TARGET_NAME="example_web.wasm"
echo "Generating JS bindings for 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"

open http://localhost:8888/example.html
4 changes: 0 additions & 4 deletions build_glium.sh

This file was deleted.

8 changes: 4 additions & 4 deletions check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ CARGO_INCREMENTAL=0 cargo clippy --workspace --all-targets --all-features -- -D
cargo test --workspace --all-targets --all-features
cargo test --workspace --doc

cargo check -p egui --target wasm32-unknown-unknown
cargo check -p egui_web --target wasm32-unknown-unknown
cargo check -p demo_web --target wasm32-unknown-unknown
cargo check -p example_web --target wasm32-unknown-unknown
cargo check -p egui --lib --target wasm32-unknown-unknown
cargo check -p egui_web --lib --target wasm32-unknown-unknown
cargo check -p egui_demo --lib --target wasm32-unknown-unknown
cargo check -p example_web --lib --target wasm32-unknown-unknown

# For finding bloat:
# cargo bloat --release --bin demo_glium -n 200 | rg egui
Expand Down
11 changes: 0 additions & 11 deletions demo_glium/Cargo.toml

This file was deleted.

50 changes: 25 additions & 25 deletions docs/demo_web.js → docs/egui_demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,35 +213,35 @@ function makeMutClosure(arg0, arg1, dtor, f) {
return real;
}
function __wbg_adapter_24(arg0, arg1) {
wasm._dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hf85506f45f4e8b16(arg0, arg1);
wasm._dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h81f03ee2d784e177(arg0, arg1);
}

function __wbg_adapter_27(arg0, arg1, arg2) {
wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h047d08be48ab6c09(arg0, arg1, addHeapObject(arg2));
wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h16ce614a5c125c56(arg0, arg1, addHeapObject(arg2));
}

function __wbg_adapter_30(arg0, arg1, arg2) {
wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h047d08be48ab6c09(arg0, arg1, addHeapObject(arg2));
wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h16ce614a5c125c56(arg0, arg1, addHeapObject(arg2));
}

function __wbg_adapter_33(arg0, arg1, arg2) {
wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h047d08be48ab6c09(arg0, arg1, addHeapObject(arg2));
wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h16ce614a5c125c56(arg0, arg1, addHeapObject(arg2));
}

function __wbg_adapter_36(arg0, arg1) {
wasm._dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hf802d845e8b4a07b(arg0, arg1);
wasm._dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hcb627f1d4e0d7728(arg0, arg1);
}

function __wbg_adapter_39(arg0, arg1, arg2) {
wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h047d08be48ab6c09(arg0, arg1, addHeapObject(arg2));
wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h16ce614a5c125c56(arg0, arg1, addHeapObject(arg2));
}

function __wbg_adapter_42(arg0, arg1, arg2) {
wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h047d08be48ab6c09(arg0, arg1, addHeapObject(arg2));
wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h16ce614a5c125c56(arg0, arg1, addHeapObject(arg2));
}

function __wbg_adapter_45(arg0, arg1, arg2) {
wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hf01ebeadb2908509(arg0, arg1, addHeapObject(arg2));
wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h49f53e48165122c2(arg0, arg1, addHeapObject(arg2));
}

/**
Expand Down Expand Up @@ -604,8 +604,8 @@ async function init(input) {
imports.wbg.__wbg_viewport_54305c74f5668b33 = function(arg0, arg1, arg2, arg3, arg4) {
getObject(arg0).viewport(arg1, arg2, arg3, arg4);
};
imports.wbg.__wbg_log_f2e13ca55da8bad3 = function(arg0) {
console.log(getObject(arg0));
imports.wbg.__wbg_error_e325755affc8634b = function(arg0) {
console.error(getObject(arg0));
};
imports.wbg.__wbg_warn_9e92ccdc67085e1b = function(arg0) {
console.warn(getObject(arg0));
Expand Down Expand Up @@ -795,35 +795,35 @@ async function init(input) {
var ret = wasm.memory;
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper434 = function(arg0, arg1, arg2) {
var ret = makeMutClosure(arg0, arg1, 93, __wbg_adapter_24);
imports.wbg.__wbindgen_closure_wrapper308 = function(arg0, arg1, arg2) {
var ret = makeMutClosure(arg0, arg1, 57, __wbg_adapter_24);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper435 = function(arg0, arg1, arg2) {
var ret = makeMutClosure(arg0, arg1, 93, __wbg_adapter_27);
imports.wbg.__wbindgen_closure_wrapper309 = function(arg0, arg1, arg2) {
var ret = makeMutClosure(arg0, arg1, 57, __wbg_adapter_27);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper438 = function(arg0, arg1, arg2) {
var ret = makeMutClosure(arg0, arg1, 93, __wbg_adapter_30);
imports.wbg.__wbindgen_closure_wrapper311 = function(arg0, arg1, arg2) {
var ret = makeMutClosure(arg0, arg1, 57, __wbg_adapter_30);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper440 = function(arg0, arg1, arg2) {
var ret = makeMutClosure(arg0, arg1, 93, __wbg_adapter_33);
imports.wbg.__wbindgen_closure_wrapper313 = function(arg0, arg1, arg2) {
var ret = makeMutClosure(arg0, arg1, 57, __wbg_adapter_33);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper442 = function(arg0, arg1, arg2) {
var ret = makeMutClosure(arg0, arg1, 93, __wbg_adapter_36);
imports.wbg.__wbindgen_closure_wrapper315 = function(arg0, arg1, arg2) {
var ret = makeMutClosure(arg0, arg1, 57, __wbg_adapter_36);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper444 = function(arg0, arg1, arg2) {
var ret = makeMutClosure(arg0, arg1, 93, __wbg_adapter_39);
imports.wbg.__wbindgen_closure_wrapper317 = function(arg0, arg1, arg2) {
var ret = makeMutClosure(arg0, arg1, 57, __wbg_adapter_39);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper446 = function(arg0, arg1, arg2) {
var ret = makeMutClosure(arg0, arg1, 93, __wbg_adapter_42);
imports.wbg.__wbindgen_closure_wrapper320 = function(arg0, arg1, arg2) {
var ret = makeMutClosure(arg0, arg1, 57, __wbg_adapter_42);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper521 = function(arg0, arg1, arg2) {
imports.wbg.__wbindgen_closure_wrapper499 = function(arg0, arg1, arg2) {
var ret = makeMutClosure(arg0, arg1, 128, __wbg_adapter_45);
return addHeapObject(ret);
};
Expand Down
Binary file renamed docs/demo_web_bg.wasm → docs/egui_demo_bg.wasm
Binary file not shown.
4 changes: 2 additions & 2 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@
</script>

<!-- this is the JS generated by the `wasm-bindgen` CLI tool -->
<script src="demo_web.js"></script>
<script src="egui_demo.js"></script>

<script>
// We'll defer our execution until the wasm is ready to go.
// Here we tell bindgen the path to the wasm file so it can start
// initialization and return to us a promise when it's done.
wasm_bindgen("./demo_web_bg.wasm")
wasm_bindgen("./egui_demo_bg.wasm")
.then(on_wasm_loaded)["catch"](console.error);

function on_wasm_loaded() {
Expand Down
12 changes: 9 additions & 3 deletions demo_web/Cargo.toml → egui_demo/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "demo_web"
name = "egui_demo"
version = "0.1.0"
authors = ["Emil Ernerfeldt <[email protected]>"]
license = "MIT OR Apache-2.0"
Expand All @@ -10,8 +10,14 @@ crate-type = ["cdylib", "rlib"]

[dependencies]
egui = { path = "../egui", features = ["serde", "serde_json"] }
serde = { version = "1", features = ["derive"] }

# For compiling natively:
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
egui_glium = { path = "../egui_glium" }

# For compiling to web:
[target.'cfg(target_arch = "wasm32")'.dependencies]
egui_web = { path = "../egui_web" }
js-sys = "0.3"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
wasm-bindgen = "0.2"
2 changes: 2 additions & 0 deletions demo_web/src/lib.rs → egui_demo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
#![cfg_attr(not(debug_assertions), deny(warnings))] // Forbid warnings in release builds
#![warn(clippy::all)]

#[cfg(target_arch = "wasm32")]
use wasm_bindgen::prelude::*;

/// This is the entry-point for all the web-assembly.
/// This is called once from the HTML.
/// It loads the app, installs some callbacks, then returns.
/// You can add more callbacks like this if you want to call in to your code.
#[cfg(target_arch = "wasm32")]
#[wasm_bindgen]
pub fn start(canvas_id: &str) -> Result<(), wasm_bindgen::JsValue> {
let app = egui::DemoApp::default();
Expand Down
1 change: 1 addition & 0 deletions demo_glium/src/main.rs → egui_demo/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#![cfg_attr(not(debug_assertions), deny(warnings))] // Forbid warnings in release builds
#![warn(clippy::all)]

// When compiling natively:
fn main() {
let app = egui::DemoApp::default();
egui_glium::run(Box::new(app));
Expand Down
2 changes: 1 addition & 1 deletion egui_web/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@

This crates allows you to compile GUI code written with [Egui](https://crates.io/crates/egui) to [WASM](https://en.wikipedia.org/wiki/WebAssembly) to run on a web page.

Check out [docs/index.html](https://github.com/emilk/egui/blob/master/docs/index.html), [demo_web](https://github.com/emilk/egui/tree/master/demo_web) and [build_web.sh](https://github.com/emilk/egui/blob/master/build_web.sh) for examples of how to set it up.
Check out [docs/index.html](https://github.com/emilk/egui/blob/master/docs/index.html), [egui_demo](https://github.com/emilk/egui/tree/master/egui_demo) and [build_web.sh](https://github.com/emilk/egui/blob/master/build_web.sh) for examples of how to set it up.

To use `egui_web`, you need to set the `RUSTFLAGS=--cfg=web_sys_unstable_apis` flag.
3 changes: 3 additions & 0 deletions example_web/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# egui_web fetch example

This is an example of how to write a web-app which use the fetch API.
7 changes: 7 additions & 0 deletions setup_web.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
set -eu

# Pre-requisites:
rustup target add wasm32-unknown-unknown
cargo install -f wasm-bindgen-cli
cargo update

0 comments on commit d0f6954

Please sign in to comment.