Skip to content

Commit

Permalink
Merge branch 'main' into jake/wasmtime
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake Champion authored Apr 14, 2023
2 parents 6eacb7e + 6861267 commit 9f527bf
Show file tree
Hide file tree
Showing 14 changed files with 86 additions and 46 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ license = "Apache-2.0 WITH LLVM-exception"
name = "wizer"
readme = "./README.md"
repository = "https://github.com/bytecodealliance/wizer"
version = "1.6.0"
version = "1.6.1-beta.4"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
1 change: 1 addition & 0 deletions fuzz/fuzz_targets/same_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ fn assert_val_eq(a: &Val, b: &Val) {
let b = f64::from_bits(*b);
a == b || (a.is_nan() && b.is_nan())
}),
(Val::V128(a), Val::V128(b)) => assert_eq!(a, b),
_ => panic!("{:?} != {:?}", a, b),
}
}
Expand Down
4 changes: 2 additions & 2 deletions npm/wizer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
## API

```
$ npm install --save @bytecode-alliance/wizer
$ npm install --save @bytecodealliance/wizer
```

```js
const execFile = require('child_process').execFile;
const wizer = require('@bytecode-alliance/wizer');
const wizer = require('@bytecodealliance/wizer');

execFile(wizer, ['input.wasm', '-o', 'initialized.wasm'], (err, stdout) => {
console.log(stdout);
Expand Down
16 changes: 8 additions & 8 deletions npm/wizer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { endianness } from "node:os";
import { platform, arch } from "node:process";

const knownPackages = {
"win32 x64 LE": "@bytecode-alliance/wizer-win32-x64",
"darwin arm64 LE": "@bytecode-alliance/wizer-darwin-arm64",
"darwin x64 LE": "@bytecode-alliance/wizer-darwin-x64",
"linux x64 LE": "@bytecode-alliance/wizer-linux-x64",
"win32 x64 LE": "@bytecodealliance/wizer-win32-x64",
"darwin arm64 LE": "@bytecodealliance/wizer-darwin-arm64",
"darwin x64 LE": "@bytecodealliance/wizer-darwin-x64",
"linux x64 LE": "@bytecodealliance/wizer-linux-x64",
};

function pkgForCurrentPlatform() {
Expand All @@ -14,7 +14,7 @@ function pkgForCurrentPlatform() {
if (platformKey in knownPackages) {
return knownPackages[platformKey];
}
throw new Error(`Unsupported platform: "${platformKey}". "@bytecode-alliance/wizer does not have a precompiled binary for the platform/architecture you are using. You can open an issue on https://github.com/bytecodealliance/wizer/issues to request for your platform/architecture to be included."`);
throw new Error(`Unsupported platform: "${platformKey}". "@bytecodealliance/wizer does not have a precompiled binary for the platform/architecture you are using. You can open an issue on https://github.com/bytecodealliance/wizer/issues to request for your platform/architecture to be included."`);
}

const pkg = pkgForCurrentPlatform();
Expand All @@ -25,10 +25,10 @@ try {
// package should have been installed alongside this package at install time.
location = (await import(pkg)).default;
} catch (e) {
throw new Error(`The package "${pkg}" could not be found, and is needed by @bytecode-alliance/wizer.
If you are installing @bytecode-alliance/wizer with npm, make sure that you don't specify the
throw new Error(`The package "${pkg}" could not be found, and is needed by @bytecodealliance/wizer.
If you are installing @bytecodealliance/wizer with npm, make sure that you don't specify the
"--no-optional" flag. The "optionalDependencies" package.json feature is used
by @bytecode-alliance/wizer to install the correct binary executable for your current platform.`);
by @bytecodealliance/wizer to install the correct binary executable for your current platform.`);
}

export default location;
16 changes: 8 additions & 8 deletions npm/wizer/package-lock.json

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

15 changes: 6 additions & 9 deletions npm/wizer/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
{
"name": "@bytecode-alliance/wizer",
"version": "1.6.0",
"name": "@bytecodealliance/wizer",
"version": "1.6.1-beta.4",
"description": "The WebAssembly Pre-Initializer",
"type": "module",
"publishConfig": {
"access": "public"
},
"scripts": {
"version": "node ./update.js $npm_package_version"
},
Expand All @@ -23,10 +20,10 @@
"wizer": "./wizer.js"
},
"optionalDependencies": {
"@bytecode-alliance/wizer-darwin-arm64": "1.6.0",
"@bytecode-alliance/wizer-darwin-x64": "1.6.0",
"@bytecode-alliance/wizer-linux-x64": "1.6.0",
"@bytecode-alliance/wizer-win32-x64": "1.6.0"
"@bytecodealliance/wizer-darwin-arm64": "1.6.1-beta.4",
"@bytecodealliance/wizer-darwin-x64": "1.6.1-beta.4",
"@bytecodealliance/wizer-linux-x64": "1.6.1-beta.4",
"@bytecodealliance/wizer-win32-x64": "1.6.1-beta.4"
},
"license": "Apache-2.0",
"repository": {
Expand Down
5 changes: 1 addition & 4 deletions npm/wizer/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export default location
function packageJson(name, version, description, os, cpu) {
version = version.startsWith('v') ? version.replace('v','') : version
return JSON.stringify({
name: `@bytecode-alliance/${name}`,
name: `@bytecodealliance/${name}`,
bin: {
[name]: "wizer"
},
Expand All @@ -129,8 +129,5 @@ function packageJson(name, version, description, os, cpu) {
preferUnplugged: false,
os: [os],
cpu: [cpu],
publishConfig: {
access: "public"
},
}, null, 4);
}
16 changes: 8 additions & 8 deletions npm/wizer/wizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { endianness } from "node:os";
import { platform, arch } from "node:process";
import { execFileSync } from "node:child_process";
const knownPackages = {
"win32 x64 LE": "@bytecode-alliance/wizer-win32-x64",
"darwin arm64 LE": "@bytecode-alliance/wizer-darwin-arm64",
"darwin x64 LE": "@bytecode-alliance/wizer-darwin-x64",
"linux x64 LE": "@bytecode-alliance/wizer-linux-x64",
"win32 x64 LE": "@bytecodealliance/wizer-win32-x64",
"darwin arm64 LE": "@bytecodealliance/wizer-darwin-arm64",
"darwin x64 LE": "@bytecodealliance/wizer-darwin-x64",
"linux x64 LE": "@bytecodealliance/wizer-linux-x64",
};

function pkgForCurrentPlatform() {
Expand All @@ -15,7 +15,7 @@ function pkgForCurrentPlatform() {
if (platformKey in knownPackages) {
return knownPackages[platformKey];
}
throw new Error(`Unsupported platform: "${platformKey}". "@bytecode-alliance/wizer does not have a precompiled binary for the platform/architecture you are using. You can open an issue on https://github.com/bytecodealliance/wizer/issues to request for your platform/architecture to be included."`);
throw new Error(`Unsupported platform: "${platformKey}". "@bytecodealliance/wizer does not have a precompiled binary for the platform/architecture you are using. You can open an issue on https://github.com/bytecodealliance/wizer/issues to request for your platform/architecture to be included."`);
}

const pkg = pkgForCurrentPlatform();
Expand All @@ -26,10 +26,10 @@ try {
// package should have been installed alongside this package at install time.
location = (await import(pkg)).default;
} catch (e) {
throw new Error(`The package "${pkg}" could not be found, and is needed by @bytecode-alliance/wizer.
If you are installing @bytecode-alliance/wizer with npm, make sure that you don't specify the
throw new Error(`The package "${pkg}" could not be found, and is needed by @bytecodealliance/wizer.
If you are installing @bytecodealliance/wizer with npm, make sure that you don't specify the
"--no-optional" flag. The "optionalDependencies" package.json feature is used
by @bytecode-alliance/wizer to install the correct binary executable for your current platform.`);
by @bytecodealliance/wizer to install the correct binary executable for your current platform.`);
}

execFileSync(location, process.argv.slice(2), { stdio: "inherit" });
23 changes: 21 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const DEFAULT_KEEP_INIT_FUNC: bool = false;
const DEFAULT_WASM_MULTI_VALUE: bool = true;
const DEFAULT_WASM_MULTI_MEMORY: bool = true;
const DEFAULT_WASM_BULK_MEMORY: bool = false;
const DEFAULT_WASM_SIMD: bool = true;

/// We only ever use `Store<T>` with a fixed `T` that is our optional WASI
/// context.
Expand Down Expand Up @@ -202,6 +203,12 @@ pub struct Wizer {
/// Disabled by default.
#[cfg_attr(feature = "structopt", structopt(long, value_name = "true|false"))]
wasm_bulk_memory: Option<bool>,

/// Enable or disable the Wasm SIMD128 proposal.
///
/// Enabled by default.
#[cfg_attr(feature = "structopt", structopt(long, value_name = "true|false"))]
wasm_simd: Option<bool>,
}

impl std::fmt::Debug for Wizer {
Expand All @@ -219,6 +226,7 @@ impl std::fmt::Debug for Wizer {
wasm_multi_memory,
wasm_multi_value,
wasm_bulk_memory,
wasm_simd,
} = self;
f.debug_struct("Wizer")
.field("init_func", &init_func)
Expand All @@ -233,6 +241,7 @@ impl std::fmt::Debug for Wizer {
.field("wasm_multi_memory", &wasm_multi_memory)
.field("wasm_multi_value", &wasm_multi_value)
.field("wasm_bulk_memory", &wasm_bulk_memory)
.field("wasm_simd", &wasm_simd)
.finish()
}
}
Expand Down Expand Up @@ -294,6 +303,7 @@ impl Wizer {
wasm_multi_memory: None,
wasm_multi_value: None,
wasm_bulk_memory: None,
wasm_simd: None,
}
}

Expand Down Expand Up @@ -437,6 +447,14 @@ impl Wizer {
self
}

/// Enable or disable the Wasm SIMD128 proposal.
///
/// Defaults to `true`.
pub fn wasm_simd(&mut self, enable: bool) -> &mut Self {
self.wasm_simd = Some(enable);
self
}

/// Initialize the given Wasm, snapshot it, and return the serialized
/// snapshot as a new, pre-initialized Wasm module.
pub fn run(&self, wasm: &[u8]) -> anyhow::Result<Vec<u8>> {
Expand Down Expand Up @@ -511,9 +529,10 @@ impl Wizer {
// `memory.init` for the time being:
config.wasm_bulk_memory(self.wasm_bulk_memory.unwrap_or(DEFAULT_WASM_BULK_MEMORY));

config.wasm_simd(self.wasm_simd.unwrap_or(DEFAULT_WASM_SIMD));

// Proposals that we should add support for.
config.wasm_reference_types(false);
config.wasm_simd(false);
config.wasm_threads(false);

Ok(config)
Expand All @@ -532,7 +551,7 @@ impl Wizer {

// Proposals that we should add support for.
reference_types: false,
simd: false,
simd: self.wasm_simd.unwrap_or(DEFAULT_WASM_SIMD),
threads: false,
tail_call: false,
memory64: false,
Expand Down
3 changes: 3 additions & 0 deletions src/rewrite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ impl Wizer {
wasmtime::Val::F64(x) => {
wasm_encoder::Instruction::F64Const(f64::from_bits(*x))
}
wasmtime::Val::V128(x) => {
wasm_encoder::Instruction::V128Const(*x as i128)
}
_ => unreachable!(),
},
);
Expand Down
6 changes: 4 additions & 2 deletions src/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ use wasmtime::{AsContext, AsContextMut};

const WASM_PAGE_SIZE: u64 = 65_536;

/// The maximum number of data segments that most engines support.
const MAX_DATA_SEGMENTS: usize = 100_000;
/// The maximum number of data segments that we will emit. Most
/// engines support more than this, but we want to leave some
/// headroom.
const MAX_DATA_SEGMENTS: usize = 10_000;

/// A "snapshot" of Wasm state from its default value after having been initialized.
pub struct Snapshot {
Expand Down
3 changes: 2 additions & 1 deletion src/translate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ pub(crate) fn val_type(ty: wasmparser::ValType) -> wasm_encoder::ValType {
I64 => ValType::I64,
F32 => ValType::F32,
F64 => ValType::F64,
V128 => ValType::V128,
FuncRef => ValType::FuncRef,
V128 | ExternRef => panic!("not supported"),
ExternRef => panic!("not supported"),
}
}

Expand Down
20 changes: 20 additions & 0 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -643,3 +643,23 @@ fn accept_bulk_memory_init() -> Result<()> {
"#,
)
}

#[test]
fn accept_simd128() -> Result<()> {
run_wat(
&[],
49,
r#"
(module
(global $g (mut v128) (v128.const i32x4 2 3 5 7))
(func (export "wizer.initialize")
global.get $g
global.get $g
i32x4.mul
global.set $g)
(func (export "run") (result i32)
global.get $g
i32x4.extract_lane 3))
"#,
)
}

0 comments on commit 9f527bf

Please sign in to comment.