mirror of
https://github.com/rustwasm/wasm-bindgen.git
synced 2024-12-14 20:11:37 +03:00
894b479213
This commit moves `wasm-bindgen` the CLI tool from internally using `parity-wasm` for wasm parsing/serialization to instead use `walrus`. The `walrus` crate is something we've been working on recently with an aim to replace the usage of `parity-wasm` in `wasm-bindgen` to make the current CLI tool more maintainable as well as more future-proof. The `walrus` crate provides a much nicer AST to work with as well as a structured `Module`, whereas `parity-wasm` provides a very raw interface to the wasm module which isn't really appropriate for our use case. The many transformations and tweaks that wasm-bindgen does have a huge amount of ad-hoc index management to carefully craft a final wasm binary, but this is all entirely taken care for us with the `walrus` crate. Additionally, `wasm-bindgen` will ingest and rewrite the wasm file, often changing the binary offsets of functions. Eventually with DWARF debug information we'll need to be sure to preserve the debug information throughout the transformations that `wasm-bindgen` does today. This is practically impossible to do with the `parity-wasm` architecture, but `walrus` was designed from the get-go to solve this problem transparently in the `walrus` crate itself. (it doesn't today, but this is planned work) It is the intention that this does not end up regressing any `wasm-bindgen` use cases, neither in functionality or in speed. As a large change and refactoring, however, it's likely that at least something will arise! We'll want to continue to remain vigilant to any issues that come up with this commit. Note that the `gc` crate has been deleted as part of this change, as the `gc` crate is no longer necessary since `walrus` does it automatically. Additionally the `gc` crate was one of the main problems with preserving debug information as it often deletes wasm items! Finally, this also starts moving crates to the 2018 edition where necessary since `walrus` requires the 2018 edition, and in general it's more pleasant to work within the 2018 edition!
40 lines
793 B
Rust
Executable File
40 lines
793 B
Rust
Executable File
#![cfg(target_arch = "wasm32")]
|
|
|
|
extern crate wasm_bindgen;
|
|
extern crate wasm_bindgen_test;
|
|
|
|
use wasm_bindgen::prelude::*;
|
|
use wasm_bindgen_test::*;
|
|
|
|
wasm_bindgen_test_configure!(run_in_browser);
|
|
|
|
#[wasm_bindgen]
|
|
pub struct ConsumeRetString;
|
|
|
|
#[wasm_bindgen]
|
|
impl ConsumeRetString {
|
|
// https://github.com/rustwasm/wasm-bindgen/issues/329#issuecomment-411082013
|
|
//
|
|
// This used to cause two `const ptr = ...` declarations, which is invalid
|
|
// JS.
|
|
pub fn consume(self) -> String {
|
|
String::new()
|
|
}
|
|
}
|
|
|
|
#[wasm_bindgen_test]
|
|
fn works() {
|
|
ConsumeRetString.consume();
|
|
}
|
|
|
|
#[wasm_bindgen]
|
|
extern "C" {
|
|
#[wasm_bindgen(js_namespace = console)]
|
|
pub fn log(s: &str);
|
|
}
|
|
|
|
#[wasm_bindgen_test]
|
|
fn can_log_html_strings() {
|
|
log("<script>alert('lol')</script>");
|
|
}
|