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: jobs:
- job: "wasi" - job: "wasi"
pool: pool:
vmImage: "ubuntu-18.04" vmImage: "ubuntu-20.04"
steps: steps:
- script: | - script: |
sudo apt-get install build-essential curl cmake sudo apt-get install build-essential curl cmake llvm lld
displayName: Install system packages displayName: Install system packages
- script: | - script: |
curl https://get.wasmer.io -sSfL | sh curl https://get.wasmer.io -sSfL | sh
displayName: Install wasmer displayName: Install wasmer
- script: | - 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/ 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/wasi-sdk-* /opt/wasi-sdk sudo mv /opt/zig-* /opt/zig
sudo ln -s /opt/wasi-sdk/share/*sysroot* /opt/wasi-sysroot env PATH=/opt/zig/bin:/opt/zig:$PATH
displayName: Install the WASI SDK displayName: Install the Zig SDK
- script: | - script: |
env WASMER_DIR=${HOME}/.wasmer PATH=${HOME}/.wasmer/bin:/opt/wasi-sdk/bin:${HOME}/.cargo/bin:$PATH dist-build/wasm32-wasi.sh 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 displayName: Compile libsodium

13
configure vendored
View File

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

View File

@ -810,7 +810,9 @@ dnl Checks for functions and headers
AC_FUNC_ALLOCA AC_FUNC_ALLOCA
AS_IF([test "x$EMSCRIPTEN" = "x"],[ AS_IF([test "x$EMSCRIPTEN" = "x"],[
AC_CHECK_FUNCS([arc4random arc4random_buf]) AC_CHECK_FUNCS([arc4random arc4random_buf])
AS_IF([test "x$WASI" = "x"],[
AC_CHECK_FUNCS([mmap mlock madvise mprotect]) AC_CHECK_FUNCS([mmap mlock madvise mprotect])
])
AC_MSG_CHECKING(for getrandom with a standard API) AC_MSG_CHECKING(for getrandom with a standard API)
AC_LINK_IFELSE([AC_LANG_PROGRAM([[ 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([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]) AC_SUBST([LIBTOOL_EXTRA_FLAGS])

View File

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