Skip to content

Commit

Permalink
feature: allow to skip wasm-opt when invoked by clang
Browse files Browse the repository at this point in the history
By exporting the WASMLABS_SKIP_WASM_OPT envvar, the wasm-opt wrapper
present in the wasm-base container image will make the wasm-opt call a
no-op.

This is useful for cases when we don't desire wasm-opt to be called,
for example when invoked directly by
clang (llvm/llvm-project#55781).
  • Loading branch information
ereslibre committed Jan 17, 2023
1 parent aef3bf3 commit 72eca41
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 3 deletions.
13 changes: 10 additions & 3 deletions Dockerfile.wasm-base
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
FROM ubuntu:20.04
ARG BINARYEN_VERSION=111
ARG BINARYEN_VERSION
ENV BINARYEN_PATH=/opt
RUN apt update && \
DEBIAN_FRONTEND=noninteractive apt install -y \
wget && \
wget https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VERSION}/binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz && \
tar -xf binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz --strip-components=1 -C /opt && \
rm binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz
ENV PATH="$PATH:/opt/bin"
rm binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz && \
mkdir -p /opt/priority-bin
# wasm-opt is called in unexpected contexts
# (https://github.com/llvm/llvm-project/issues/55781). To avoid this,
# we install a `wasm-opt` wrapper with a higher priority in the PATH
# that can disable wasm-opt execution when desired.
ADD images/wasm-base/wasm-opt /opt/priority-bin/
ENV PATH="/opt/priority-bin:$PATH:/opt/bin"
42 changes: 42 additions & 0 deletions images/wasm-base/wasm-opt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!//usr/bin/env bash
# Inspired by https://raw.githubusercontent.com/ruby/ruby/df6b72b8ff7af16a56fa48f3b4abb1d8850f4d1c/wasm/wasm-opt
#
# A fake wasm-opt, which does nothing at all
# See also: tool/wasm-clangw

if [[ -z "${WASMLABS_SKIP_WASM_OPT}" ]]; then
exec $BINARYEN_PATH/bin/wasm-opt "$@"
fi

set -e
input=
output=
while [ $# -ne 0 ]; do
case "$1" in
-o)
shift
output=$1
;;
-*)
# ignore other options
;;
*)
input=$1
;;
esac
shift
done

if [ -z "$input" ]; then
echo "missing input binary"
exit 1
fi

if [ -z "$output" ]; then
echo "missing output binary"
exit 1
fi

if [ "$input" != "$output" ]; then
cp "$input" "$output"
fi
9 changes: 9 additions & 0 deletions php/php-7.3.33/wl-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,16 @@ logStatus "Configuring build with '${PHP_CONFIGURE}'... "
./configure --host=wasm32-wasi host_alias=wasm32-musl-wasi --target=wasm32-wasi target_alias=wasm32-musl-wasi ${PHP_CONFIGURE} || exit 1

logStatus "Building php-cgi... "
# By exporting WASMLABS_SKIP_WASM_OPT envvar during the build, the
# wasm-opt wrapper in the wasm-base image will be a dummy wrapper that
# is effectively a NOP.
#
# This is due to https://github.com/llvm/llvm-project/issues/55781, so
# that we get to choose which optimization passes are executed after
# the artifacts have been built.
export WASMLABS_SKIP_WASM_OPT=1
make cgi || exit 1
unset WASMLABS_SKIP_WASM_OPT

logStatus "Preparing artifacts... "
mkdir -p ${WASMLABS_OUTPUT}/bin 2>/dev/null || exit 1
Expand Down
9 changes: 9 additions & 0 deletions php/php-7.4.32/wl-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,16 @@ then
fi

logStatus "Building '${MAKE_TARGETS}'... "
# By exporting WASMLABS_SKIP_WASM_OPT envvar during the build, the
# wasm-opt wrapper in the wasm-base image will be a dummy wrapper that
# is effectively a NOP.
#
# This is due to https://github.com/llvm/llvm-project/issues/55781, so
# that we get to choose which optimization passes are executed after
# the artifacts have been built.
export WASMLABS_SKIP_WASM_OPT=1
make -j ${MAKE_TARGETS} || exit 1
unset WASMLABS_SKIP_WASM_OPT

logStatus "Preparing artifacts... "
mkdir -p ${WASMLABS_OUTPUT}/bin 2>/dev/null || exit 1
Expand Down
9 changes: 9 additions & 0 deletions php/php-8.1.11/wl-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,16 @@ logStatus "Configuring build with '${PHP_CONFIGURE}'... "
./configure --host=wasm32-wasi host_alias=wasm32-musl-wasi --target=wasm32-wasi target_alias=wasm32-musl-wasi ${PHP_CONFIGURE} || exit 1

logStatus "Building php-cgi... "
# By exporting WASMLABS_SKIP_WASM_OPT envvar during the build, the
# wasm-opt wrapper in the wasm-base image will be a dummy wrapper that
# is effectively a NOP.
#
# This is due to https://github.com/llvm/llvm-project/issues/55781, so
# that we get to choose which optimization passes are executed after
# the artifacts have been built.
export WASMLABS_SKIP_WASM_OPT=1
make cgi || exit 1
unset WASMLABS_SKIP_WASM_OPT

logStatus "Preparing artifacts... "
mkdir -p ${WASMLABS_OUTPUT}/bin 2>/dev/null || exit 1
Expand Down
9 changes: 9 additions & 0 deletions php/php-8.2.0/wl-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,16 @@ then
fi

logStatus "Building '${MAKE_TARGETS}'... "
# By exporting WASMLABS_SKIP_WASM_OPT envvar during the build, the
# wasm-opt wrapper in the wasm-base image will be a dummy wrapper that
# is effectively a NOP.
#
# This is due to https://github.com/llvm/llvm-project/issues/55781, so
# that we get to choose which optimization passes are executed after
# the artifacts have been built.
export WASMLABS_SKIP_WASM_OPT=1
make -j ${MAKE_TARGETS} || exit 1
unset WASMLABS_SKIP_WASM_OPT

logStatus "Preparing artifacts... "
mkdir -p ${WASMLABS_OUTPUT}/bin 2>/dev/null || exit 1
Expand Down

0 comments on commit 72eca41

Please sign in to comment.