2022-03-15 09:33:34 -04:00
|
|
|
#!/bin/bash
|
|
|
|
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
|
|
|
|
2022-12-25 11:46:32 -05:00
|
|
|
set -eo pipefail
|
|
|
|
|
|
|
|
get_abs_filename() {
|
|
|
|
# $1 : relative filename
|
|
|
|
echo "$(cd "$(dirname "$1")" && pwd)/$(basename "$1")"
|
|
|
|
}
|
|
|
|
|
2022-03-17 10:31:10 -04:00
|
|
|
pushd $SCRIPTDIR &> /dev/null
|
|
|
|
|
2022-06-15 23:29:45 -04:00
|
|
|
if [ -f /usr/local/opt/llvm/bin/llvm-dwarfdump ]; then
|
|
|
|
DWARFDUMP=/usr/local/opt/llvm/bin/llvm-dwarfdump
|
|
|
|
elif [ -f /opt/homebrew/llvm/bin/llvm-dwarfdump ]; then
|
|
|
|
DWARFDUMP=/opt/homebrew/llvm/bin/llvm-dwarfdump
|
|
|
|
else
|
|
|
|
DWARFDUMP=`which llvm-dwarfdump`
|
|
|
|
if [[ "${DWARFDUMP}" == "" ]]; then
|
|
|
|
echo llvm-dwarfdump not found
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
2022-12-25 11:46:32 -05:00
|
|
|
if [[ "$1" == "release" ]]; then
|
|
|
|
OUTPUTDIR=../target/wasm32-unknown-unknown/release/pkg
|
|
|
|
INPUTDIR=../target/wasm32-unknown-unknown/release
|
|
|
|
|
2023-08-30 13:07:48 -04:00
|
|
|
# Path to, but not including, the cargo workspace ("veilid")
|
|
|
|
WORKSPACE_PARENT=$(dirname $(dirname $(cargo locate-project --workspace --message-format=plain)))
|
|
|
|
# Do not include said path in wasm blob output
|
|
|
|
RUSTFLAGS="--remap-path-prefix=$WORKSPACE_PARENT=/home/user $RUSTFLAGS"
|
|
|
|
# Do not include user home directory in wasm blob output
|
|
|
|
RUSTFLAGS="--remap-path-prefix=$HOME=/home/user $RUSTFLAGS"
|
|
|
|
# Explicitly mark RUSTFLAGS as an environment variable, so it's passed to cargo
|
|
|
|
export RUSTFLAGS
|
|
|
|
|
2022-12-25 11:46:32 -05:00
|
|
|
cargo build --target wasm32-unknown-unknown --release
|
|
|
|
mkdir -p $OUTPUTDIR
|
2023-09-04 17:34:49 -04:00
|
|
|
wasm-bindgen --out-dir $OUTPUTDIR --target web --weak-refs $INPUTDIR/veilid_wasm.wasm
|
2022-12-25 11:46:32 -05:00
|
|
|
wasm-strip $OUTPUTDIR/veilid_wasm_bg.wasm
|
|
|
|
else
|
2022-03-17 10:31:10 -04:00
|
|
|
OUTPUTDIR=../target/wasm32-unknown-unknown/debug/pkg
|
|
|
|
INPUTDIR=../target/wasm32-unknown-unknown/debug
|
|
|
|
|
2023-08-22 13:19:59 -04:00
|
|
|
RUSTFLAGS="-O -g $RUSTFLAGS" cargo build --target wasm32-unknown-unknown
|
2022-03-17 10:31:10 -04:00
|
|
|
mkdir -p $OUTPUTDIR
|
2023-09-04 17:34:49 -04:00
|
|
|
wasm-bindgen --out-dir $OUTPUTDIR --target web --weak-refs --keep-debug --debug $INPUTDIR/veilid_wasm.wasm
|
2022-06-15 23:29:45 -04:00
|
|
|
./wasm-sourcemap.py $OUTPUTDIR/veilid_wasm_bg.wasm -o $OUTPUTDIR/veilid_wasm_bg.wasm.map --dwarfdump $DWARFDUMP
|
2022-06-29 22:17:19 -04:00
|
|
|
# wasm-strip $OUTPUTDIR/veilid_wasm_bg.wasm
|
2022-03-15 09:33:34 -04:00
|
|
|
fi
|
|
|
|
|
2022-03-17 10:31:10 -04:00
|
|
|
popd &> /dev/null
|
2022-12-25 11:46:32 -05:00
|
|
|
|
|
|
|
# Print for use with scripts
|
2023-08-22 13:19:59 -04:00
|
|
|
echo SUCCESS:OUTPUTDIR=$(get_abs_filename $OUTPUTDIR)
|