Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxime Bedard committed Aug 12, 2021
1 parent 33a2a37 commit ba6117a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
16 changes: 4 additions & 12 deletions crates/cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ fn main() {
// When using clippy, we need to write a stubbed engine.wasm file to ensure compilation succeeds. This
// skips building the actual engine.wasm binary that would be injected into the CLI binary.
fn stub_engine_for_clippy() {
let engine_path = PathBuf::from(env::var("OUT_DIR").unwrap())
.join("engine.wasm");
let engine_path = PathBuf::from(env::var("OUT_DIR").unwrap()).join("engine.wasm");

if !engine_path.exists() {
std::fs::write(engine_path, &[]).expect("failed to write empty engine.wasm stub");
Expand Down Expand Up @@ -59,8 +58,7 @@ fn copy_engine_binary() {
println!("cargo:rerun-if-changed={:?}", engine_path);

if engine_path.exists() {
let copied_engine_path = PathBuf::from(env::var("OUT_DIR").unwrap())
.join("engine.wasm");
let copied_engine_path = PathBuf::from(env::var("OUT_DIR").unwrap()).join("engine.wasm");

fs::copy(&engine_path, &copied_engine_path).unwrap();
optimize_engine(&copied_engine_path);
Expand All @@ -78,10 +76,7 @@ fn optimize_engine(engine_path: impl AsRef<Path>) {

fn run_wasm_strip(engine_path: impl AsRef<Path>) {
let wasm_strip = which::which("wasm-strip")
.unwrap_or_else(|_| {
PathBuf::from(env::var("OUT_DIR").unwrap())
.join("vendor/wasm-opt")
});
.unwrap_or_else(|_| PathBuf::from(env::var("OUT_DIR").unwrap()).join("vendor/wasm-opt"));

let output = Command::new(wasm_strip)
.arg(engine_path.as_ref())
Expand All @@ -96,10 +91,7 @@ fn run_wasm_strip(engine_path: impl AsRef<Path>) {

fn run_wasm_opt(engine_path: impl AsRef<Path>) {
let wasm_opt = which::which("wasm-opt")
.unwrap_or_else(|_| {
PathBuf::from(env::var("OUT_DIR").unwrap())
.join("vendor/wasm-opt")
});
.unwrap_or_else(|_| PathBuf::from(env::var("OUT_DIR").unwrap()).join("vendor/wasm-opt"));

let output = Command::new(wasm_opt)
.arg(engine_path.as_ref())
Expand Down
13 changes: 10 additions & 3 deletions crates/cli/src/opt.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use anyhow::{bail, Error, Result};
use std::path::{PathBuf, Path};
use std::path::{Path, PathBuf};
use std::process::Command;
use wizer::Wizer;

Expand All @@ -14,7 +14,12 @@ pub(crate) struct Optimizer<'a> {

impl<'a> Optimizer<'a> {
pub fn new(wasm: &'a [u8], script: PathBuf) -> Self {
Self { wasm, script, strip: false, optimize: false }
Self {
wasm,
script,
strip: false,
optimize: false,
}
}

pub fn strip(self, strip: bool) -> Self {
Expand All @@ -26,7 +31,9 @@ impl<'a> Optimizer<'a> {
}

pub fn write_optimized_wasm(self, dest: impl AsRef<Path>) -> Result<(), Error> {
let dir = self.script.parent()
let dir = self
.script
.parent()
.filter(|p| p.is_dir())
.ok_or(anyhow::anyhow!("input script is not a file"))?;

Expand Down

0 comments on commit ba6117a

Please sign in to comment.