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

ref(wasm-split): Simplify varint encoding prefix #621

Merged
merged 4 commits into from Jan 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 0 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions crates/wasm-split/Cargo.toml
Expand Up @@ -11,5 +11,4 @@ anyhow = "1.0.38"
structopt = "0.3.21"
hex = "0.4.2"
uuid = { version = "0.8.2", features = ["v4"] }
wasmbin = "0.3.1"
integer-encoding = "3.0.2"
wasmbin = "0.3.1"
13 changes: 6 additions & 7 deletions crates/wasm-split/src/main.rs
Expand Up @@ -10,11 +10,10 @@
use std::fs::File;
use std::io::{BufReader, BufWriter};
use std::path::PathBuf;

use integer_encoding::VarInt;
use structopt::StructOpt;
use uuid::Uuid;
use wasmbin::builtins::Blob;
use wasmbin::io::Encode;
use wasmbin::sections::{CustomSection, RawCustomSection, Section};
use wasmbin::Module;

Expand Down Expand Up @@ -165,17 +164,17 @@ fn main() -> Result<(), anyhow::Error> {
// From the wasm spec, the URL is encoded as bytes, and prefixed with a varint encoding of a u32 size
// https://github.com/WebAssembly/tool-conventions/blob/08bacbed/Debugging.md#external-dwarf
// Emscripten: https://github.com/emscripten-core/emscripten/blob/4eefe273/tools/building.py#L1200
let contents_vec = external_dwarf_url.as_bytes();
let debug_url_len = external_dwarf_url.len() as u32;
let mut encoded_byte_vec = debug_url_len.encode_var_vec();
encoded_byte_vec.extend(contents_vec);
// We use the `wasmbin::io::Encode` trait, as it will handle serializing a string as a Vec<u8> with
// an LEB128 prefix.
let data_vec = &mut Vec::new();
external_dwarf_url.encode(data_vec).unwrap();

module
.sections
.push(Section::Custom(Blob::from(CustomSection::Other(
RawCustomSection {
name: "external_debug_info".to_string(),
data: encoded_byte_vec,
data: data_vec.to_vec(),
},
))));
}
Expand Down