From a78773db4752be0c7e11e59ac15743b4032260ac Mon Sep 17 00:00:00 2001 From: Kaur Kuut Date: Tue, 2 Jun 2020 19:46:04 +0300 Subject: [PATCH 1/2] Standardize web terminology. --- .github/workflows/ci.yml | 18 ++++---- CHANGELOG.md | 3 ++ Cargo.toml | 9 +++- README.md | 2 +- druid/examples/hello_wasm_web/index.html | 27 ------------ .../{hello_wasm_web => hello_web}/Cargo.toml | 5 ++- .../{hello_wasm_web => hello_web}/README.md | 14 +++--- druid/examples/hello_web/index.html | 24 +++++++++++ .../{hello_wasm_web => hello_web}/index.js | 2 +- .../{hello_wasm_web => hello_web}/src/lib.rs | 2 +- druid/examples/{switch.rs => switches.rs} | 0 druid/examples/wasm/README.md | 39 ----------------- druid/examples/{wasm => web}/.gitignore | 0 druid/examples/{wasm => web}/Cargo.toml | 5 ++- druid/examples/web/README.md | 43 +++++++++++++++++++ druid/examples/{wasm => web}/build.rs | 32 ++++++-------- druid/examples/{wasm => web}/src/lib.rs | 8 ++-- 17 files changed, 120 insertions(+), 113 deletions(-) delete mode 100644 druid/examples/hello_wasm_web/index.html rename druid/examples/{hello_wasm_web => hello_web}/Cargo.toml (79%) rename druid/examples/{hello_wasm_web => hello_web}/README.md (59%) create mode 100644 druid/examples/hello_web/index.html rename druid/examples/{hello_wasm_web => hello_web}/index.js (52%) rename druid/examples/{hello_wasm_web => hello_web}/src/lib.rs (97%) rename druid/examples/{switch.rs => switches.rs} (100%) delete mode 100644 druid/examples/wasm/README.md rename druid/examples/{wasm => web}/.gitignore (100%) rename druid/examples/{wasm => web}/Cargo.toml (85%) create mode 100644 druid/examples/web/README.md rename druid/examples/{wasm => web}/build.rs (84%) rename druid/examples/{wasm => web}/src/lib.rs (88%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 43663b45ee..7434ac72b2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -213,25 +213,25 @@ jobs: command: test args: --manifest-path=docs/book_examples/Cargo.toml --no-run --target wasm32-unknown-unknown - # Clippy and build the special druid-wasm-examples package. - - name: cargo clippy druid-wasm-examples + # Clippy and build the special druid-web-examples package. + - name: cargo clippy druid-web-examples uses: actions-rs/cargo@v1 with: command: clippy - args: --manifest-path=druid/examples/wasm/Cargo.toml --target wasm32-unknown-unknown -- -D warnings + args: --manifest-path=druid/examples/web/Cargo.toml --target wasm32-unknown-unknown -- -D warnings - name: wasm-pack build examples - run: wasm-pack build --dev --target web druid/examples/wasm + run: wasm-pack build --dev --target web druid/examples/web - # Clippy and build the hello_wasm_web example - - name: cargo clippy hello_wasm_web example + # Clippy and build the hello_web example + - name: cargo clippy hello_web example uses: actions-rs/cargo@v1 with: command: clippy - args: --manifest-path=druid/examples/hello_wasm_web/Cargo.toml --target wasm32-unknown-unknown -- -D warnings + args: --manifest-path=druid/examples/hello_web/Cargo.toml --target wasm32-unknown-unknown -- -D warnings - - name: wasm-pack build hello_wasm_web example - run: wasm-pack build --target web druid/examples/hello_wasm_web + - name: wasm-pack build hello_web example + run: wasm-pack build --dev --target web druid/examples/hello_web test-nightly: runs-on: ${{ matrix.os }} diff --git a/CHANGELOG.md b/CHANGELOG.md index c10fa8b45f..9353ed126f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,8 @@ You can find its changes [documented below](#060---2020-06-01). ### Maintenance +- Standardized web targeting terminology. ([#1013] by [@xStrom]) + ### Outside News ## [0.6.0] - 2020-06-01 @@ -313,6 +315,7 @@ Last release without a changelog :( [#1003]: https://github.com/xi-editor/druid/pull/1003 [#1007]: https://github.com/xi-editor/druid/pull/1007 [#1008]: https://github.com/xi-editor/druid/pull/1008 +[#1013]: https://github.com/xi-editor/druid/pull/1013 [Unreleased]: https://github.com/xi-editor/druid/compare/v0.6.0...master [0.6.0]: https://github.com/xi-editor/druid/compare/v0.5.0...v0.6.0 diff --git a/Cargo.toml b/Cargo.toml index 1d20d9d82e..74e0c2f253 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,6 +4,11 @@ members = [ "druid-shell", "druid-derive", "docs/book_examples", - "druid/examples/wasm", - "druid/examples/hello_wasm_web", + "druid/examples/web", + "druid/examples/hello_web", +] +default-members = [ + "druid", + "druid-shell", + "druid-derive", ] diff --git a/README.md b/README.md index 319b214261..c17c83fef5 100644 --- a/README.md +++ b/README.md @@ -91,7 +91,7 @@ alternatives that can offer those capabilities: - Use the the platform-native widgets or mimic them. ([Relm]) - Embed easily into custom render pipelines. ([Conrod]) - Adhere to a specific architectural style such as Elm. ([Iced], [Relm]) -- Support rendering to HTML when compiling for WASM. ([Iced], [Moxie]) +- Support rendering to HTML when targeting the web. ([Iced], [Moxie]) Druid is just one of many ongoing [Rust-native GUI experiments]. If it doesn't suit your use case, perhaps one of the others will! diff --git a/druid/examples/hello_wasm_web/index.html b/druid/examples/hello_wasm_web/index.html deleted file mode 100644 index 60f5731254..0000000000 --- a/druid/examples/hello_wasm_web/index.html +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - Druid WASM example - - - - - - - - - - \ No newline at end of file diff --git a/druid/examples/hello_wasm_web/Cargo.toml b/druid/examples/hello_web/Cargo.toml similarity index 79% rename from druid/examples/hello_wasm_web/Cargo.toml rename to druid/examples/hello_web/Cargo.toml index e0127b8e15..7d402a0930 100644 --- a/druid/examples/hello_wasm_web/Cargo.toml +++ b/druid/examples/hello_web/Cargo.toml @@ -1,8 +1,8 @@ [package] -name = "hello-wasm-web" +name = "hello-web" version = "0.1.0" license = "Apache-2.0" -description = "Minimal wasm example for web" +description = "Minimal web example" repository = "https://github.com/xi-editor/druid" edition = "2018" publish = false @@ -12,5 +12,6 @@ crate-type = ["cdylib", "rlib"] [dependencies] druid = { path="../.." } + wasm-bindgen = "0.2.63" console_error_panic_hook = "0.1.6" diff --git a/druid/examples/hello_wasm_web/README.md b/druid/examples/hello_web/README.md similarity index 59% rename from druid/examples/hello_wasm_web/README.md rename to druid/examples/hello_web/README.md index a86df19fb1..bfb864a74c 100644 --- a/druid/examples/hello_wasm_web/README.md +++ b/druid/examples/hello_web/README.md @@ -1,6 +1,7 @@ -# druid WASM hello world +# Druid web hello world -This is a minimal example of building a single druid application for the web. To build all the druid examples as wasm, check out the main wasm example. +This is a minimal example of building a single druid application for the web. +To build all the druid examples for the web, check out the `web` example directory. ## Building @@ -13,7 +14,9 @@ First build with. > wasm-pack build --target web --dev ``` -This generates a JavaScript module that exports the `wasm_main` function that's been annotated with the `#[wasm_bindgen]` macro. Leave off the `--dev` flag if you're doing a release build. +This generates a JavaScript module that exports the `wasm_main` function that's +been annotated with the `#[wasm_bindgen]` macro. Leave off the `--dev` flag +if you're doing a release build. Now run @@ -21,9 +24,10 @@ Now run > http ``` -which should start serving this folder. +which should start serving this directory. Finally, point your browser to the appropriate localhost url (usually http://localhost:8000) and you should see your app. -When you make changes to the project, re-run `wasm-pack build --target web --dev` and you can see the changes in your browser when you refresh -- no need to restart `http`. \ No newline at end of file +When you make changes to the project, re-run `wasm-pack build --target web --dev` and you can +see the changes in your browser when you refresh -- no need to restart `http`. diff --git a/druid/examples/hello_web/index.html b/druid/examples/hello_web/index.html new file mode 100644 index 0000000000..daf8dd0c56 --- /dev/null +++ b/druid/examples/hello_web/index.html @@ -0,0 +1,24 @@ + + + + + Druid web example + + + + + + + + diff --git a/druid/examples/hello_wasm_web/index.js b/druid/examples/hello_web/index.js similarity index 52% rename from druid/examples/hello_wasm_web/index.js rename to druid/examples/hello_web/index.js index 3207dd9121..2b113bf209 100644 --- a/druid/examples/hello_wasm_web/index.js +++ b/druid/examples/hello_web/index.js @@ -1,4 +1,4 @@ -import init, { wasm_main } from "./pkg/hello_wasm_web.js"; +import init, { wasm_main } from "./pkg/hello_web.js"; async function run() { await init(); diff --git a/druid/examples/hello_wasm_web/src/lib.rs b/druid/examples/hello_web/src/lib.rs similarity index 97% rename from druid/examples/hello_wasm_web/src/lib.rs rename to druid/examples/hello_web/src/lib.rs index 2c2e877e47..719698fdab 100644 --- a/druid/examples/hello_wasm_web/src/lib.rs +++ b/druid/examples/hello_web/src/lib.rs @@ -29,7 +29,7 @@ struct HelloState { // hello.rs example. #[wasm_bindgen] pub fn wasm_main() { - // This hook is necessary to get panic messages on wasm32 + // This hook is necessary to get panic messages in the console std::panic::set_hook(Box::new(console_error_panic_hook::hook)); main() } diff --git a/druid/examples/switch.rs b/druid/examples/switches.rs similarity index 100% rename from druid/examples/switch.rs rename to druid/examples/switches.rs diff --git a/druid/examples/wasm/README.md b/druid/examples/wasm/README.md deleted file mode 100644 index 4d6c2cae1e..0000000000 --- a/druid/examples/wasm/README.md +++ /dev/null @@ -1,39 +0,0 @@ -# druid WASM examples - -This crate generates and builds all necessary files for deploying `druid` examples to the web. - -## Building - -You will need `cargo` and `wasm-pack` for building the code and a simple -server like [`http`](https://crates.io/crates/https) for serving the web pages. - -First build with - -``` -> wasm-pack build --target web -``` - -This step has two main functions: - - 1. It generates an HTML document for each of the `druid` examples with a script that - calls the appropriate function in the JavaScript module exposing the raw WASM. - 2. It builds the WASM binary which exposes all functions annotated with `#[wasm_bindgen]`. - 3. It builds the JavaScript module that loads the WASM binary and binds all exposed functions to - JavaScript functions so they can be called directly from JavaScript. - -To preview the build in a web browser, run - -``` -> http -``` - -which should start serving the crate root folder containing `index.html`. - -Finally, point your browser to the appropriate localhost url (usually http://localhost:8000) and you -should see a list of HTML documents -- one for each example. - -When you make changes to the project, re-run `wasm-pack build --target web` and you can see the changes in your browser when you refresh -- no need to restart `http`. - -## New Examples - -New examples that can be built against the WASM target should have an associated `impl_example!()` entry added to `lib.rs`. Examples that don't support the WASM target should be specified in the `EXCEPTIONS` list defined at the top of the `build.rs` script. diff --git a/druid/examples/wasm/.gitignore b/druid/examples/web/.gitignore similarity index 100% rename from druid/examples/wasm/.gitignore rename to druid/examples/web/.gitignore diff --git a/druid/examples/wasm/Cargo.toml b/druid/examples/web/Cargo.toml similarity index 85% rename from druid/examples/wasm/Cargo.toml rename to druid/examples/web/Cargo.toml index acfb797f8e..1afc2b791d 100644 --- a/druid/examples/wasm/Cargo.toml +++ b/druid/examples/web/Cargo.toml @@ -1,8 +1,8 @@ [package] -name = "druid-wasm-examples" +name = "druid-web-examples" version = "0.1.0" license = "Apache-2.0" -description = "Wasm scaffolding for druid examples" +description = "Scaffolding for druid web examples" repository = "https://github.com/xi-editor/druid" edition = "2018" publish = false @@ -12,6 +12,7 @@ crate-type = ["cdylib", "rlib"] [dependencies] druid = { path="../.." } + wasm-bindgen = "0.2.63" console_error_panic_hook = "0.1.6" log = "0.4.8" diff --git a/druid/examples/web/README.md b/druid/examples/web/README.md new file mode 100644 index 0000000000..aa76f6fb28 --- /dev/null +++ b/druid/examples/web/README.md @@ -0,0 +1,43 @@ +# Druid web examples + +This crate generates and builds all the necessary files for deploying `druid` examples to the web. + +## Building + +You will need `cargo` and `wasm-pack` for building the code and a simple +server like [`http`](https://crates.io/crates/https) for serving the web pages. + +First build with + +``` +> wasm-pack build --target web --dev +``` + +This step has two main functions: + + 1. It generates an HTML document for each of the `druid` examples with a script that + calls the appropriate function in the JavaScript module exposing the raw Wasm. + 2. It builds the Wasm binary which exposes all functions annotated with `#[wasm_bindgen]`. + 3. It builds the JavaScript module that loads the Wasm binary and binds all the exposed + functions to JavaScript functions so they can be called directly from JavaScript. + +To preview the build in a web browser, run + +``` +> http +``` + +which should start serving the crate root folder containing `index.html`. + +Finally, point your browser to the appropriate localhost url (usually http://localhost:8000) and you +should see a list of HTML documents -- one for each example. + +When you make changes to the project, re-run `wasm-pack build --target web --dev` and you can +see the changes in your browser when you refresh -- no need to restart `http`. + +## New Examples + +New examples that can be built against the web target should have an associated +`impl_example!()` entry added to `lib.rs`. Examples that don't +support the web target should be specified in the `EXCEPTIONS` list defined +at the top of the `build.rs` script. diff --git a/druid/examples/wasm/build.rs b/druid/examples/web/build.rs similarity index 84% rename from druid/examples/wasm/build.rs rename to druid/examples/web/build.rs index fb8e5b1741..5fad33740e 100644 --- a/druid/examples/wasm/build.rs +++ b/druid/examples/web/build.rs @@ -16,11 +16,12 @@ use std::io::{ErrorKind, Result}; use std::path::{Path, PathBuf}; use std::{env, fs}; -/// Examples known to not work with WASM are skipped. Ideally this list will eventually be empty. +/// Examples known to not work with the web backend are skipped. +/// Ideally this list will eventually be empty. const EXCEPTIONS: &[&str] = &[ - "svg", // usvg doesn't currently build with WASM. - "ext_event", // WASM doesn't currently support spawning threads. - "blocking_function", // WASM doesn't currently support spawning threads. + "svg", // usvg doesn't currently build as Wasm. + "ext_event", // the web backend doesn't currently support spawning threads. + "blocking_function", // the web backend doesn't currently support spawning threads. ]; /// Create a platform specific link from `src` to the `dst` directory. @@ -96,15 +97,14 @@ mod examples { "# .to_string(); - let mut index_html = r#" - + let mut index_html = r#" - Druid WASM examples - index + Druid web examples -

Druid WASM examples

+

Druid web examples

    "# .to_string(); @@ -122,7 +122,7 @@ mod examples { if let Some(example) = path.file_stem() { let example_str = example.to_string_lossy(); - // Skip examples that are known to not work with wasm. + // Skip examples that are known to not work. if EXCEPTIONS.contains(&example_str.as_ref()) { continue; } @@ -130,13 +130,7 @@ mod examples { // Record the valid example module we found to add to the generated examples.in examples_in.push_str(&format!(" pub mod {};\n", example_str)); - // The "switch" example name would conflict with JavaScript's switch statement. So we - // rename it here to switch_demo. - let js_entry_fn_name = if &example_str == "switch" { - "switch_demo".to_string() - } else { - example_str.to_string() - }; + let js_entry_fn_name = example_str.to_string(); // Add an entry to the index.html file. let index_entry = format!( @@ -153,7 +147,7 @@ mod examples { - Druid WASM examples - {name} + Druid web examples - {name} - + "#, - name = js_entry_fn_name + name = example_str.to_string() ); // Write out the html file into a designated html directory located in crate root.