Skip to content
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

updated examples, added build script #1165

Merged
merged 21 commits into from
Apr 29, 2020

Conversation

fbucek
Copy link
Contributor

@fbucek fbucek commented Apr 28, 2020

fixes: #1162

  • Updated examples to work with wasm-bindgen -> build.sh script to run them

  • Added minimal_wp example which works with wasm-pack

  • Added readme.md with minimum info how to run these examples.

  • Added ci/run_examples.sh to build all examples ( not used )

  • missing info how to install of wasm-bindgen/wasm-pack

  • update info about multi-thread ( check steps in multi-thread/readme.md )

@fbucek fbucek changed the title Issue/examples build script updated examples, added build script Apr 28, 2020
@jstarry
Copy link
Member

jstarry commented Apr 28, 2020

Nice bash! What was the issue with multi_thread? I think it will need to be a special case since it needs to build the worker and the app

@fbucek
Copy link
Contributor Author

fbucek commented Apr 28, 2020

multi_thread: exactly, it builds ok, but browser does not show anything since build.sh and index.htm is prepared for one wasm file. I do not know if some packager is needed or it is possible to load mulitple js/wasm ( worker and app )

@jstarry
Copy link
Member

jstarry commented Apr 28, 2020

ah got it, no need for package manager. The readme explains the steps: https://github.com/yewstack/yew/tree/master/examples/multi_thread

@jstarry
Copy link
Member

jstarry commented Apr 29, 2020

I tried running and got this:

[ Building: minimal using wasm-bindgen ]
   Compiling wasm-bindgen-backend v0.2.60
   Compiling wasm-bindgen-macro-support v0.2.60
   Compiling wasm-bindgen-macro v0.2.60
   Compiling wasm-bindgen v0.2.60
   Compiling js-sys v0.3.37
   Compiling console_error_panic_hook v0.1.6
   Compiling web-sys v0.3.37
   Compiling wasm-bindgen-futures v0.4.10
   Compiling gloo-events v0.1.1
   Compiling gloo-timers v0.2.1
   Compiling gloo-console-timer v0.1.0
   Compiling gloo-file v0.1.0
   Compiling gloo v0.2.1
   Compiling yew v0.15.0 (/Users/jstarry/Workspace/yewstack/yew/yew)
   Compiling minimal v0.1.0 (/Users/jstarry/Workspace/yewstack/yew/examples/minimal)
    Finished release [optimized] target(s) in 30.39s
error: failed to read `../target/wasm32-unknown-unknown/release/minimal.wasm`

Caused by:
    0: failed to read `../target/wasm32-unknown-unknown/release/minimal.wasm`
    1: No such file or directory (os error 2)
[FAIL] Command: "wasm-bindgen --target web --no-typescript --out-dir $SRCDIR/static/ --out-name wasm $TARGET_DIR/$EXAMPLE.wasm" exited with exit code: 1

Copy link
Member

@jstarry jstarry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good! I did a more thorough review. Really appreciate the nice readme in examples/ :)

.travis.yml Outdated Show resolved Hide resolved
ci/build_examples.sh Outdated Show resolved Hide resolved
examples/multi_thread/build.sh Outdated Show resolved Hide resolved
examples/build.sh Outdated Show resolved Hide resolved
examples/build.sh Outdated Show resolved Hide resolved
examples/minimal_wp/Cargo.toml Show resolved Hide resolved
examples/static/.gitignore Outdated Show resolved Hide resolved
examples/readme.md Outdated Show resolved Hide resolved
examples/readme.md Outdated Show resolved Hide resolved

Use `build.sh` script to build examples.

Examples are prepared for `wasm-bindgen` except `minimal_wp` which is prepared for `wasm-pack`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain that wasm-bindgen was chosen because:

  1. Want to keep setup simple (no bundlers)
  2. Prefer to keep examples as binaries rather than libraries (wasm-pack limitation)

Also, I think here would be a good place to link to https://yew.rs/docs/getting-started/starter-templates for people who are interested in how to setup their own app after they learn about examples.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part is little bit confusing for me.

In https://yew.rs/docs/getting-started/project-setup is written: We don't recommend using wasm-bindgen directly because it requires hand-writing some JavaScript to bootstrap you WebAssembly binary.

But wasm-pack and wasm-bindgen both can use same /examples/static/index.html file. No other steps are needed. Neither of them needs to use bundler when compiled with --target web

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 you're right. The docs need to be updated. I wonder if I wrote those before --target web or something.. or maybe I just wrote incorrectly 😅

Copy link
Member

@jstarry jstarry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works so well! This is a huge improvement 👍

I made a bunch of suggestions for small tweaks, you can use Github UI to accept them

examples/build.sh Outdated Show resolved Hide resolved
examples/build.sh Outdated Show resolved Hide resolved
examples/readme.md Outdated Show resolved Hide resolved
examples/readme.md Outdated Show resolved Hide resolved
examples/readme.md Outdated Show resolved Hide resolved
examples/readme.md Outdated Show resolved Hide resolved
examples/readme.md Outdated Show resolved Hide resolved
examples/readme.md Outdated Show resolved Hide resolved
examples/readme.md Outdated Show resolved Hide resolved
examples/readme.md Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

not possible to run examples
2 participants