#debug-info #wasm-binary #source-map #debugging #wasm #debugging-tool

app cargo-wasm2map

Cargo command which generates source map for .wasm file with DWARF debug info embedded as source map

1 unstable release

0.1.0 Apr 19, 2023

#5 in #sourcemap

MIT/Apache

41KB
563 lines

Cargo WASM Sourcemap Utility

Build status crates.io Documentation Min Rust 1.64.0

Generates a browser-supported sourcemap for WASM binaries containing DWARF debug information and associates it with the WASM binary, so when loaded in the browser you can see the rust line, character and source code (if available) in the debug panel and console.

NOTE: Can build without unsafe code (the only unsafe code is related to using the memmap2 crate).

Before

Before WASM sourcemapping

After

After WASM sourcemapping

Usage

  1. Use it with Cargo to manually preprocess your WASM binary before serving:
 cargo install cargo-wasm2map

 # Build your WASM binary the way you usually do
 cargo build --target wasm32-unknown-unknown

# Generate sourcemap for the target WASM (replace myproject with your project
# name).
 cargo wasm2map target/wasm32-unknown-unknown/debug/myproject.wasm \
    -patch -base-url http://localhost:8080

 # Serve the WASM to your browser... (i.e. http://localhost:8080 or wherever
 # your index.html is)
  1. Use it as a library in your utility:
use wasm2map::WASM;

let mapper = WASM::load("/path/to/the/file.wasm");
    if let Ok(mut mapper) = mapper {
        let sourcemap = mapper.map_v3();
        mapper.patch("http://localhost:8080").expect("Failed to patch");
}

Current limitations

  • It does not bundle the source code in the sourcemap currently, so source browsing will not work in the browser

Contribution

Your contributions are welcome, especially bug reports and testing on various platforms. Feel free to open a PR if you can contribute a fix.

If you would like to contribute an API change, extension or a new trait implementation, please open an issue first and discuss before starting work on a PR. For details please read the CONTRIBUTING.md file.

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option. Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

SPDX-License-Identifier: Apache-2.0 OR MIT

Dependencies

~9.5MB
~192K SLoC