use wasm-opt if available

This commit is contained in:
Magnus Ulimoen 2019-07-22 22:33:05 +02:00
parent 5bd6d0d487
commit e516154d14
1 changed files with 17 additions and 7 deletions

View File

@ -1,7 +1,8 @@
#! /usr/bin/env python3 #! /usr/bin/env python3
from argparse import ArgumentParser from argparse import ArgumentParser
from subprocess import call from subprocess import check_call
from shutil import copyfile
if __name__ == "__main__": if __name__ == "__main__":
parser = ArgumentParser(description="Build js and wasm") parser = ArgumentParser(description="Build js and wasm")
@ -11,13 +12,22 @@ if __name__ == "__main__":
args = parser.parse_args() args = parser.parse_args()
if args.release: if args.release:
call(["cargo", "build", "--release", check_call(["cargo", "build", "--release",
"--target", "wasm32-unknown-unknown"]) "--target", "wasm32-unknown-unknown"])
target = "target/wasm32-unknown-unknown/release/webgl.wasm" target = "target/wasm32-unknown-unknown/release/webgl.wasm"
else: else:
call(["cargo", "build", check_call(["cargo", "build",
"--target", "wasm32-unknown-unknown"]) "--target", "wasm32-unknown-unknown"])
target = "target/wasm32-unknown-unknown/debug/webgl.wasm" target = "target/wasm32-unknown-unknown/debug/webgl.wasm"
call(["wasm-bindgen", target, "--out-dir", ".", check_call(["wasm-bindgen", target, "--out-dir", ".",
"--no-typescript", "--target", "web"]) "--no-typescript", "--target", "web"])
if args.release:
try:
copyfile("webgl_bg.wasm", "before-wasm-opt.wasm")
check_call(["wasm-opt", "-O4", "before-wasm-opt.wasm",
"-o", "webgl_bg.wasm"])
except FileNotFoundError:
print("wasm-opt not found, not optimising further")
pass