2022-07-26 11:12:42 +02:00
|
|
|
#!/bin/sh
|
|
|
|
set -e
|
|
|
|
|
2024-09-26 23:23:41 +02:00
|
|
|
# NOTE: to be removed once no longer used in https://github.com/python/buildmaster-config/blob/main/master/custom/factories.py .
|
|
|
|
|
2022-07-26 11:12:42 +02:00
|
|
|
# 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 15:30:36 +02:00
|
|
|
WASI_SYSROOT="${WASI_SDK_PATH}/share/wasi-sysroot"
|
2022-07-26 11:12:42 +02: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 15:30:36 +02:00
|
|
|
CC="${WASI_SDK_PATH}/bin/clang"
|
|
|
|
CPP="${WASI_SDK_PATH}/bin/clang-cpp"
|
|
|
|
CXX="${WASI_SDK_PATH}/bin/clang++"
|
|
|
|
|
2022-07-26 11:12:42 +02:00
|
|
|
# --sysroot is required if WASI-SDK is not installed in /opt/wasi-sdk.
|
2022-07-27 15:30:36 +02: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 11:12:42 +02: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 15:30:36 +02:00
|
|
|
PATH="${WASI_SDK_PATH}/bin:${PATH}"
|
2022-07-26 11:12:42 +02:00
|
|
|
|
2022-07-27 15:30:36 +02:00
|
|
|
export WASI_SDK_PATH WASI_SYSROOT
|
2022-07-26 11:12:42 +02:00
|
|
|
export CC CPP CXX LDSHARED AR RANLIB
|
2022-07-27 15:30:36 +02:00
|
|
|
export CFLAGS LDFLAGS
|
2022-07-26 11:12:42 +02:00
|
|
|
export PKG_CONFIG_PATH PKG_CONFIG_LIBDIR PKG_CONFIG_SYSROOT_DIR
|
|
|
|
export PATH
|
|
|
|
|
2024-05-28 09:53:32 +02:00
|
|
|
# no exec, it makes argv[0] path absolute.
|
2022-08-13 21:56:08 +02:00
|
|
|
"$@"
|