From 4847e6e7a4dfd0c4f4066bffd411e6bd523101f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Fern=C3=A1ndez=20L=C3=B3pez?= Date: Tue, 17 Jan 2023 14:54:44 +0100 Subject: [PATCH 1/2] feature: allow to skip wasm-opt when invoked by clang 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 (https://github.com/llvm/llvm-project/issues/55781). --- Dockerfile.wasm-base | 13 ++++++--- images/wasm-base/wasm-opt | 54 ++++++++++++++++++++++++++++++++++++++ php/php-7.3.33/wl-build.sh | 9 +++++++ php/php-7.4.32/wl-build.sh | 9 +++++++ php/php-8.1.11/wl-build.sh | 9 +++++++ php/php-8.2.0/wl-build.sh | 9 +++++++ 6 files changed, 100 insertions(+), 3 deletions(-) create mode 100755 images/wasm-base/wasm-opt diff --git a/Dockerfile.wasm-base b/Dockerfile.wasm-base index 1111944..8fd4e5f 100644 --- a/Dockerfile.wasm-base +++ b/Dockerfile.wasm-base @@ -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" diff --git a/images/wasm-base/wasm-opt b/images/wasm-base/wasm-opt new file mode 100755 index 0000000..9578b85 --- /dev/null +++ b/images/wasm-base/wasm-opt @@ -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 \ No newline at end of file diff --git a/php/php-7.3.33/wl-build.sh b/php/php-7.3.33/wl-build.sh index b6305a4..480a1c0 100644 --- a/php/php-7.3.33/wl-build.sh +++ b/php/php-7.3.33/wl-build.sh @@ -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 diff --git a/php/php-7.4.32/wl-build.sh b/php/php-7.4.32/wl-build.sh index 5700b6c..ae38ead 100644 --- a/php/php-7.4.32/wl-build.sh +++ b/php/php-7.4.32/wl-build.sh @@ -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 diff --git a/php/php-8.1.11/wl-build.sh b/php/php-8.1.11/wl-build.sh index 8eeb8b4..95dc523 100644 --- a/php/php-8.1.11/wl-build.sh +++ b/php/php-8.1.11/wl-build.sh @@ -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 diff --git a/php/php-8.2.0/wl-build.sh b/php/php-8.2.0/wl-build.sh index daab841..59e2e73 100644 --- a/php/php-8.2.0/wl-build.sh +++ b/php/php-8.2.0/wl-build.sh @@ -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 From 844158d294dbda0fca998acbe0d7697652068702 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Fern=C3=A1ndez=20L=C3=B3pez?= Date: Tue, 17 Jan 2023 14:59:45 +0100 Subject: [PATCH 2/2] chore: Remove repetition on Dockerfile arguments --- Dockerfile.wasi-builder | 4 ++-- Makefile.builders | 6 ++++-- php/Dockerfile | 2 +- ruby/Dockerfile | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Dockerfile.wasi-builder b/Dockerfile.wasi-builder index 184b7f2..8ffa2af 100644 --- a/Dockerfile.wasi-builder +++ b/Dockerfile.wasi-builder @@ -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} diff --git a/Makefile.builders b/Makefile.builders index cbfaca8..48e1b16 100644 --- a/Makefile.builders +++ b/Makefile.builders @@ -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} \ No newline at end of file + 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} \ No newline at end of file diff --git a/php/Dockerfile b/php/Dockerfile index 8972cd9..bc331dd 100644 --- a/php/Dockerfile +++ b/php/Dockerfile @@ -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 \ diff --git a/ruby/Dockerfile b/ruby/Dockerfile index 53c0243..84f89e5 100644 --- a/ruby/Dockerfile +++ b/ruby/Dockerfile @@ -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 \