rustwasm/wasm-pack-template

wasm-pack-template

A template for kick starting a Rust and WebAssembly project using Tutorial

A template for kick starting a Rust and WebAssembly project using wasm-pack.

Tutorial | Chat

Built with 🦀🕸 by The Rust and WebAssembly Working Group

About

📚 Read this template tutorial! 📚

This template is designed for compiling Rust libraries into WebAssembly and publishing the resulting package to NPM.

Be sure to check out other wasm-pack tutorials online for other templates and usages of wasm-pack.

🚴 Usage

🐑 Use cargo generate to Clone this Template

Learn more about cargo generate here.

cargo generate --git https://github.com/rustwasm/.git --name my-project
cd my-project

🛠️ Build with wasm-pack build

wasm-pack build

🔬 Test in Headless Browsers with wasm-pack test

wasm-pack test --headless --firefox

🎁 Publish to NPM with wasm-pack publish

wasm-pack publish

🔋 Batteries Included

  • wasm-bindgen for communicating between WebAssembly and JavaScript.
  • console_error_panic_hook for logging panic messages to the developer console.
  • wee_alloc, an allocator optimized for small code size.
Issues

Collection of the latest Issues

xanderificnl

xanderificnl

question
Comment Icon1

Summary

It isn't clear whether the Apache & MIT license apply to this template itself, or if they are merely suggested licenses for anyone who builds on this template.

Specifically, I'd like to know:

  • Is the template itself licensed?
  • Are the license files LICENSE_{APACHE,MIT} included as suggestions?
  • Should the MIT license file include more authors? (i.e. contributors to this template)

Additional details

The reason I ask is that I haven't seen any boilerplate notices in the code referencing the Apache license. So, as far as I understand it, the Apache license doesn't apply.

In regard to the MIT license, cargo-generate modifies it to list me as the sole author, but the plain text file in this repository uses the placeholder "authors" (plural) and the date is stuck on 2018. Which might imply that there should be more authors (i.e. contributors to the template).

Thanks!

  • Xander
szunami

szunami

bug
Comment Icon2

Describe the Bug

I hit what I believe is https://github.com/rustwasm/wasm-pack/issues/886 while working through the Game of Life tutorial. I have pushed my current code state here:

https://github.com/szunami/hello_rust_wasm/commit/50ab3561207a5ce18a86819393b76284c1ca8e40

I am on cargo 1.47.0 (f3c7e066a 2020-08-28), npm 6.4.1, hapy to offer other version as appropriate.

Steps to Reproduce

check out ^ and run wasm-pack build. On my machine I get a very verbose error that includes [wasm-validator error in module] unexpected true: Exported global cannot be mutable, on global$0.

Notably, running wasm-pack build --dev succeeds.

Expected Behavior

The build should succeed.

Actual Behavior

The build fails.

Additional Context

There are two solutions mentioned in the bug thread: https://github.com/rustwasm/wasm-pack/issues/886#issuecomment-666309982 and https://github.com/rustwasm/wasm-pack/issues/886#issuecomment-667669802 I think it would be appropriate if one of these solutions came pre-baked into this repository. I am happy to contribute either change.

I recognize that there are some rough edges with respect to WASM, but I think it would be nice if the "hello world" project succeeded consistently. If the solutions in the thread are inappropriate for general adoption, perhaps a new template could be spun up which is more consistent?

rictic

rictic

bug
Comment Icon1

Describe the Bug

I'm new to Rust and WASM, and have been using this template to learn both. As my project grew, so did my build times, but Rust has a reputation for slower compiles, so I didn't think very much of it.

Today I took some time to investigate improving build times and I was able to get a 7x improvement by running wasm-pack --target web and writing normal standard JS.

I understand that there are a lot of parts of the web ecosystem that need a bundler to work today (e.g. JSX), so this might be the right option for today. Might be worth investigating esbuild with a wasm supporting plugin though? Or add something to the README about how for projects that don't need much JS --target web can be a better option?

Or maybe there's a way to run webpack without requiring it to process the wasm? As far as I can tell the wasm runs fine without webpack doing anything to it...

Steps to Reproduce

  1. Check out https://github.com/rictic/airlock.chat at revision f22af3254c8a94a64e2249f75f28c428ab98ef27
  2. Run ./start.sh to start webpack dev server and cargo watch to re-run wasm-pack on save.
  3. Observe the speed of the edit-refresh loop (~12s on my machine).
  4. Compare that with an incremental rebuild of wasm-pack --dev --target web (~1s on my machine)

Expected Behavior

The edit-refresh for a mostly-rust project is largely dependent on the speed of wasm-pack.

Actual Behavior

Most of the time is spent in webpack, and as the size of the emitted wasm file increases, time spent in webpack increases as well.

Additional Context

See https://github.com/rictic/airlock.chat/pull/65 for more details of what went into moving one project off of using a bundler entirely (though it helps that it's almost entirely Rust, and as a little prototype it doesn't need to support older browsers).

AndrewPomorski

AndrewPomorski

bug
Comment Icon0

Describe the Bug

When running a build on travis using the default .travis.yml file, the build fails on before script :

Steps to Reproduce

  1. Generate a wasm-pack-template project with cargo generate --git https://github.com/rustwasm/wasm-pack-template.git --name my-project

  2. Set up a build on travis CI

  3. push to master, the build will fail

https://travis-ci.org/github/AndrewPomorski/wasm-game-of-life/jobs/726136106/config

Additional info

The error message from Travis build server:

Expected Behavior

The build should pass without having to reconfigure travis.

Actual Behavior

Build fails

lamei1224

lamei1224

bug
Comment Icon2

Describe the Bug

Error is displayed when i execute 'wasm-pack build' command

Steps to Reproduce

  1. Firstly ,i want to re-line code from https://github.com/paritytech/stateless-blockchain
  2. When i execute wasm-pack build on package accumulator-client
  3. Error displayed"the legacy llvm-style asm syntax is no longer supported"

Expected Behavior

Execute command wasm-pack build will be successful

Actual Behavior

Error displayed

If applicable, add screenshots to help explain your problem. wasm-pack error

khionu

khionu

Comment Icon0

The "Chat" link in the Readme cannot be used to invite a person to a Discord. Discord Invites are in the format of https://discord.gg/invite_code or https://discordapp.com/invite/invite_code.

andrewdavidmackenzie

andrewdavidmackenzie

question
Comment Icon3

Summary

When I run a similar project in Travis CI I get this error:

So I am not sure how you are able to get travis to run --chrome --headless

Any ideas?

BTW: In "-script" I see "cd testing" but there is no such folder. I don't see it created during setup, but maybe wrong.

alexcrichton

alexcrichton

Comment Icon0

I first commited a bug in https://github.com/rustwasm/wasm-pack-template/pull/37 which would cause the template to not build, but it was caught by @fitzgen's sharp eyes. Unfortunately though Travis didn't catch this.

The reason, I believe, is that cargo generate --git . --name testing, what Travis is currently doing, actually checks out the master branch of the repository rather than whatever branch the PR is set to be. This means that every PR is actually testing what's on master, not what's in the PR!

bwasty

bwasty

Comment Icon0

I created a fresh project with the template and haven't changed any code yet, but the build on AppVeyor fails with this:

I don't understand the problem - when I run cargo update locally, nothing changes and --locked seems like 'the right thing to do' for CI.

alexcrichton

alexcrichton

Comment Icon0

A topic that recently came up in #wg-wasm on Discord was that a wasm-pack project was performance much more slowly than a raw rustc-generated wasm file. It turned out to be related to opt-level = 's' in Cargo.toml, causing a nearly 3x (!) slowdown compared to -C opt-level=3 (the default).

I'm not sure how often this comes up in the wild though. Unfortunately there's not really a silver bullet here :(. I figured it'd be good to catalog though!

Information - Updated Jun 13, 2022

Stars: 403
Forks: 143
Issues: 26

Wasm template for Rust hosting without npm-deploy on github pages using Travis script

It automatically hosts your wasm projects on gh-pages using a travis script on the latest commit

Wasm template for Rust hosting without npm-deploy on github pages using Travis script

Roctogen: a rust client library for the GitHub v3 API

This client API is generated from the Isahc HTTP client

Roctogen: a rust client library for the GitHub v3 API

A rust github template for ease of use

Install the rust toolchain in order to have cargo installed by following

A rust github template for ease of use

📓 Relnotes: Automatic GitHub Release Notes

Tera templates for release notes format

📓 Relnotes: Automatic GitHub Release Notes

Rust-generated WebAssembly GitHub action template

A template to bootstrap the creation of a Rust-generated WebAssembly GitHub action

Rust-generated WebAssembly GitHub action template

cargo_auto_github_lib

Library for cargo-auto automation tasks written in rust language with functions for github

cargo_auto_github_lib

Huber is to simplify the package management from GitHub projects with a builtin awesome list...

Huber is to simplify the package management from GitHub projects with a builtin awesome list (live updating) of popular projects

Huber is to simplify the package management from GitHub projects with a builtin awesome list...

Renote is a CLI to extend GitHub operation experience, which is a complementary tool to...

Renote is a CLI to extend GitHub operation experience, which is a complementary tool to use with gh advanced search options

Renote is a CLI to extend GitHub operation experience, which is a complementary tool to...

Droid is a GitHub based package manager for unix systems

The goal is to create a way

Droid is a GitHub based package manager for unix systems

Droid is a GitHub based package manager for unix systems

The goal is to create a way

Droid is a GitHub based package manager for unix systems
Facebook Instagram Twitter GitHub Dribbble
Privacy