2022-07-26 06:12:42 -03:00
|
|
|
#!/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}"
|
2022-07-27 10:30:36 -03:00
|
|
|
WASI_SYSROOT="${WASI_SDK_PATH}/share/wasi-sysroot"
|
2022-07-26 06:12:42 -03:00
|
|
|
|
|
|
|
if ! test -x "${WASI_SDK_PATH}/bin/clang"; then
|
|
|
|
echo "Error: ${WASI_SDK_PATH}/bin/clang does not exist." >&2
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
|
2022-07-27 10:30:36 -03:00
|
|
|
CC="${WASI_SDK_PATH}/bin/clang"
|
|
|
|
CPP="${WASI_SDK_PATH}/bin/clang-cpp"
|
|
|
|
CXX="${WASI_SDK_PATH}/bin/clang++"
|
|
|
|
|
2022-07-26 06:12:42 -03:00
|
|
|
# --sysroot is required if WASI-SDK is not installed in /opt/wasi-sdk.
|
2022-07-27 10:30:36 -03:00
|
|
|
if test "${WASI_SDK_PATH}" != "/opt/wasi-sdk"; then
|
|
|
|
CC="${CC} --sysroot=${WASI_SYSROOT}"
|
|
|
|
CPP="${CPP} --sysroot=${WASI_SYSROOT}"
|
|
|
|
CXX="${CXX} --sysroot=${WASI_SYSROOT}"
|
|
|
|
fi
|
2022-07-26 06:12:42 -03:00
|
|
|
|
|
|
|
# use ccache if available
|
|
|
|
if command -v ccache >/dev/null 2>&1; then
|
|
|
|
CC="ccache ${CC}"
|
|
|
|
CPP="ccache ${CPP}"
|
|
|
|
CXX="ccache ${CXX}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
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}"
|
|
|
|
|
2022-07-27 10:30:36 -03:00
|
|
|
PATH="${WASI_SDK_PATH}/bin:${PATH}"
|
2022-07-26 06:12:42 -03:00
|
|
|
|
2022-07-27 10:30:36 -03:00
|
|
|
export WASI_SDK_PATH WASI_SYSROOT
|
2022-07-26 06:12:42 -03:00
|
|
|
export CC CPP CXX LDSHARED AR RANLIB
|
2022-07-27 10:30:36 -03:00
|
|
|
export CFLAGS LDFLAGS
|
2022-07-26 06:12:42 -03:00
|
|
|
export PKG_CONFIG_PATH PKG_CONFIG_LIBDIR PKG_CONFIG_SYSROOT_DIR
|
|
|
|
export PATH
|
|
|
|
|
2022-08-13 16:56:08 -03:00
|
|
|
# no exec, it makes arvg[0] path absolute.
|
|
|
|
"$@"
|