Skip to content

Commit

Permalink
Add wasm-opt to build
Browse files Browse the repository at this point in the history
  • Loading branch information
0rphee committed Jan 17, 2025
1 parent 6e93cfa commit cb86fb8
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,4 @@ dist

*~
web/src/ghc_wasm_jsffi.js
web/static/xolsh-exe.wasm
2 changes: 2 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
jlox-test
ghc-wasm-meta.packages.${system}.wasm32-wasi-ghc-9_10
ghc-wasm-meta.packages.${system}.wasm32-wasi-cabal-9_10

pkgs.binaryen # wasm-opt
pkgs.wasmtime

# for https://gitlab.haskell.org/ghc/ghc/-/blob/master/utils/jsffi/post-link.mjs
Expand Down
2 changes: 1 addition & 1 deletion loxexamples/ch10.lox
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ fun fib(n) {
}

print "begin fib";
for (var i = 0; i < 35; i = i + 1) {
for (var i = 0; i < 25; i = i + 1) {
print fib(i);
}
print "end fib, begin count";
Expand Down
14 changes: 12 additions & 2 deletions web/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ outdir=""
case $1 in
dev)
echo "dev run"
outdir="./static/"
outdir="./static"
;;
prod)
echo "prod run"
wasm32-wasi-cabal update
npm install
outdir="./dist/"
outdir="./dist"
cp -R static/ $outdir/
;;
*)
Expand All @@ -28,6 +28,16 @@ wasm32-wasi-cabal build xolsh-exe && wasmpath=$(wasm32-wasi-cabal list-bin xolsh

cp -f $wasmpath $outdir/xolsh-exe.wasm

# O1 is better than On n>=2
optflags="-O1 --strip-debug"
optargs="$outdir/xolsh-exe.wasm -o $outdir/xolsh-exe.wasm"
echo running wasm-opt $optflags $optargs
wasm-opt $optflags $optargs
# "wasm-tools strip" doesnt seem to have any effect (size changed 5056952 -> 5057240)
# it even seems to degrade a bit the performance
# wasm-tools strip $optargs
echo end running wasm-opt

case $1 in
dev)
esbuild ./src/index.js --bundle --serve=127.0.0.1:9000 --servedir=./static --outfile=./static/index.js --format=esm --platform=browser "--external:node:timers"
Expand Down
4 changes: 2 additions & 2 deletions web/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
</head>
<body>
<header>
<div>
<div class="h-title">
<h2>xolsh - hslox</h2>
<div>a lox interpreter</div>
</div>
<div>
<div class="h-buttons">
<button id="run-button" class="btn btn-primary">
<i class="fa-solid fa-play"></i> Run
</button>
Expand Down
14 changes: 12 additions & 2 deletions web/static/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ header {
align-items: center;
padding: 1.5rem;
background-color: var(--normal-bg);
/* small screens*/
gap: 2rem;
}

a {
Expand All @@ -45,13 +47,21 @@ header>div>h2 {
margin: 0;
}

header>div {
.h-title,
.h-buttons {
margin: 0;
display: flex;
gap: 2rem;
align-items: center;
}

.h-title {
gap: 1.5rem;
}

.h-buttons {
gap: 1.5rem;
}

button {
font-family: monospace;
margin: 0;
Expand Down
1 change: 0 additions & 1 deletion web/xolsh-web.wasm

This file was deleted.

0 comments on commit cb86fb8

Please sign in to comment.