Skip to content

Commit 8aec06d

Browse files
authored
Merge pull request #34 from ereslibre/skip-wasm-opt
Skip wasm-opt in PHP builds
2 parents aef3bf3 + 844158d commit 8aec06d

File tree

10 files changed

+108
-9
lines changed

10 files changed

+108
-9
lines changed

Dockerfile.wasi-builder

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
ARG WASM_BASE=20220116
1+
ARG WASM_BASE
22
FROM ghcr.io/vmware-labs/wasm-base:${WASM_BASE}
3-
ARG WASI_SDK_VERSION=19
3+
ARG WASI_SDK_VERSION
44
ENV WASI_SDK=wasi-sdk-${WASI_SDK_VERSION}
55
ENV WASI_SDK_ROOT=/wasi-sdk
66
ENV WASI_SDK_PATH=${WASI_SDK_ROOT}

Dockerfile.wasm-base

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
FROM ubuntu:20.04
2-
ARG BINARYEN_VERSION=111
2+
ARG BINARYEN_VERSION
3+
ENV BINARYEN_PATH=/opt
34
RUN apt update && \
45
DEBIAN_FRONTEND=noninteractive apt install -y \
56
wget && \
67
wget https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VERSION}/binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz && \
78
tar -xf binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz --strip-components=1 -C /opt && \
8-
rm binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz
9-
ENV PATH="$PATH:/opt/bin"
9+
rm binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz && \
10+
mkdir -p /opt/priority-bin
11+
# wasm-opt is called in unexpected contexts
12+
# (https://github.com/llvm/llvm-project/issues/55781). To avoid this,
13+
# we install a `wasm-opt` wrapper with a higher priority in the PATH
14+
# that can disable wasm-opt execution when desired.
15+
ADD images/wasm-base/wasm-opt /opt/priority-bin/
16+
ENV PATH="/opt/priority-bin:$PATH:/opt/bin"

Makefile.builders

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
BUILDER_ROOT_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST))))
22

3+
WASM_BASE_TAG ?= $(shell git rev-parse --short HEAD)
4+
35
.PHONY: wasm-base
46
wasm-base:
5-
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}
7+
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}
68

79
.PHONY: wasi-builder-19
810
wasi-builder-19: wasm-base
9-
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}
11+
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}

images/wasm-base/wasm-opt

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!//usr/bin/env bash
2+
# Inspired by
3+
# https://raw.githubusercontent.com/ruby/ruby/df6b72b8ff7af16a56fa48f3b4abb1d8850f4d1c/wasm/wasm-opt
4+
#
5+
# A fake wasm-opt, which does nothing at all
6+
# See also: tool/wasm-clangw
7+
8+
function logStatus {
9+
if [[ -n "${WASMLABS_OUTPUT}" ]]; then
10+
echo "$(date --iso-8601=ns) | $@" >> $WASMLABS_OUTPUT/wasmlabs-progress.log
11+
else
12+
echo "$(date --iso-8601=ns) | $@"
13+
fi
14+
}
15+
16+
if [[ -z "${WASMLABS_SKIP_WASM_OPT}" ]]; then
17+
logStatus "wasm-opt (with args \"$@\") was intercepted; executing $BINARYEN_PATH/bin/wasm-opt"
18+
exec $BINARYEN_PATH/bin/wasm-opt "$@"
19+
fi
20+
21+
logStatus "wasm-opt (with args \"$@\") was intercepted; this invocation will be a no-op"
22+
23+
set -e
24+
input=
25+
output=
26+
while [ $# -ne 0 ]; do
27+
case "$1" in
28+
-o)
29+
shift
30+
output=$1
31+
;;
32+
-*)
33+
# ignore other options
34+
;;
35+
*)
36+
input=$1
37+
;;
38+
esac
39+
shift
40+
done
41+
42+
if [ -z "$input" ]; then
43+
echo "missing input binary"
44+
exit 1
45+
fi
46+
47+
if [ -z "$output" ]; then
48+
echo "missing output binary"
49+
exit 1
50+
fi
51+
52+
if [ "$input" != "$output" ]; then
53+
cp "$input" "$output"
54+
fi

php/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ARG WASI_SDK_VERSION=19
1+
ARG WASI_SDK_VERSION
22
FROM ghcr.io/vmware-labs/wasi-builder:${WASI_SDK_VERSION}
33
RUN DEBIAN_FRONTEND=noninteractive apt install -y \
44
bison \

php/php-7.3.33/wl-build.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,16 @@ logStatus "Configuring build with '${PHP_CONFIGURE}'... "
3131
./configure --host=wasm32-wasi host_alias=wasm32-musl-wasi --target=wasm32-wasi target_alias=wasm32-musl-wasi ${PHP_CONFIGURE} || exit 1
3232

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

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

php/php-7.4.32/wl-build.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,16 @@ then
4343
fi
4444

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

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

php/php-8.1.11/wl-build.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,16 @@ logStatus "Configuring build with '${PHP_CONFIGURE}'... "
3535
./configure --host=wasm32-wasi host_alias=wasm32-musl-wasi --target=wasm32-wasi target_alias=wasm32-musl-wasi ${PHP_CONFIGURE} || exit 1
3636

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

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

php/php-8.2.0/wl-build.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,16 @@ then
4646
fi
4747

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

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

ruby/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ARG WASI_SDK_VERSION=19
1+
ARG WASI_SDK_VERSION
22
FROM ghcr.io/vmware-labs/wasi-builder:${WASI_SDK_VERSION}
33
RUN DEBIAN_FRONTEND=noninteractive apt install -y \
44
ruby \

0 commit comments

Comments
 (0)