• Stars
    star
    218
  • Rank 181,805 (Top 4 %)
  • Language
    Rust
  • Created almost 7 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

`wasm-snip` replaces a WebAssembly function's body with an `unreachable`

wasm-snip

wasm-snip replaces a Wasm function's body with an unreachable instruction.

Build Status Crates.io version Download docs.rs docs

API Docs | Contributing | Chat

Built with 🦀🕸 by The Rust and WebAssembly Working Group

About

wasm-snip replaces a WebAssembly function's body with an unreachable.

Maybe you know that some function will never be called at runtime, but the compiler can't prove that at compile time? Snip it! All the functions it transitively called — which weren't called by anything else and therefore could also never be called at runtime — will get removed too.

Very helpful when shrinking the size of WebAssembly binaries!

This functionality relies on the "name" section being present in the .wasm file, so build with debug symbols:

[profile.release]
debug = true

Executable

To install the wasm-snip executable, run

$ cargo install wasm-snip

You can use wasm-snip to remove the annoying_space_waster function from input.wasm and put the new binary in output.wasm like this:

$ wasm-snip input.wasm -o output.wasm annoying_space_waster

For information on using the wasm-snip executable, run

$ wasm-snip --help

And you'll get the most up-to-date help text, like:

Replace a wasm function with an `unreachable`.

USAGE:
wasm-snip [FLAGS] [OPTIONS] <input> [--] [function]...

FLAGS:
-h, --help                    Prints help information
--snip-rust-fmt-code          Snip Rust's `std::fmt` and `core::fmt` code.
--snip-rust-panicking-code    Snip Rust's `std::panicking` and `core::panicking` code.
-V, --version                 Prints version information

OPTIONS:
-o, --output <output>         The path to write the output wasm file to. Defaults to stdout.
-p, --pattern <pattern>...    Snip any function that matches the given regular expression.

ARGS:
<input>          The input wasm file containing the function(s) to snip.
<function>...    The specific function(s) to snip. These must match exactly. Use the -p flag for fuzzy matching.

Library

To use wasm-snip as a library, add this to your Cargo.toml:

[dependencies.wasm-snip]
# Do not build the executable.
default-features = false

See docs.rs/wasm-snip for API documentation.

License

Licensed under either of

at your option.

Contributing

See CONTRIBUTING.md for hacking.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

More Repositories

1

wasm-bindgen

Facilitating high-level interactions between Wasm modules and JavaScript
Rust
7,655
star
2

wasm-pack

📦✨ your favorite rust -> wasm workflow tool!
Rust
6,173
star
3

gloo

A modular toolkit for building fast, reliable Web applications and libraries with Rust and WASM
Rust
1,773
star
4

book

The Rust and WebAssembly Book
Handlebars
1,734
star
5

team

A point of coordination for all things Rust and WebAssembly
1,436
star
6

twiggy

Twiggy🌱 is a code size profiler
Rust
1,254
star
7

wee_alloc

The Wasm-Enabled, Elfin Allocator
Rust
666
star
8

awesome-rust-and-webassembly

Awesome Rust and WebAssembly projects, libraries, tools, and resources
627
star
9

wasm-pack-template

a template for starting a rust-wasm project to be used with wasm-pack
Rust
618
star
10

rust-webpack-template

Kickstart your Rust, WebAssembly, and Webpack project!
JavaScript
562
star
11

create-wasm-app

npm init template for consuming rustwasm pkgs
JavaScript
492
star
12

walrus

Walrus is a WebAssembly transformation library 🌊🐘
Rust
377
star
13

console_error_panic_hook

A panic hook for wasm32-unknown-unknown that logs panics with console.error
Rust
317
star
14

wasm_game_of_life

A Rust and WebAssembly tutorial implementing the Game of Life
Rust
276
star
15

rust-parcel-template

Kickstart your Rust, WebAssembly, and Parcel project!
Rust
156
star
16

deprecated_rust_wasm_template

Deprecated in favor of rustwasm/wasm-pack-template or rustwasm/rust-webpack-template
Shell
102
star
17

wasm-tracing-allocator

A global allocator for Wasm that traces allocations and deallocations for debugging purposes.
Rust
101
star
18

rustwasm.github.io

Rust and WebAssembly website! 🦀 + 🕸
HTML
68
star
19

weedle

A WebIDL Parser
WebIDL
43
star
20

rfcs

The Rust and WebAssembly RFCs
Shell
39
star
21

wasm-webidl-bindings

Read, write, and manipulate the Wasm WebIDL bindings custom section
Rust
38
star
22

binary-install

Rust
10
star
23

wasm-weight-tracker

Tracking Rust and WebAssembly sizes over time
Rust
10
star
24

hello-wasm-bindgen

a presentation introducing wasm-bindgen
JavaScript
8
star
25

sfhtml5-rust-and-wasm

JavaScript
4
star
26

.github

Default issue templates, CONTRIBUTING.md, etc...
2
star
27

wasm-weight-tracker-data

WIP
1
star