WASI: remove wasi-sdk dependency; build module with zig

This commit is contained in:
Frank Denis 2021-07-19 12:12:56 +02:00
parent 7d71804ee0
commit 4a64ce1836
4 changed files with 38 additions and 35 deletions

View File

@ -7,19 +7,19 @@ pr: none
jobs:
- job: "wasi"
pool:
vmImage: "ubuntu-18.04"
vmImage: "ubuntu-20.04"
steps:
- script: |
sudo apt-get install build-essential curl cmake
sudo apt-get install build-essential curl cmake llvm lld
displayName: Install system packages
- script: |
curl https://get.wasmer.io -sSfL | sh
displayName: Install wasmer
- script: |
curl -sL -o - https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-12/wasi-sdk-12.0-linux.tar.gz | tar xz -f - -C /opt/
sudo mv /opt/wasi-sdk-* /opt/wasi-sdk
sudo ln -s /opt/wasi-sdk/share/*sysroot* /opt/wasi-sysroot
displayName: Install the WASI SDK
curl -sL -o - https://ziglang.org/download/0.8.0/zig-linux-x86_64-0.8.0.tar.xz | tar xJ -f - -C /opt/
sudo mv /opt/zig-* /opt/zig
env PATH=/opt/zig/bin:/opt/zig:$PATH
displayName: Install the Zig SDK
- script: |
env WASMER_DIR=${HOME}/.wasmer PATH=${HOME}/.wasmer/bin:/opt/wasi-sdk/bin:${HOME}/.cargo/bin:$PATH dist-build/wasm32-wasi.sh
displayName: Compile libsodium

15
configure vendored
View File

@ -20290,7 +20290,10 @@ then :
fi
ac_fn_c_check_func "$LINENO" "mmap" "ac_cv_func_mmap"
if test "x$WASI" = "x"
then :
ac_fn_c_check_func "$LINENO" "mmap" "ac_cv_func_mmap"
if test "x$ac_cv_func_mmap" = xyes
then :
printf "%s\n" "#define HAVE_MMAP 1" >>confdefs.h
@ -20316,6 +20319,8 @@ then :
fi
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for getrandom with a standard API" >&5
printf %s "checking for getrandom with a standard API... " >&6; }
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
@ -20452,7 +20457,11 @@ then :
fi
ac_fn_c_check_func "$LINENO" "memset_s" "ac_cv_func_memset_s"
if test "x$WASI" = "x"
then :
ac_fn_c_check_func "$LINENO" "memset_s" "ac_cv_func_memset_s"
if test "x$ac_cv_func_memset_s" = xyes
then :
printf "%s\n" "#define HAVE_MEMSET_S 1" >>confdefs.h
@ -20472,6 +20481,8 @@ then :
fi
fi
TEST_LDFLAGS=''

View File

@ -810,7 +810,9 @@ dnl Checks for functions and headers
AC_FUNC_ALLOCA
AS_IF([test "x$EMSCRIPTEN" = "x"],[
AC_CHECK_FUNCS([arc4random arc4random_buf])
AC_CHECK_FUNCS([mmap mlock madvise mprotect])
AS_IF([test "x$WASI" = "x"],[
AC_CHECK_FUNCS([mmap mlock madvise mprotect])
])
AC_MSG_CHECKING(for getrandom with a standard API)
AC_LINK_IFELSE([AC_LANG_PROGRAM([[
@ -864,7 +866,10 @@ AS_IF([test "x$WASI" = "x"],[
])
AC_CHECK_FUNCS([posix_memalign nanosleep])
AC_CHECK_FUNCS([memset_s explicit_bzero explicit_memset])
AS_IF([test "x$WASI" = "x"],[
AC_CHECK_FUNCS([memset_s explicit_bzero explicit_memset])
])
AC_SUBST([LIBTOOL_EXTRA_FLAGS])

View File

@ -1,36 +1,20 @@
#! /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
fi
export PATH="/usr/local/opt/llvm/bin:$PATH"
export PATH="/opt/zig/bin:/opt/zig:/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 CC="zig cc"
export CFLAGS="-DED25519_NONDETERMINISTIC=1 --target=wasm32-wasi -O2"
export LDFLAGS="-s -Wl,--stack-first"
export NM="llvm-nm"
export AR="llvm-ar"
export RANLIB="llvm-ranlib"
export STRIP="llvm-strip"
make distclean > /dev/null
grep -q -F -- 'wasi' build-aux/config.sub || \
sed -i -e 's/-nacl\*)/-nacl*|-wasi)/' build-aux/config.sub
make distclean >/dev/null
if [ "x$1" = "x--bench" ]; then
export BENCHMARKS=1
@ -43,16 +27,19 @@ else
export LIBSODIUM_ENABLE_MINIMAL_FLAG=""
fi
./configure ${LIBSODIUM_ENABLE_MINIMAL_FLAG} \
--prefix="$PREFIX" --with-sysroot="$WASI_LIBC" \
--host=wasm32-wasi \
--disable-ssp --disable-shared || exit 1
if ! ./configure ${LIBSODIUM_ENABLE_MINIMAL_FLAG} \
--prefix="$PREFIX" \
--host=wasm32-wasi \
--disable-ssp --disable-shared --without-pthreads; then
cat config.log
exit 1
fi
NPROCESSORS=$(getconf NPROCESSORS_ONLN 2>/dev/null || getconf _NPROCESSORS_ONLN 2>/dev/null)
PROCESSORS=${NPROCESSORS:-3}
if [ -z "$BENCHMARKS" ]; then
make -j${PROCESSORS} check && make install && make distclean > /dev/null
make -j${PROCESSORS} check && make install && make distclean >/dev/null
else
make -j${PROCESSORS} && make check
fi