mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-20 08:16:31 +00:00
Migrate wasm-bindgen
to using walrus
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!
This commit is contained in:
@ -1,3 +1,9 @@
|
||||
use crate::shell::Shell;
|
||||
use curl::easy::Easy;
|
||||
use failure::{bail, format_err, Error, ResultExt};
|
||||
use log::{debug, warn};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::{self, json};
|
||||
use std::env;
|
||||
use std::io::{self, Read};
|
||||
use std::net::{SocketAddr, TcpListener, TcpStream};
|
||||
@ -6,13 +12,6 @@ use std::process::{Child, Command, Stdio};
|
||||
use std::thread;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use curl::easy::Easy;
|
||||
use failure::{Error, ResultExt};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json;
|
||||
|
||||
use shell::Shell;
|
||||
|
||||
/// Execute a headless browser tests against a server running on `server`
|
||||
/// address.
|
||||
///
|
||||
|
@ -11,29 +11,12 @@
|
||||
//! For more documentation about this see the `wasm-bindgen-test` crate README
|
||||
//! and source code.
|
||||
|
||||
extern crate curl;
|
||||
extern crate env_logger;
|
||||
#[macro_use]
|
||||
extern crate failure;
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
extern crate parity_wasm;
|
||||
extern crate rouille;
|
||||
extern crate serde;
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
#[macro_use]
|
||||
extern crate serde_json;
|
||||
extern crate wasm_bindgen_cli_support;
|
||||
|
||||
use failure::{bail, format_err, Error, ResultExt};
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
use std::process;
|
||||
use std::thread;
|
||||
|
||||
use failure::{Error, ResultExt};
|
||||
use parity_wasm::elements::{Deserialize, Module, Section};
|
||||
use wasm_bindgen_cli_support::Bindgen;
|
||||
|
||||
// no need for jemalloc bloat in this binary (and we don't need speed)
|
||||
@ -88,15 +71,14 @@ fn rmain() -> Result<(), Error> {
|
||||
// that any exported function with the prefix `__wbg_test` is a test we need
|
||||
// to execute.
|
||||
let wasm = fs::read(&wasm_file_to_test).context("failed to read wasm file")?;
|
||||
let wasm = Module::deserialize(&mut &wasm[..]).context("failed to deserialize wasm module")?;
|
||||
let wasm = walrus::Module::from_buffer(&wasm).context("failed to deserialize wasm module")?;
|
||||
let mut tests = Vec::new();
|
||||
if let Some(exports) = wasm.export_section() {
|
||||
for export in exports.entries() {
|
||||
if !export.field().starts_with("__wbg_test") {
|
||||
continue;
|
||||
}
|
||||
tests.push(export.field().to_string());
|
||||
|
||||
for export in wasm.exports.iter() {
|
||||
if !export.name.starts_with("__wbg_test") {
|
||||
continue;
|
||||
}
|
||||
tests.push(export.name.to_string());
|
||||
}
|
||||
|
||||
// Right now there's a bug where if no tests are present then the
|
||||
@ -112,15 +94,11 @@ fn rmain() -> Result<(), Error> {
|
||||
// `wasm_bindgen_test_configure` macro, which emits a custom section for us
|
||||
// to read later on.
|
||||
let mut node = true;
|
||||
for section in wasm.sections() {
|
||||
let custom = match section {
|
||||
Section::Custom(section) => section,
|
||||
_ => continue,
|
||||
};
|
||||
if custom.name() != "__wasm_bindgen_test_unstable" {
|
||||
for custom in wasm.custom.iter() {
|
||||
if custom.name != "__wasm_bindgen_test_unstable" {
|
||||
continue;
|
||||
}
|
||||
node = !custom.payload().contains(&0x01);
|
||||
node = !custom.value.contains(&0x01);
|
||||
}
|
||||
let headless = env::var("NO_HEADLESS").is_err();
|
||||
let debug = env::var("WASM_BINDGEN_NO_DEBUG").is_err();
|
||||
|
@ -3,8 +3,8 @@ use std::fs;
|
||||
use std::net::SocketAddr;
|
||||
use std::path::Path;
|
||||
|
||||
use failure::{Error, ResultExt};
|
||||
use rouille::{self, Request, Response, Server};
|
||||
use failure::{format_err, Error, ResultExt};
|
||||
use rouille::{Request, Response, Server};
|
||||
use wasm_bindgen_cli_support::wasm2es6js::Config;
|
||||
|
||||
pub fn spawn(
|
||||
@ -70,7 +70,7 @@ pub fn spawn(
|
||||
// like an ES module with the wasm module under the hood.
|
||||
//
|
||||
// TODO: don't reparse the wasm module here, should pass the
|
||||
// `parity_wasm::Module struct` directly from the output of
|
||||
// `Module struct` directly from the output of
|
||||
// `wasm-bindgen` previously here and avoid unnecessary
|
||||
// parsing.
|
||||
let wasm_name = format!("{}_bg.wasm", module);
|
||||
|
@ -1,17 +1,8 @@
|
||||
extern crate wasm_bindgen_cli_support;
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
extern crate docopt;
|
||||
extern crate wasm_bindgen_shared;
|
||||
#[macro_use]
|
||||
extern crate failure;
|
||||
extern crate env_logger;
|
||||
|
||||
use docopt::Docopt;
|
||||
use failure::{bail, Error};
|
||||
use serde::Deserialize;
|
||||
use std::path::PathBuf;
|
||||
use std::process;
|
||||
|
||||
use docopt::Docopt;
|
||||
use failure::Error;
|
||||
use wasm_bindgen_cli_support::Bindgen;
|
||||
|
||||
// no need for jemalloc bloat in this binary (and we don't need speed)
|
||||
|
@ -1,16 +1,10 @@
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
extern crate docopt;
|
||||
extern crate failure;
|
||||
extern crate wasm_bindgen_cli_support;
|
||||
|
||||
use docopt::Docopt;
|
||||
use failure::{Error, ResultExt};
|
||||
use serde::Deserialize;
|
||||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
use std::process;
|
||||
|
||||
use docopt::Docopt;
|
||||
use failure::{Error, ResultExt};
|
||||
|
||||
// no need for jemalloc bloat in this binary (and we don't need speed)
|
||||
#[global_allocator]
|
||||
static ALLOC: std::alloc::System = std::alloc::System;
|
||||
@ -70,7 +64,7 @@ fn rmain(args: &Args) -> Result<(), Error> {
|
||||
.generate(&wasm)?;
|
||||
|
||||
if args.flag_typescript {
|
||||
let ts = object.typescript();
|
||||
let ts = object.typescript()?;
|
||||
write(&args, "d.ts", ts.as_bytes(), false)?;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user