Last active
February 21, 2023 01:52
-
-
Save Codezigineer/501c09f8a3114ce7bb32c7d27301650b to your computer and use it in GitHub Desktop.
webcomp: Very simple WebAssembly compiler based on LLVM 8+
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [[ "$(curl https://gist.github.com/Codezigineer/501c09f8a3114ce7bb32c7d27301650b/raw/webcomp.sh)" != "$(cat $0)" ]]; then | |
cd "$(dirname $0)" | |
curl https://gist.github.com/Codezigineer/501c09f8a3114ce7bb32c7d27301650b/raw/webcomp.sh -o webcomp | |
fi | |
usage() { | |
echo "Usage: webcomp [ -f infile ] [ -o outfile ] [ -O0 ] [ -O1 ] [ -O2 ] [ -O3 ] [ -t target {default is wasm32} ] [ -O ]" | |
} | |
set -e | |
target=wasm32 | |
optlevel= | |
while getopts ":f:o:O0:O1:O2:O3:t:O:" o; do | |
case "${o}" in | |
f) | |
in="$in ${OPTARG}" | |
;; | |
o) | |
out=${OPTARG} | |
;; | |
O0) | |
;; | |
O1) | |
optlevel=-01 | |
;; | |
O2) | |
optlevel=-02 | |
;; | |
O3) | |
optlevel=-03 | |
;; | |
t) | |
target=${OPTARG} | |
;; | |
*) | |
if [[ -z "${in}" ]] || [[ -z "${out}" ]]; then | |
usage | |
exit 1 | |
fi | |
;; | |
esac | |
done | |
if [[ -z "$in" ]]; then | |
usage | |
exit 1; | |
elif [[ -z "$out" ]]; then | |
usage | |
exit 1; | |
fi | |
if [[ "$target" != "wasm32" ]] && [[ "$target" != "wasm64" ]]; then | |
target=wasm32 | |
fi | |
oldpwd=$PWD | |
folder=$(mktemp -d) | |
cd $folder | |
wget https://github.com/PicsumProjects/wclibc/releases/download/latest/wclibc-${target}.wasm -o wclibc.wasm | |
clang \ | |
--target=$target \ | |
-nostdlib \ | |
-Wl,--no-entry \ | |
-Wl,--export-all \ | |
./wclibc.wasm | |
$in | |
-o $oldpwd/$out | |
cd $oldpwd | |
rm -rf $folder |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment