1
mirror of https://github.com/jedisct1/libsodium.git synced 2024-12-20 02:25:14 -07:00
libsodium/dist-build/wasm32-wasi.sh

59 lines
1.5 KiB
Bash
Raw Normal View History

2019-04-08 11:47:33 -07:00
#! /bin/sh
if [ -z "$WASI_LIBC" ]; then
for path in /opt/wasi-libc /opt/wasi-sysroot; do
if [ -d "$path" ]; then
export WASI_LIBC="$path"
break
fi
done
fi
if [ -z "$WASI_LIBC" ]; then
echo "Set WASI_LIBC to the path to the WASI libc sysroot" >&2
exit 1
2019-04-08 11:47:33 -07:00
fi
export PATH="/usr/local/opt/llvm/bin:$PATH"
export PREFIX="$(pwd)/libsodium-wasm32-wasi"
mkdir -p $PREFIX || exit 1
export CC="clang"
export CFLAGS="-DED25519_NONDETERMINISTIC=1 --target=wasm32-wasi --sysroot=${WASI_LIBC} -O2"
export LDFLAGS="-s -Wl,--no-threads -Wl,--stack-first"
2019-04-08 11:47:33 -07:00
export NM="llvm-nm"
export AR="llvm-ar"
export RANLIB="llvm-ranlib"
export STRIP="llvm-strip"
2020-07-04 06:32:13 -07:00
make distclean >/dev/null
2019-04-08 11:47:33 -07:00
2020-07-04 06:32:13 -07:00
grep -q -F -- 'wasi' build-aux/config.sub ||
2019-04-08 12:45:08 -07:00
sed -i -e 's/-nacl\*)/-nacl*|-wasi)/' build-aux/config.sub
2019-04-08 12:02:22 -07:00
2019-04-08 14:23:07 -07:00
if [ "x$1" = "x--bench" ]; then
export BENCHMARKS=1
export CPPFLAGS="-DBENCHMARKS -DITERATIONS=100"
2019-04-08 14:23:07 -07:00
fi
if [ -n "$LIBSODIUM_MINIMAL_BUILD" ]; then
2019-04-08 11:47:33 -07:00
export LIBSODIUM_ENABLE_MINIMAL_FLAG="--enable-minimal"
else
export LIBSODIUM_ENABLE_MINIMAL_FLAG=""
fi
./configure ${LIBSODIUM_ENABLE_MINIMAL_FLAG} \
2020-07-04 06:32:13 -07:00
--prefix="$PREFIX" --with-sysroot="$WASI_LIBC" \
--host=wasm32-wasi \
--disable-ssp --disable-shared || exit 1
2019-04-08 11:47:33 -07:00
NPROCESSORS=$(getconf NPROCESSORS_ONLN 2>/dev/null || getconf _NPROCESSORS_ONLN 2>/dev/null)
PROCESSORS=${NPROCESSORS:-3}
2019-04-08 14:23:07 -07:00
if [ -z "$BENCHMARKS" ]; then
2020-07-04 06:32:13 -07:00
make -j${PROCESSORS} check && make install && make distclean >/dev/null
else
make -j${PROCESSORS} && make check
2019-04-08 14:23:07 -07:00
fi