Skip to content

Commit 25086f1

Browse files
gh-95174: Move WASIX logic into wasi-env (GH-95320)
wasi-env now sets WASIX flags. This allows us to control all build parameter for wasm32-wasi buildbot from CPython repository. Also export and improve SYSROOT parameter. (cherry picked from commit 2833f37) Co-authored-by: Christian Heimes <[email protected]>
1 parent e14c4d5 commit 25086f1

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

Tools/wasm/README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,15 +234,14 @@ compatibility stubs.
234234

235235
The script ``wasi-env`` sets necessary compiler and linker flags as well as
236236
``pkg-config`` overrides. The script assumes that WASI-SDK is installed in
237-
``/opt/wasi-sdk`` or ``$WASI_SDK_PATH``.
237+
``/opt/wasi-sdk`` or ``$WASI_SDK_PATH`` and WASIX is installed in
238+
``/opt/wasix`` or ``$WASIX_PATH``.
238239

239240
```shell
240241
mkdir -p builddir/wasi
241242
pushd builddir/wasi
242243

243244
CONFIG_SITE=../../Tools/wasm/config.site-wasm32-wasi \
244-
CFLAGS="-isystem /opt/wasix/include" \
245-
LDFLAGS="-L/opt/wasix/lib -lwasix" \
246245
../../Tools/wasm/wasi-env ../../configure -C \
247246
--host=wasm32-unknown-wasi \
248247
--build=$(../../config.guess) \

Tools/wasm/wasi-env

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,24 @@ if test -z "$1"; then
3030
fi
3131

3232
WASI_SDK_PATH="${WASI_SDK_PATH:-/opt/wasi-sdk}"
33+
WASI_SYSROOT="${WASI_SDK_PATH}/share/wasi-sysroot"
34+
WASIX_PATH="${WASIX_PATH:-/opt/wasix}"
3335

3436
if ! test -x "${WASI_SDK_PATH}/bin/clang"; then
3537
echo "Error: ${WASI_SDK_PATH}/bin/clang does not exist." >&2
3638
exit 2
3739
fi
3840

41+
CC="${WASI_SDK_PATH}/bin/clang"
42+
CPP="${WASI_SDK_PATH}/bin/clang-cpp"
43+
CXX="${WASI_SDK_PATH}/bin/clang++"
44+
3945
# --sysroot is required if WASI-SDK is not installed in /opt/wasi-sdk.
40-
WASI_SYSROOT="${WASI_SDK_PATH}/share/wasi-sysroot"
41-
CC="${WASI_SDK_PATH}/bin/clang --sysroot=${WASI_SYSROOT}"
42-
CPP="${WASI_SDK_PATH}/bin/clang-cpp --sysroot=${WASI_SYSROOT}"
43-
CXX="${WASI_SDK_PATH}/bin/clang++ --sysroot=${WASI_SYSROOT}"
46+
if test "${WASI_SDK_PATH}" != "/opt/wasi-sdk"; then
47+
CC="${CC} --sysroot=${WASI_SYSROOT}"
48+
CPP="${CPP} --sysroot=${WASI_SYSROOT}"
49+
CXX="${CXX} --sysroot=${WASI_SYSROOT}"
50+
fi
4451

4552
# use ccache if available
4653
if command -v ccache >/dev/null 2>&1; then
@@ -58,10 +65,17 @@ PKG_CONFIG_PATH=""
5865
PKG_CONFIG_LIBDIR="${WASI_SYSROOT}/lib/pkgconfig:${WASI_SYSROOT}/share/pkgconfig"
5966
PKG_CONFIG_SYSROOT_DIR="${WASI_SYSROOT}"
6067

61-
PATH="${WASI_SDK_PATH}/bin:$PATH"
68+
# add WASIX (POSIX stubs for WASI) if WASIX is installed
69+
if test -f "${WASIX_PATH}/lib/libwasix.a"; then
70+
CFLAGS="${CFLAGS} -isystem ${WASIX_PATH}/include"
71+
LDFLAGS="${LDFLAGS} -L${WASIX_PATH}/lib -lwasix"
72+
fi
73+
74+
PATH="${WASI_SDK_PATH}/bin:${PATH}"
6275

63-
export WASI_SDK_PATH
76+
export WASI_SDK_PATH WASI_SYSROOT
6477
export CC CPP CXX LDSHARED AR RANLIB
78+
export CFLAGS LDFLAGS
6579
export PKG_CONFIG_PATH PKG_CONFIG_LIBDIR PKG_CONFIG_SYSROOT_DIR
6680
export PATH
6781

0 commit comments

Comments
 (0)