Skip to content

Commit

Permalink
Merge #105
Browse files Browse the repository at this point in the history
105: Simplify the example a bit r=grovesNL a=17cupsofcoffee

Here's a few tweaks that make the example a bit simpler/up-to-date:

* A seperate `wasm_main` is no longer required due to rustwasm/wasm-bindgen#1843.
* The prelude import wasn't actually being used anywhere.
* Nightly is no longer required to build this project, so I removed that from the instructions.
* `--no-modules` has been replaced with `--target web`, which doesn't rely on global variables and allows support for [JS snippets](https://rustwasm.github.io/docs/wasm-bindgen/reference/js-snippets.html).
    * The only caveat to this is that the generates JS is a ES module instead of a basic JS file - but any browser that supports WASM will also support ES modules, so I don't think this is an issue in practice.

Co-authored-by: Joe Clay <27cupsofcoffee@gmail.com>
  • Loading branch information
bors[bot] and 17cupsofcoffee authored May 21, 2020
2 parents 4ed4327 + 4c8a3c6 commit 722a850
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: rust
rust:
- 1.37.0
- 1.40.0
- stable
- beta
- nightly
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</div>
<br />
<div align="center">
<img src="https://img.shields.io/badge/Min%20Rust-1.37-green.svg" alt="Minimum Rust Version">
<img src="https://img.shields.io/badge/Min%20Rust-1.40-green.svg" alt="Minimum Rust Version">
<a href="https://crates.io/crates/glow"><img src="https://img.shields.io/crates/v/glow.svg?label=glow" alt="crates.io"></a>
<a href="https://docs.rs/glow"><img src="https://docs.rs/glow/badge.svg" alt="docs.rs"></a>
<a href="https://travis-ci.org/grovesNL/glow"><img src="https://travis-ci.org/grovesNL/glow.svg?branch=master" alt="Travis Build Status" /></a>
Expand Down
4 changes: 2 additions & 2 deletions examples/hello/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ cargo run --features=window-sdl2
To run with web-sys:

```shell
cargo +nightly build --target wasm32-unknown-unknown
cargo build --target wasm32-unknown-unknown
mkdir -p generated
wasm-bindgen ../../target/wasm32-unknown-unknown/debug/hello.wasm --out-dir generated --no-modules
wasm-bindgen ../../target/wasm32-unknown-unknown/debug/hello.wasm --out-dir generated --target web
cp index.html generated
```

Expand Down
8 changes: 4 additions & 4 deletions examples/hello/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
<body>
<canvas id="canvas" width="640" height="480"></canvas>
<script src="./hello.js"></script>
<script>
window.addEventListener("load", async () => {
await wasm_bindgen("./hello_bg.wasm");
});
<script type="module">
import init from "./hello.js";

init();
</script>
</body>
</html>
9 changes: 1 addition & 8 deletions examples/hello/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
use glow::*;

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

#[cfg(all(target_arch = "wasm32", feature = "stdweb"))]
use std_web::{
traits::*,
unstable::TryInto,
web::{document, html_element::*},
};

#[cfg(all(target_arch = "wasm32", feature = "stdweb"))]
use webgl_stdweb::WebGL2RenderingContext;

#[cfg_attr(all(target_arch = "wasm32", feature = "web-sys"), wasm_bindgen(start))]
pub fn wasm_main() {
main();
}

fn main() {
unsafe {
// Create a context from a WebGL2 context on wasm32 targets
Expand Down

0 comments on commit 722a850

Please sign in to comment.