Skip to content

Commit

Permalink
remove binaryen for windows
Browse files Browse the repository at this point in the history
Signed-off-by: karthik Ganeshram <karthik.ganeshram@fermyon.com>
  • Loading branch information
karthik2804 committed Nov 30, 2022
1 parent d692160 commit be913b9
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 24 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

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

57 changes: 35 additions & 22 deletions crates/spin-js-cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#![deny(warnings)]

#[cfg(not(target_os = "windows"))]
use binaryen::{CodegenConfig, Module};
use {
anyhow::{bail, Context, Result},
binaryen::{CodegenConfig, Module},
std::{
env,
fs::{self, File},
Expand Down Expand Up @@ -31,28 +32,40 @@ fn main() -> Result<()> {

let wasm: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/engine.wasm"));

let mut wasm = Wizer::new()
.allow_wasi(true)?
.inherit_stdio(true)
.run(wasm)?;

let codegen_cfg = CodegenConfig {
optimization_level: 3,
shrink_level: 0,
debug_info: false,
};

if let Ok(mut module) = Module::read(&wasm) {
module.optimize(&codegen_cfg);
module
.run_optimization_passes(vec!["strip"], &codegen_cfg)
.unwrap();
wasm = module.write();
} else {
bail!("Unable to read wasm binary for wasm-opt optimizations");
// using binaryen on windows causes spinjs to silently generate malformed wasm
#[cfg(target_os = "windows")]
{
let wasm = Wizer::new()
.allow_wasi(true)?
.inherit_stdio(true)
.run(wasm)?;
fs::write(&opts.output, wasm)?;
}
#[cfg(not(target_os = "windows"))]
{
let mut wasm = Wizer::new()
.allow_wasi(true)?
.inherit_stdio(true)
.run(wasm)?;

let codegen_cfg = CodegenConfig {
optimization_level: 3,
shrink_level: 0,
debug_info: false,
};

if let Ok(mut module) = Module::read(&wasm) {
module.optimize(&codegen_cfg);
module
.run_optimization_passes(vec!["strip"], &codegen_cfg)
.unwrap();
wasm = module.write();
} else {
bail!("Unable to read wasm binary for wasm-opt optimizations");
}

fs::write(&opts.output, wasm)?;
}

fs::write(&opts.output, wasm)?;

return Ok(());
}
Expand Down

0 comments on commit be913b9

Please sign in to comment.