From 6f3a3aad496d2333aefa6ca011861c3f18eeb113 Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Sat, 1 Jan 2022 21:40:22 -0500 Subject: [PATCH] web-wasm,web-wasi: Add build tools - Binaryen - wabt - WASI runtimes: wasmtime, wasmer, wavm, wasm3 --- Makefile | 4 +- common/common.webassembly | 68 ++++++++++++++++++++++++ imagefiles/wasmer-pwd.sh | 4 ++ {web-wasi => imagefiles}/wasmtime-pwd.sh | 0 web-wasi/Dockerfile.in | 10 ++-- web-wasm/Dockerfile.in | 2 + 6 files changed, 80 insertions(+), 8 deletions(-) create mode 100644 common/common.webassembly create mode 100755 imagefiles/wasmer-pwd.sh rename {web-wasi => imagefiles}/wasmtime-pwd.sh (100%) diff --git a/Makefile b/Makefile index 310ad2c..0f29722 100644 --- a/Makefile +++ b/Makefile @@ -44,7 +44,8 @@ NON_STANDARD_IMAGES = manylinux2014-x64 manylinux2014-x86 \ # Docker composite files DOCKER_COMPOSITE_SOURCES = common.docker common.debian common.manylinux common.buildroot \ - common.crosstool common.windows common-manylinux.crosstool common.dockcross common.label-and-env + common.crosstool common.webassembly common.windows common-manylinux.crosstool common.dockcross \ + common.label-and-env DOCKER_COMPOSITE_FOLDER_PATH = common/ DOCKER_COMPOSITE_PATH = $(addprefix $(DOCKER_COMPOSITE_FOLDER_PATH),$(DOCKER_COMPOSITE_SOURCES)) @@ -98,6 +99,7 @@ $(GEN_IMAGE_DOCKERFILES) Dockerfile: %Dockerfile: %Dockerfile.in $(DOCKER_COMPOS -e '/common.crosstool/ r $(DOCKER_COMPOSITE_FOLDER_PATH)common.crosstool' \ -e '/common.buildroot/ r $(DOCKER_COMPOSITE_FOLDER_PATH)common.buildroot' \ -e '/common-manylinux.crosstool/ r $(DOCKER_COMPOSITE_FOLDER_PATH)common-manylinux.crosstool' \ + -e '/common.webassembly/ r $(DOCKER_COMPOSITE_FOLDER_PATH)common.webassembly' \ -e '/common.windows/ r $(DOCKER_COMPOSITE_FOLDER_PATH)common.windows' \ -e '/common.dockcross/ r $(DOCKER_COMPOSITE_FOLDER_PATH)common.dockcross' \ -e '/common.label-and-env/ r $(DOCKER_COMPOSITE_FOLDER_PATH)common.label-and-env' \ diff --git a/common/common.webassembly b/common/common.webassembly new file mode 100644 index 0000000..5ec11e3 --- /dev/null +++ b/common/common.webassembly @@ -0,0 +1,68 @@ +# common.webassembly +# +# Common WebAssembly tools. + +# main 2021-12-31 +ENV BINARYEN_GIT_TAG 6137b338c7fb37ba98b63c31225ec9cfda8cfa59 +RUN git clone https://github.com/WebAssembly/binaryen.git && \ + cd binaryen && \ + git checkout ${BINARYEN_GIT_TAG} && \ + cd ../ && \ + mkdir binaryen-build && \ + cd binaryen-build && \ + /usr/bin/cmake \ + -DCMAKE_C_COMPILER=/usr/bin/cc \ + -DCMAKE_CXX_COMPILER=/usr/bin/c++ \ + -G Ninja \ + -DCMAKE_INSTALL_PREFIX:PATH=/usr \ + -DCMAKE_TOOLCHAIN_FILE="" \ + ../binaryen && \ + ninja && \ + ninja install && \ + cd ../ && \ + rm -rf binaryen* + +# main 2021-12-31 +ENV WABT_GIT_TAG a4366956e877c404d328358b2c00320b476763c0 +RUN git clone --recurse-submodules https://github.com/WebAssembly/wabt.git && \ + cd wabt && \ + git checkout ${WABT_GIT_TAG} && \ + cd ../ && \ + mkdir wabt-build && \ + cd wabt-build && \ + /usr/bin/cmake \ + -DCMAKE_C_COMPILER=/usr/bin/cc \ + -DCMAKE_CXX_COMPILER=/usr/bin/c++ \ + -G Ninja \ + -DCMAKE_INSTALL_PREFIX:PATH=/usr \ + -DCMAKE_TOOLCHAIN_FILE="" \ + ../wabt && \ + ninja && \ + ninja install && \ + cd ../ && \ + rm -rf wabt* + +RUN mkdir /wasi-runtimes + +ENV WASMTIME_HOME /wasi-runtimes/wasmtime +RUN mkdir ${WASMTIME_HOME} && curl https://wasmtime.dev/install.sh -sSf | bash +COPY imagefiles/wasmtime-pwd.sh ${WASMTIME_HOME}/bin/ +ENV PATH "$WASMTIME_HOME/bin:$PATH" + +ENV WASMER_DIR /wasi-runtimes/wasmer +RUN curl https://get.wasmer.io -sSfL | sh +COPY imagefiles/wasmer-pwd.sh ${WASMER_DIR}/bin/ +ENV PATH "$WASMER_DIR/bin:$PATH" + +ENV WASM3_VERSION 0.5.0 +RUN mkdir -p /wasi-runtimes/wasm3/bin && \ + curl -LO https://github.com/wasm3/wasm3/releases/download/v${WASM3_VERSION}/wasm3-linux-x64.elf && \ + mv wasm3-linux-x64.elf /wasi-runtimes/wasm3/bin/wasm3 && \ + chmod +x /wasi-runtimes/wasm3/bin/wasm3 +ENV PATH "/wasi-runtimes/wasm3/bin:$PATH" + +ENV WAVM_VERSION 2021-12-15 +RUN mkdir -p /wasi-runtimes/wavm/ && \ + curl -LO https://github.com/WAVM/WAVM/releases/download/nightly%2F${WAVM_VERSION}/wavm-0.0.0-prerelease-linux.tar.gz && \ + tar -xv -C /wasi-runtimes/wavm/ -f wavm-0.0.0-prerelease-linux.tar.gz +ENV PATH "/wasi-runtimes/wavm/bin:$PATH" \ No newline at end of file diff --git a/imagefiles/wasmer-pwd.sh b/imagefiles/wasmer-pwd.sh new file mode 100755 index 0000000..e2baa28 --- /dev/null +++ b/imagefiles/wasmer-pwd.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +# Mount the PWD to enable access in try_run commands +exec ${WASMER_DIR}/bin/wasmer run --dir=. --dir=$PWD "$@" diff --git a/web-wasi/wasmtime-pwd.sh b/imagefiles/wasmtime-pwd.sh similarity index 100% rename from web-wasi/wasmtime-pwd.sh rename to imagefiles/wasmtime-pwd.sh diff --git a/web-wasi/Dockerfile.in b/web-wasi/Dockerfile.in index 9b5ec67..929a3be 100644 --- a/web-wasi/Dockerfile.in +++ b/web-wasi/Dockerfile.in @@ -2,12 +2,6 @@ FROM dockcross/base:latest LABEL maintainer="Matt McCormick matt.mccormick@kitware.com" -# The cross-compiling emulator -ENV WASMTIME_HOME /usr/local/wasmtime -RUN mkdir ${WASMTIME_HOME} && curl https://wasmtime.dev/install.sh -sSf | bash -COPY wasmtime-pwd.sh ${WASMTIME_HOME}/bin/ -ENV PATH "$WASMTIME_HOME/bin:$PATH" - ENV WASI_VERSION 14 ENV WASI_VERSION_FULL ${WASI_VERSION}.0 RUN cd /usr/ && \ @@ -17,7 +11,7 @@ RUN cd /usr/ && \ ENV WASI_SDK_PATH /usr/wasi-sdk-${WASI_VERSION_FULL} ENV WASI_SYSROOT ${WASI_SDK_PATH}/share/wasi-sysroot -COPY clang-wasi-sysroot.sh clang++-wasi-sysroot.sh wasmtime-pwd.sh /usr/local/bin/ +COPY clang-wasi-sysroot.sh clang++-wasi-sysroot.sh /usr/local/bin/ ENV CROSS_TRIPLE=wasm32-wasi ENV CROSS_ROOT=${WASI_SDK_PATH} @@ -27,6 +21,8 @@ ENV AR=${CROSS_ROOT}/bin/llvm-ar \ CXX=clang++-wasi-sysroot.sh \ LD=${CROSS_ROOT}/bin/wasm-ld +#include "common.webassembly" + COPY WASI.cmake /usr/src/ RUN mv /usr/src/WASI.cmake /usr/share/cmake-*/Modules/Platform/ COPY Toolchain.cmake ${CROSS_ROOT}/ diff --git a/web-wasm/Dockerfile.in b/web-wasm/Dockerfile.in index 0560e44..ada6112 100644 --- a/web-wasm/Dockerfile.in +++ b/web-wasm/Dockerfile.in @@ -54,6 +54,8 @@ RUN ln -s /usr/bin/python3 /usr/bin/python #include "common.docker" +#include "common.webassembly" + ENV EMSCRIPTEN_VERSION 3.0.0 ENV PATH /emsdk:/emsdk/upstream/bin/:/emsdk/upstream/emscripten:${PATH}