From d4e7c0aff286f5c5766bb68c781b0ab656507b2d Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Tue, 2 Apr 2024 13:32:34 -0400 Subject: [PATCH] web-wasi-threads: initial addition This is a different toolchain following how wasi-sdk defines the platform triple and how builds are configured -- everything should be built with the flags defined in the toolchain file. We build from web-wasi:latest, and that is built first. --- .github/workflows/main.yml | 19 +++++++++++++++++++ Makefile | 24 ++++++++++++++++++++++-- README.md | 7 +++++++ common/common.webassembly | 1 + imagefiles/wasmtime-pwd-threads.sh | 4 ++++ web-wasi-threads/Dockerfile.in | 11 +++++++++++ web-wasi-threads/Toolchain.cmake | 17 +++++++++++++++++ 7 files changed, 81 insertions(+), 2 deletions(-) create mode 100755 imagefiles/wasmtime-pwd-threads.sh create mode 100644 web-wasi-threads/Dockerfile.in create mode 100644 web-wasi-threads/Toolchain.cmake diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a24bcf1..05fb9c0 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1039,6 +1039,25 @@ jobs: cpython: "no", cpython_arg: "", } + - { + image: "web-wasi-threads", + stockfish: "no", + stockfish_arg: "", + ninja: "no", + ninja_arg: "", + openssl: "no", + openssl_arg: "linux-generic64 no-asm no-threads no-engine no-hw no-weak-ssl-ciphers no-dtls no-shared no-dso", + C: "no", + C_arg: "", + C-Plus-Plus: "no", + C-Plus-Plus_arg: "", + fmt: "no", + fmt_arg: "", + raylib: "no", + raylib_arg: "", + cpython: "no", + cpython_arg: "", + } # Bare metal images - { image: "bare-armv7emhf-nano_newlib", diff --git a/Makefile b/Makefile index 6c1a2d4..bfeda0b 100644 --- a/Makefile +++ b/Makefile @@ -37,7 +37,7 @@ GEN_IMAGES := android-arm android-arm64 \ manylinux_2_28-x64 \ manylinux2014-x64 manylinux2014-x86 \ manylinux2014-aarch64 linux-arm64-lts \ - web-wasm web-wasi linux-mips linux-mips-uclibc linux-mips-lts windows-arm64 windows-armv7 \ + web-wasm web-wasi web-wasi-threads linux-mips linux-mips-uclibc linux-mips-lts windows-arm64 windows-armv7 \ windows-static-x86 windows-static-x64 windows-static-x64-posix \ windows-shared-x86 windows-shared-x64 windows-shared-x64-posix \ linux-armv7 linux-armv7a linux-armv7l-musl linux-armv7-lts linux-armv7a-lts linux-x86_64-full \ @@ -50,7 +50,7 @@ GEN_IMAGE_DOCKERFILES = $(addsuffix /Dockerfile,$(GEN_IMAGES)) # These images are expected to have explicit rules for *both* build and testing NON_STANDARD_IMAGES := manylinux_2_28-x64 manylinux2014-x64 manylinux2014-x86 \ - manylinux2014-aarch64 web-wasm + manylinux2014-aarch64 web-wasm web-wasi-threads # Docker composite files DOCKER_COMPOSITE_SOURCES = common.docker common.debian common.manylinux2014 common.manylinux_2_28 common.buildroot \ @@ -143,6 +143,26 @@ web-wasm.test: web-wasm rm -rf web-wasm/test # +# web-wasi-threads +# +web-wasi-threads: web-wasi web-wasi-threads/Dockerfile + mkdir -p $@/imagefiles && cp -r imagefiles $@/ + cp -r test web-wasi-threads/ + $(DOCKER) $(BUILD_CMD) -t $(ORG)/web-wasi-threads:$(TAG) \ + -t $(ORG)/web-wasi-threads:latest \ + --build-arg IMAGE=$(ORG)/web-wasi-threads \ + --build-arg VERSION=$(TAG) \ + --build-arg VCS_REF=`git rev-parse --short HEAD` \ + --build-arg VCS_URL=`git config --get remote.origin.url` \ + --build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \ + web-wasi-threads + +web-wasi-threads.test: web-wasi-threads + $(DOCKER) run $(RM) $(ORG)/web-wasi-threads:latest > $(BIN)/dockcross-web-wasi-threads \ + && chmod +x $(BIN)/dockcross-web-wasi-threads + $(BIN)/dockcross-web-wasi-threads -i $(ORG)/web-wasi-threads:latest python3 test/run.py + rm -rf web-wasi-threads/test +# # manylinux2014-aarch64 # manylinux2014-aarch64: manylinux2014-aarch64/Dockerfile diff --git a/README.md b/README.md index 21c80af..326159c 100644 --- a/README.md +++ b/README.md @@ -122,6 +122,7 @@ The dockcross script will execute the given command-line inside the container, a | dockcross/linux-x64-tinycc | x86_64 | tinycc + GCC | Linux | | dockcross/web-wasm | Wasm | LLVM | Web (JS) | | dockcross/web-wasi | Wasm | LLVM | Web (Universal) | +| dockcross/web-wasi-threads | Wasm | LLVM | Web (Universal) | | dockcross/windows-shared-x86 | x86 | GCC | Windows | | dockcross/windows-shared-x64 | x86_64 | GCC | Windows | | dockcross/windows-shared-x64-posix | x86_64 | GCC | Windows | @@ -403,6 +404,12 @@ The [Emscripten](https://emscripten.org/) [WebAssembly](https://webassembly.org/ The [WebAssembly System Interface (WASI)](https://wasi.dev/) SDK LLVM/Clang/WASI Sysroot cross compiler. +### dockcross/web-wasi-threads + +![Docker Image Size (tag)](https://img.shields.io/docker/image-size/dockcross/web-wasi-threads/latest) ![Docker Pulls](https://img.shields.io/docker/pulls/dockcross/web-wasi-threads) + +The [WebAssembly System Interface (WASI)](https://wasi.dev/) SDK LLVM/Clang/WASI Sysroot cross compiler with the toolchain configured to enable the wasm threading proposal. + ### dockcross/windows-static-x64 ![Docker Image Size (tag)](https://img.shields.io/docker/image-size/dockcross/windows-static-x64/latest) ![Docker Pulls](https://img.shields.io/docker/pulls/dockcross/windows-static-x64) diff --git a/common/common.webassembly b/common/common.webassembly index 250456f..8151040 100644 --- a/common/common.webassembly +++ b/common/common.webassembly @@ -47,6 +47,7 @@ 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/ +COPY imagefiles/wasmtime-pwd-threads.sh ${WASMTIME_HOME}/bin/ ENV PATH "$WASMTIME_HOME/bin:$PATH" # For wasmer diff --git a/imagefiles/wasmtime-pwd-threads.sh b/imagefiles/wasmtime-pwd-threads.sh new file mode 100755 index 0000000..b9f8a98 --- /dev/null +++ b/imagefiles/wasmtime-pwd-threads.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +# Mount the PWD and the /work mount dir to enable access in try_run commands +exec ${WASMTIME_HOME}/bin/wasmtime -S threads=y run --dir=. --dir=$PWD --dir=/work/ "$@" diff --git a/web-wasi-threads/Dockerfile.in b/web-wasi-threads/Dockerfile.in new file mode 100644 index 0000000..9d821e9 --- /dev/null +++ b/web-wasi-threads/Dockerfile.in @@ -0,0 +1,11 @@ +ARG ORG=dockcross +FROM ${ORG}/web-wasi:latest + +LABEL maintainer="Matt McCormick matt.mccormick@kitware.com" + +ENV CROSS_TRIPLE=wasm32-wasi-threads + +COPY Toolchain.cmake ${CROSS_ROOT}/ +ENV CMAKE_TOOLCHAIN_FILE ${CROSS_ROOT}/Toolchain.cmake + +#include "common.label-and-env" diff --git a/web-wasi-threads/Toolchain.cmake b/web-wasi-threads/Toolchain.cmake new file mode 100644 index 0000000..f43dae5 --- /dev/null +++ b/web-wasi-threads/Toolchain.cmake @@ -0,0 +1,17 @@ +set(WASI_SDK_PREFIX $ENV{WASI_SDK_PATH}) +include($ENV{WASI_SDK_PATH}/share/cmake/wasi-sdk-pthread.cmake) + +set(CMAKE_FIND_ROOT_PATH $ENV{CROSS_ROOT}) +set(CMAKE_SYSROOT $ENV{WASI_SYSROOT}) + +set(CMAKE_C_COMPILER /usr/local/bin/clang-wasi-sysroot.sh) +set(CMAKE_CXX_COMPILER /usr/local/bin/clang++-wasi-sysroot.sh) +set(CMAKE_AR llvm-ar-$ENV{LLVM_VERSION}) +set(CMAKE_RANLIB llvm-ranlib-$ENV{LLVM_VERSION}) +set(CMAKE_ASM_COMPILER clang-$ENV{LLVM_VERSION}) + +set(CMAKE_C_COMPILER_TARGET $ENV{CROSS_TRIPLE}) +set(CMAKE_CXX_COMPILER_TARGET $ENV{CROSS_TRIPLE}) +set(CMAKE_ASM_COMPILER_TARGET $ENV{CROSS_TRIPLE}) + +set(CMAKE_CROSSCOMPILING_EMULATOR /wasi-runtimes/wasmtime/bin/wasmtime-pwd-threads.sh)