简体   繁体   中英

Web Assembly and Rust: cargo build vs wasm-pack

Some examples of building wasm use cargo build (like the examples in the book Programming WebAssembly)

cargo build --release --target=wasm32-unknown-unknown

And others use,

wasm-pack build --target web ....

What's the different between these two methods of building a project?

Wasm-pack is a bigger convenience application that provides more than simply building the Rust code.

Amongst other things wasm-pack provides:

  • Building Rust projects to WebAssembly (equivalent to cargo build --target=wasm32-unknown-unknown... )
  • Binding to Node.js
  • Publishing results to the npm registry.
  • Creating new projects (like cargo new )

This tool seeks to be a one-stop shop for building and working with rust- generated WebAssembly that you would like to interop with JavaScript, in the browser or with Node.js. wasm-pack helps you build rust-generated WebAssembly packages that you could publish to the npm registry, or otherwise use alongside any javascript packages in workflows that you already use, such as webpack or greenkeeper. 1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM