2019-04-11 21:57:29 +00:00
|
|
|
#! /usr/bin/env python3
|
|
|
|
|
|
|
|
from argparse import ArgumentParser
|
2019-07-22 20:33:05 +00:00
|
|
|
from subprocess import check_call
|
|
|
|
from shutil import copyfile
|
2019-04-11 21:57:29 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
parser = ArgumentParser(description="Build js and wasm")
|
|
|
|
parser.add_argument("-r", help="Build release type",
|
|
|
|
dest="release", action="store_true")
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
if args.release:
|
2019-07-22 20:33:05 +00:00
|
|
|
check_call(["cargo", "build", "--release",
|
|
|
|
"--target", "wasm32-unknown-unknown"])
|
2019-04-11 21:57:29 +00:00
|
|
|
target = "target/wasm32-unknown-unknown/release/webgl.wasm"
|
|
|
|
else:
|
2019-07-22 20:33:05 +00:00
|
|
|
check_call(["cargo", "build",
|
|
|
|
"--target", "wasm32-unknown-unknown"])
|
2019-04-11 21:57:29 +00:00
|
|
|
target = "target/wasm32-unknown-unknown/debug/webgl.wasm"
|
|
|
|
|
2019-07-22 20:33:05 +00:00
|
|
|
check_call(["wasm-bindgen", target, "--out-dir", ".",
|
|
|
|
"--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
|