-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from rylev/wasm-bindgen
Use wasm-bindgen instead of stdweb
- Loading branch information
Showing
14 changed files
with
120 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,5 @@ members = [ | |
"piet-cairo", | ||
"piet-direct2d", | ||
"piet-web", | ||
"piet-web/examples/basic" | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
# Running the examples | ||
|
||
Generally follow the directions at [stdweb]. | ||
Ensure both cargo and [npm] are installed. | ||
|
||
`$ cargo install -f cargo-web` | ||
Make sure that wasm-bindgen is installed. This needs to be the same version of | ||
wasm-bindgen used by piet-web. | ||
|
||
`$ cargo web start --target=wasm32-unknown-unknown --example basic-web` | ||
`$ cargo install -f wasm-bindgen-cli` | ||
|
||
`$ cd examples/basic && ./build.sh` | ||
|
||
Then navigate browser to local web server. | ||
|
||
[stdweb]: https://github.com/koute/stdweb | ||
[npm]: https://www.npmjs.com/get-npm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules/ | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[package] | ||
name = "piet-web-example" | ||
version = "0.0.1" | ||
authors = ["Ryan Levick <[email protected]>"] | ||
edition = "2018" | ||
|
||
[lib] | ||
crate-type = ["cdylib"] | ||
|
||
[dependencies] | ||
piet = { path = "../../../piet" } | ||
piet-web = { path = "../.." } | ||
wasm-bindgen = "0.2.30" | ||
kurbo = "0.1.2" | ||
|
||
[dependencies.web-sys] | ||
version = "0.3.6" | ||
features = ["CanvasRenderingContext2d", "Window", "Document", "Element", "HtmlElement", "HtmlCanvasElement"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
* | ||
!.gitignore |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const rust = import('./dist/piet_web_example'); | ||
|
||
rust | ||
.then(m => m.run()) | ||
.catch(console.error); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"scripts": { | ||
"build": "webpack", | ||
"serve": "webpack-dev-server" | ||
}, | ||
"devDependencies": { | ||
"text-encoding": "^0.7.0", | ||
"html-webpack-plugin": "^3.2.0", | ||
"webpack": "^4.11.1", | ||
"webpack-cli": "^3.1.1", | ||
"webpack-dev-server": "^3.1.0" | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
piet-web/examples/basic/basic-web-static/webpack.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const path = require('path'); | ||
const HtmlWebpackPlugin = require('html-webpack-plugin'); | ||
const webpack = require('webpack'); | ||
|
||
module.exports = { | ||
entry: './index.js', | ||
output: { | ||
path: path.resolve(__dirname), | ||
filename: 'index.js', | ||
}, | ||
plugins: [ | ||
// Have this example work in Edge which doesn't ship `TextEncoder` or | ||
// `TextDecoder` at this time. | ||
new webpack.ProvidePlugin({ | ||
TextDecoder: ['text-encoding', 'TextDecoder'], | ||
TextEncoder: ['text-encoding', 'TextEncoder'] | ||
}) | ||
], | ||
mode: 'development' | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/bin/sh | ||
|
||
set -ex | ||
|
||
# Build the `hello_world.wasm` file using Cargo | ||
cargo build --target wasm32-unknown-unknown | ||
|
||
# Run the `wasm-bindgen` CLI tool to postprocess the wasm file emitted by the | ||
# Rust compiler to emit the JS support glue that's necessary | ||
wasm-bindgen ../../../target/wasm32-unknown-unknown/debug/piet_web_example.wasm --out-dir basic-web-static/dist | ||
|
||
# Finally, package everything up using Webpack and start a server so we can | ||
# browse the result | ||
cd basic-web-static | ||
npm install | ||
npm run serve |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters