Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip wasm-opt in PHP builds #34

Merged
merged 2 commits into from
Jan 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Dockerfile.wasi-builder
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ARG WASM_BASE=20220116
ARG WASM_BASE
FROM ghcr.io/vmware-labs/wasm-base:${WASM_BASE}
ARG WASI_SDK_VERSION=19
ARG WASI_SDK_VERSION
ENV WASI_SDK=wasi-sdk-${WASI_SDK_VERSION}
ENV WASI_SDK_ROOT=/wasi-sdk
ENV WASI_SDK_PATH=${WASI_SDK_ROOT}
Expand Down
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"
6 changes: 4 additions & 2 deletions Makefile.builders
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
BUILDER_ROOT_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST))))

WASM_BASE_TAG ?= $(shell git rev-parse --short HEAD)

.PHONY: wasm-base
wasm-base:
docker build --build-arg BINARYEN_VERSION=111 -f ${BUILDER_ROOT_DIR}/Dockerfile.wasm-base -t ghcr.io/vmware-labs/wasm-base:20220116 ${BUILDER_ROOT_DIR}
docker build --build-arg BINARYEN_VERSION=111 -f ${BUILDER_ROOT_DIR}/Dockerfile.wasm-base -t ghcr.io/vmware-labs/wasm-base:$(WASM_BASE_TAG) ${BUILDER_ROOT_DIR}

.PHONY: wasi-builder-19
wasi-builder-19: wasm-base
docker build --build-arg WASI_SDK_VERSION=19 -f ${BUILDER_ROOT_DIR}/Dockerfile.wasi-builder -t ghcr.io/vmware-labs/wasi-builder:19 ${BUILDER_ROOT_DIR}
docker build --build-arg WASM_BASE=$(WASM_BASE_TAG) --build-arg WASI_SDK_VERSION=19 -f ${BUILDER_ROOT_DIR}/Dockerfile.wasi-builder -t ghcr.io/vmware-labs/wasi-builder:19 ${BUILDER_ROOT_DIR}
54 changes: 54 additions & 0 deletions images/wasm-base/wasm-opt
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!//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

function logStatus {
if [[ -n "${WASMLABS_OUTPUT}" ]]; then
echo "$(date --iso-8601=ns) | $@" >> $WASMLABS_OUTPUT/wasmlabs-progress.log
else
echo "$(date --iso-8601=ns) | $@"
fi
}

if [[ -z "${WASMLABS_SKIP_WASM_OPT}" ]]; then
logStatus "wasm-opt (with args \"$@\") was intercepted; executing $BINARYEN_PATH/bin/wasm-opt"
exec $BINARYEN_PATH/bin/wasm-opt "$@"
fi

logStatus "wasm-opt (with args \"$@\") was intercepted; this invocation will be a no-op"

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
2 changes: 1 addition & 1 deletion php/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG WASI_SDK_VERSION=19
ARG WASI_SDK_VERSION
FROM ghcr.io/vmware-labs/wasi-builder:${WASI_SDK_VERSION}
RUN DEBIAN_FRONTEND=noninteractive apt install -y \
bison \
Expand Down
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
2 changes: 1 addition & 1 deletion ruby/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG WASI_SDK_VERSION=19
ARG WASI_SDK_VERSION
FROM ghcr.io/vmware-labs/wasi-builder:${WASI_SDK_VERSION}
RUN DEBIAN_FRONTEND=noninteractive apt install -y \
ruby \
Expand Down