-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use wasm-bindgen instead of stdweb #6
Changes from 5 commits
7a290c1
8813215
e282525
8be4132
cb1d234
cecc179
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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" | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
# Running the examples | ||
|
||
Generally follow the directions at [stdweb]. | ||
Ensure both cargo and [npm] are installed. | ||
|
||
`$ cargo install -f cargo-web` | ||
`$ cargo install -f wasm-bindgen` | ||
|
||
`$ cargo web start --target=wasm32-unknown-unknown --example basic-web` | ||
`$ 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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules/ | ||
package-lock.json |
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.29" | ||
kurbo = "0.1.2" | ||
|
||
[dependencies.web-sys] | ||
version = "0.3.6" | ||
features = ["CanvasRenderingContext2d", "Window", "Document", "Element", "HtmlElement", "HtmlCanvasElement"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
* | ||
!.gitignore |
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); |
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" | ||
} | ||
} |
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' | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/bin/sh | ||
|
||
set -ex | ||
|
||
# Build the `hello_world.wasm` file using Cargo/rustc | ||
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 | ||
npm install --prefix basic-web-static | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This also has a paper-cut error: works fine if I cd to basic-web-static and do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm... the --prefix option should take care of that. I don't need to cd into that directory on my machine. Maybe different versions of npm are causing this? I can change the script to cd into that directory instead. Do you think that will be a more robust solution? (ah... the joys of bash scripting ❤️) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The world of npm is foreign and strange to me, though I have played with it some. Looking at the docs, it looks like prefix sets the path where the artifacts get stored, but not where the package.json is read from. Did you try this from a fresh clone? (my inexperienced experience is that npm tends to litter a lot of files in your working directory) I'm fine with it cd'ing into the directory. In general I would want to follow "best practices" but have no idea what those are. Not to be too nitpicky, but I think this is kinda important because a lot of people start projects by copying a hello example. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No worries on being nitpicky. I 100% that this should be painless for people. What you said about I tried from a fresh clone and it worked fine for me. If you run I try to avoid using cd in my bash scripts because I've ran into weird issues before, but if that's what's needed to get it working, we can do it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I'm not sure what's going on here, and totally understand wanting to minimize cd'ing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like a bug in the windows version of npm: https://npm.community/t/npm-prefix-flag-does-not-work-as-expected-on-windows/3147 I think moving to just using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good - I was just about to try it on my Mac, but seems like you've isolated it. That bug is scary, being auto-closed even though it seems valid and with the potential to affect lots of people. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's unfortunately how the web world works. It's pretty fast and loose. The latest commit should fix it (though I just ran into another way things could break that the readme now references). |
||
npm run serve --prefix basic-web-static |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get this:
I can diagnose this, but I have on my "hapless dev" hat. This is on a Windows 10 box in a git bash shell, and node (10.15.0) and npm are installed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops! It's actually
wasm-bindgen-cli
. Once it's installed it's just calledwasm-bindgen
. I will update this.