gh-95205: Improve WASM README.md (GH-95267)

Co-authored-by: Erlend Egeberg Aasland <erlend.aasland@protonmail.com>
This commit is contained in:
Christian Heimes 2022-07-26 11:12:42 +02:00 committed by GitHub
parent 4395ff1e6a
commit e8f3e8f0ab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 112 additions and 12 deletions

68
Tools/wasm/wasi-env Executable file
View file

@ -0,0 +1,68 @@
#!/bin/sh
set -e
# function
usage() {
echo "wasi-env - Run command with WASI-SDK"
echo ""
echo "wasi-env is a helper to set various environment variables to"
echo "run configure and make with WASI-SDK. A WASI-SDK must be either"
echo "installed at /opt/wasi-sdk or the env var 'WASI_SDK_PATH' must"
echo "set to the root of a WASI-SDK."
echo ""
echo "Usage: wasi-env command [...]"
echo ""
echo " -h --help display this help and exit"
echo ""
}
case $1 in
-h|--help)
usage
exit
;;
esac
if test -z "$1"; then
echo "ERROR: command required" >&2
usage
exit 1
fi
WASI_SDK_PATH="${WASI_SDK_PATH:-/opt/wasi-sdk}"
if ! test -x "${WASI_SDK_PATH}/bin/clang"; then
echo "Error: ${WASI_SDK_PATH}/bin/clang does not exist." >&2
exit 2
fi
# --sysroot is required if WASI-SDK is not installed in /opt/wasi-sdk.
WASI_SYSROOT="${WASI_SDK_PATH}/share/wasi-sysroot"
CC="${WASI_SDK_PATH}/bin/clang --sysroot=${WASI_SYSROOT}"
CPP="${WASI_SDK_PATH}/bin/clang-cpp --sysroot=${WASI_SYSROOT}"
CXX="${WASI_SDK_PATH}/bin/clang++ --sysroot=${WASI_SYSROOT}"
# use ccache if available
if command -v ccache >/dev/null 2>&1; then
CC="ccache ${CC}"
CPP="ccache ${CPP}"
CXX="ccache ${CXX}"
fi
LDSHARED="${WASI_SDK_PATH}/bin/wasm-ld"
AR="${WASI_SDK_PATH}/bin/llvm-ar"
RANLIB="${WASI_SDK_PATH}/bin/ranlib"
# instruct pkg-config to use sysroot
PKG_CONFIG_PATH=""
PKG_CONFIG_LIBDIR="${WASI_SYSROOT}/lib/pkgconfig:${WASI_SYSROOT}/share/pkgconfig"
PKG_CONFIG_SYSROOT_DIR="${WASI_SYSROOT}"
PATH="${WASI_SDK_PATH}/bin:$PATH"
export WASI_SDK_PATH
export CC CPP CXX LDSHARED AR RANLIB
export PKG_CONFIG_PATH PKG_CONFIG_LIBDIR PKG_CONFIG_SYSROOT_DIR
export PATH
exec "$@"