diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index dea9750..5a2f5b8 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -9,6 +9,9 @@ on: - "*" workflow_dispatch: +env: + OCI_EXE: docker + jobs: base: name: base @@ -20,15 +23,7 @@ jobs: submodules: "recursive" fetch-depth: 1 - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - name: build - env: - BUILD_CMD: buildx build --platform linux/amd64,linux/arm64 run: make base - name: test @@ -46,25 +41,83 @@ jobs: path: ./cache retention-days: 3 + - name: Login to Docker Hub + if: github.ref == 'refs/heads/master' + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USER }} + password: ${{ secrets.DOCKER_PASS }} + - name: deploy if: github.ref == 'refs/heads/master' run: | - docker login -u ${{ secrets.DOCKER_USER }} -p ${{ secrets.DOCKER_PASS }} docker image push dockcross/base --all-tags - image: - name: ${{ matrix.arch_name.image }} - needs: base - runs-on: ubuntu-22.04 + base-multiarch: + name: base-multiarch + runs-on: ${{ matrix.os }} + strategy: + max-parallel: 5 + matrix: + os: [ubuntu-22.04, ubuntu-22.04-arm] + steps: + - name: checkout code + uses: actions/checkout@v4 + with: + submodules: "recursive" + fetch-depth: 1 + + - name: set host_arch + run: | + echo "HOST_ARCH=$(uname -m | sed -e 's/x86_64/amd64/' -e 's/aarch64/arm64/')" >> $GITHUB_ENV + + - name: build multiarch + run: | + make base-${{ env.HOST_ARCH }} + + - name: test multiarch + run: | + mkdir -p bin + make base-${{ env.HOST_ARCH }}.test + + - name: archive base + run: | + mkdir -p cache + docker export dockcross/base:latest-${{ env.HOST_ARCH }} | xz -e9 -T0 > ./cache/base-multiarch.tar.xz + + - name: save base + uses: actions/upload-artifact@v4 + with: + name: cache-${{ matrix.os }} + path: ./cache + retention-days: 3 + + - name: Login to Docker Hub + if: github.ref == 'refs/heads/master' + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USER }} + password: ${{ secrets.DOCKER_PASS }} + + - name: deploy + if: github.ref == 'refs/heads/master' + run: | + docker image push dockcross/base --all-tags + + images: + needs: [base, base-multiarch] + runs-on: ${{ matrix.os }} env: OCI_EXE: docker strategy: fail-fast: false matrix: + os: [ubuntu-22.04, ubuntu-22.04-arm] arch_name: # Android images - { image: "android-arm", + multiarch: "", stockfish: "yes", stockfish_arg: "ARCH=armv7 COMP=ndk", ninja: "no", @@ -86,6 +139,7 @@ jobs: } - { image: "android-arm64", + multiarch: "", stockfish: "yes", stockfish_arg: "ARCH=armv8 COMP=ndk", ninja: "no", @@ -107,6 +161,7 @@ jobs: } - { image: "android-x86", + multiarch: "", stockfish: "yes", stockfish_arg: "ARCH=x86-32 COMP=ndk", ninja: "no", @@ -128,6 +183,7 @@ jobs: } - { image: "android-x86_64", + multiarch: "", stockfish: "yes", stockfish_arg: "ARCH=x86-64 COMP=ndk", ninja: "no", @@ -147,14 +203,15 @@ jobs: cpython: "no", cpython_arg: "--host=x86_64-linux-android --target=x86_64-linux-android", } - # Linux arm64/armv8 images + # inux arm64/armv8 images - { image: "linux-arm64", + multiarch: "yes", stockfish: "yes", stockfish_arg: "ARCH=armv8", ninja: "yes", ninja_arg: "", - openssl: "yes", + openssl: "no", openssl_arg: "linux-aarch64", C: "yes", C_arg: "", @@ -171,6 +228,7 @@ jobs: } - { image: "linux-arm64-lts", + multiarch: "", stockfish: "yes", stockfish_arg: "ARCH=armv8", ninja: "yes", @@ -192,6 +250,7 @@ jobs: } - { image: "linux-arm64-musl", + multiarch: "", stockfish: "yes", stockfish_arg: "ARCH=armv8", ninja: "yes", @@ -213,6 +272,7 @@ jobs: } - { image: "linux-arm64-full", + multiarch: "", stockfish: "yes", stockfish_arg: "ARCH=armv8", ninja: "yes", @@ -235,6 +295,7 @@ jobs: # Linux mipel images - { image: "linux-mipsel-lts", + multiarch: "", stockfish: "no", stockfish_arg: "", ninja: "no", @@ -257,6 +318,7 @@ jobs: # Linux armv5 images - { image: "linux-armv5", + multiarch: "", stockfish: "no", stockfish_arg: "", ninja: "yes", @@ -278,6 +340,7 @@ jobs: } - { image: "linux-armv5-musl", + multiarch: "", stockfish: "no", stockfish_arg: "", ninja: "yes", @@ -299,6 +362,7 @@ jobs: } - { image: "linux-armv5-uclibc", + multiarch: "", stockfish: "no", stockfish_arg: "", ninja: "yes", @@ -321,6 +385,7 @@ jobs: # Linux armv6 images - { image: "linux-armv6", + multiarch: "", stockfish: "no", stockfish_arg: "", ninja: "yes", @@ -342,6 +407,7 @@ jobs: } - { image: "linux-armv6-lts", + multiarch: "", stockfish: "no", stockfish_arg: "", ninja: "yes", @@ -363,6 +429,7 @@ jobs: } - { image: "linux-armv6-musl", + multiarch: "", stockfish: "no", stockfish_arg: "", ninja: "yes", @@ -385,6 +452,7 @@ jobs: # Linux armv7 images - { image: "linux-armv7", + multiarch: "", stockfish: "yes", stockfish_arg: "ARCH=armv7", ninja: "yes", @@ -406,6 +474,7 @@ jobs: } - { image: "linux-armv7a", + multiarch: "", stockfish: "yes", stockfish_arg: "ARCH=armv7-neon", ninja: "yes", @@ -427,6 +496,7 @@ jobs: } - { image: "linux-armv7a-lts", + multiarch: "", stockfish: "yes", stockfish_arg: "ARCH=armv7-neon", ninja: "yes", @@ -448,6 +518,7 @@ jobs: } - { image: "linux-armv7-lts", + multiarch: "", stockfish: "yes", stockfish_arg: "ARCH=armv7", ninja: "yes", @@ -469,6 +540,7 @@ jobs: } - { image: "linux-armv7l-musl", + multiarch: "", stockfish: "yes", stockfish_arg: "ARCH=armv7", ninja: "yes", @@ -491,6 +563,7 @@ jobs: # Linux x86 images - { image: "linux-x86", + multiarch: "", stockfish: "yes", stockfish_arg: "ARCH=x86-32-sse41-popcnt", ninja: "yes", @@ -513,6 +586,7 @@ jobs: # Linux i686 images - { image: "linux-i686", + multiarch: "", stockfish: "no", stockfish_arg: "", ninja: "yes", @@ -535,6 +609,7 @@ jobs: # Linux x86_64 images - { image: "linux-x64", + multiarch: "", stockfish: "yes", stockfish_arg: "ARCH=x86-64-modern", ninja: "yes", @@ -556,6 +631,7 @@ jobs: } - { image: "linux-x64-tinycc", + multiarch: "", stockfish: "yes", stockfish_arg: "ARCH=x86-64-modern", ninja: "yes", @@ -577,6 +653,7 @@ jobs: } - { image: "linux-x64-clang", + multiarch: "", stockfish: "yes", stockfish_arg: "ARCH=x86-64-modern COMP=clang", ninja: "yes", @@ -598,6 +675,7 @@ jobs: } - { image: "linux-x86_64-full", + multiarch: "", stockfish: "yes", stockfish_arg: "ARCH=x86-64-modern", ninja: "yes", @@ -620,6 +698,7 @@ jobs: # Linux riscv images - { image: "linux-riscv32", + multiarch: "", stockfish: "no", stockfish_arg: "", ninja: "yes", @@ -641,6 +720,7 @@ jobs: } - { image: "linux-riscv64", + multiarch: "", stockfish: "no", stockfish_arg: "", ninja: "yes", @@ -663,6 +743,7 @@ jobs: # Linux s390x images - { image: "linux-s390x", + multiarch: "", stockfish: "no", stockfish_arg: "", ninja: "yes", @@ -682,9 +763,10 @@ jobs: cpython: "yes", cpython_arg: "--host=s390x-ibm-linux-gnu --target=s390x-ibm-linux-gnu", } - # Linux mips images + # Linux mips images - { image: "linux-mips", + multiarch: "", stockfish: "no", stockfish_arg: "", ninja: "yes", @@ -706,6 +788,7 @@ jobs: } - { image: "linux-mips-uclibc", + multiarch: "", stockfish: "no", stockfish_arg: "", ninja: "yes", @@ -728,6 +811,7 @@ jobs: # Linux mips images - { image: "linux-mips-lts", + multiarch: "", stockfish: "no", stockfish_arg: "", ninja: "yes", @@ -772,6 +856,7 @@ jobs: # Linux ppc64le images - { image: "linux-ppc64le", + multiarch: "", stockfish: "yes", stockfish_arg: "ARCH=ppc-64", ninja: "yes", @@ -794,6 +879,7 @@ jobs: # Linux ppc64le-lts images - { image: "linux-ppc64le-lts", + multiarch: "", stockfish: "yes", stockfish_arg: "ARCH=ppc-64", ninja: "yes", @@ -816,6 +902,7 @@ jobs: # Linux m68k images - { image: "linux-m68k-uclibc", + multiarch: "", stockfish: "no", stockfish_arg: "", ninja: "no", @@ -838,6 +925,7 @@ jobs: # Linux xtensa images - { image: "linux-xtensa-uclibc", + multiarch: "", stockfish: "no", stockfish_arg: "", ninja: "yes", @@ -860,6 +948,7 @@ jobs: # Windows x86_x64 images - { image: "windows-static-x64", + multiarch: "", stockfish: "yes", stockfish_arg: "ARCH=x86-64-modern COMP=mingw", ninja: "no", @@ -881,6 +970,7 @@ jobs: } - { image: "windows-static-x64-posix", + multiarch: "", stockfish: "yes", stockfish_arg: "ARCH=x86-64-modern COMP=mingw", ninja: "no", @@ -902,6 +992,7 @@ jobs: } - { image: "windows-shared-x64", + multiarch: "", stockfish: "no", stockfish_arg: "", ninja: "no", @@ -923,6 +1014,7 @@ jobs: } - { image: "windows-shared-x64-posix", + multiarch: "", stockfish: "no", stockfish_arg: "", ninja: "no", @@ -945,6 +1037,7 @@ jobs: # Windows x86 images - { image: "windows-static-x86", + multiarch: "", stockfish: "yes", stockfish_arg: "ARCH=x86-32-sse41-popcnt COMP=mingw", ninja: "no", @@ -966,6 +1059,7 @@ jobs: } - { image: "windows-shared-x86", + multiarch: "", stockfish: "no", stockfish_arg: "", ninja: "no", @@ -988,6 +1082,7 @@ jobs: # Windows arm images - { image: "windows-armv7", + multiarch: "", stockfish: "no", stockfish_arg: "ARCH=armv7-neon COMP=clang", ninja: "yes", @@ -1009,6 +1104,7 @@ jobs: } - { image: "windows-arm64", + multiarch: "", stockfish: "no", stockfish_arg: "ARCH=armv8 COMP=clang", ninja: "yes", @@ -1031,6 +1127,7 @@ jobs: # manylinux_2_28 images - { image: "manylinux_2_28-x64", + multiarch: "", stockfish: "yes", stockfish_arg: "ARCH=x86-64-modern", ninja: "yes", @@ -1053,6 +1150,7 @@ jobs: # manylinux2014 images - { image: "manylinux2014-x86", + multiarch: "", stockfish: "yes", stockfish_arg: "ARCH=x86-32-sse41-popcnt", ninja: "yes", @@ -1074,6 +1172,7 @@ jobs: } - { image: "manylinux2014-x64", + multiarch: "", stockfish: "yes", stockfish_arg: "ARCH=x86-64-modern", ninja: "yes", @@ -1095,6 +1194,7 @@ jobs: } - { image: "manylinux2014-aarch64", + multiarch: "", stockfish: "no", stockfish_arg: "", ninja: "no", @@ -1117,6 +1217,7 @@ jobs: # web-wasm images - { image: "web-wasm", + multiarch: "yes", stockfish: "no", stockfish_arg: "", ninja: "no", @@ -1138,6 +1239,7 @@ jobs: } - { image: "web-wasi", + multiarch: "yes", stockfish: "no", stockfish_arg: "", ninja: "no", @@ -1159,6 +1261,7 @@ jobs: } - { image: "web-wasi-threads", + multiarch: "yes", stockfish: "no", stockfish_arg: "", ninja: "no", @@ -1181,6 +1284,7 @@ jobs: # Bare metal images - { image: "bare-armv7emhf-nano_newlib", + multiarch: "", stockfish: "no", stockfish_arg: "", ninja: "no", @@ -1211,6 +1315,13 @@ jobs: submodules: "recursive" fetch-depth: 1 + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: set host_arch + run: | + echo "HOST_ARCH=$(uname -m | sed -e 's/x86_64/amd64/' -e 's/aarch64/arm64/')" >> $GITHUB_ENV + - uses: actions/download-artifact@v4 with: name: cache @@ -1219,17 +1330,33 @@ jobs: - name: load base run: xz -d -k < ./cache/base.tar.xz | docker import - dockcross/base:latest + - uses: actions/download-artifact@v4 + with: + name: cache-${{ matrix.os }} + path: ./cache + + - name: load multiarch base + run: xz -d -k < ./cache/base-multiarch.tar.xz | docker import - dockcross/base:latest-${{ env.HOST_ARCH }} + - name: build env: BUILD_CMD: build --cache-from type=gha --cache-to type=gha,mode=max - run: make ${{ matrix.arch_name.image }} + run: | + if test "${{ matrix.arch_name.multiarch }}" = "yes"; then + make ${{ matrix.arch_name.image }} + elif test "${{ env.HOST_ARCH }}" = "amd64"; then + make ${{ matrix.arch_name.image }} + fi - name: basic test - run: make ${{ matrix.arch_name.image }}.test + run: | + if test "${{ matrix.arch_name.multiarch }}" = "yes" || test "${{ env.HOST_ARCH }}" = "amd64"; then + make ${{ matrix.arch_name.image }}.test + fi # Updated on 19/05/2022 - name: stockfish build test - if: ${{ matrix.arch_name.stockfish == 'yes' }} + if: ${{ matrix.arch_name.stockfish == 'yes' && (matrix.arch_name.multiarch == 'yes' || env.HOST_ARCH == 'amd64') }} run: | git clone --depth 1 --branch sf_15 https://github.com/official-stockfish/Stockfish.git cd Stockfish/src @@ -1240,7 +1367,7 @@ jobs: # Updated on 12/09/2022 - name: ninja build test - if: ${{ matrix.arch_name.ninja == 'yes' }} + if: ${{ matrix.arch_name.ninja == 'yes' && (matrix.arch_name.multiarch == 'yes' || env.HOST_ARCH == 'amd64') }} run: | git clone --depth 1 --branch v1.11.1 https://github.com/ninja-build/ninja.git cd ninja @@ -1248,7 +1375,7 @@ jobs: # Updated on 12/09/2022 - name: openssl build test - if: ${{ matrix.arch_name.openssl == 'yes' }} + if: ${{ matrix.arch_name.openssl == 'yes' && (matrix.arch_name.multiarch == 'yes' || env.HOST_ARCH == 'amd64') }} run: | git clone --depth 1 --branch OpenSSL_1_1_1q https://github.com/openssl/openssl.git cd openssl @@ -1261,7 +1388,7 @@ jobs: # Updated on 12/09/2022 - name: C build test - if: ${{ matrix.arch_name.C == 'yes' }} + if: ${{ matrix.arch_name.C == 'yes' && (matrix.arch_name.multiarch == 'yes' || env.HOST_ARCH == 'amd64') }} run: | git clone https://github.com/TheAlgorithms/C.git cd C @@ -1272,7 +1399,7 @@ jobs: # Updated on 12/09/2022 No longer maintained - name: C-Plus-Plus build test - if: ${{ matrix.arch_name.C-Plus-Plus == 'yes' }} + if: ${{ matrix.arch_name.C-Plus-Plus == 'yes' && (matrix.arch_name.multiarch == 'yes' || env.HOST_ARCH == 'amd64') }} run: | git clone https://github.com/TheAlgorithms/C-Plus-Plus.git cd C-Plus-Plus @@ -1283,7 +1410,7 @@ jobs: # Updated on 03/08/2024 - name: llama.cpp build test - if: ${{ matrix.arch_name.llama_cpp == 'yes' }} + if: ${{ matrix.arch_name.llama_cpp == 'yes' && (matrix.arch_name.multiarch == 'yes' || env.HOST_ARCH == 'amd64') }} run: | git clone https://github.com/ggerganov/llama.cpp.git cd llama.cpp @@ -1294,7 +1421,7 @@ jobs: # Updated on 12/09/2022 - name: fmt build test - if: ${{ matrix.arch_name.fmt == 'yes' }} + if: ${{ matrix.arch_name.fmt == 'yes' && (matrix.arch_name.multiarch == 'yes' || env.HOST_ARCH == 'amd64') }} run: | git clone --depth 1 --branch 9.1.0 https://github.com/fmtlib/fmt.git cd fmt @@ -1304,7 +1431,7 @@ jobs: # Updated on 19/05/2022 - name: cpython build test - if: ${{ matrix.arch_name.cpython == 'yes' }} + if: ${{ matrix.arch_name.cpython == 'yes' && (matrix.arch_name.multiarch == 'yes' || env.HOST_ARCH == 'amd64') }} run: | git clone --depth 1 --branch v3.11.2 https://github.com/python/cpython.git cd cpython @@ -1315,7 +1442,7 @@ jobs: # Updated on 12/09/2022 (4.2.0 branch not working) - name: raylib build test - if: ${{ matrix.arch_name.raylib == 'yes' }} + if: ${{ matrix.arch_name.raylib == 'yes' && (matrix.arch_name.multiarch == 'yes' || env.HOST_ARCH == 'amd64') }} run: | git clone https://github.com/raysan5/raylib.git cd raylib @@ -1326,7 +1453,7 @@ jobs: # Updated on 31/3/2022 - name: mbedtls build test - if: ${{ matrix.arch_name.mbedtls == 'yes' }} + if: ${{ matrix.arch_name.mbedtls == 'yes' && (matrix.arch_name.multiarch == 'yes' || env.HOST_ARCH == 'amd64') }} run: | git clone --depth 1 --branch archive/baremetal https://github.com/Mbed-TLS/mbedtls.git cd mbedtls @@ -1337,7 +1464,7 @@ jobs: # Updated on 20/6/2022 - name: libopencm3 build test - if: ${{ matrix.arch_name.libopencm3 == 'yes' }} + if: ${{ matrix.arch_name.libopencm3 == 'yes' && (matrix.arch_name.multiarch == 'yes' || env.HOST_ARCH == 'amd64') }} run: | git clone https://github.com/libopencm3/libopencm3.git cd libopencm3 @@ -1352,8 +1479,79 @@ jobs: cd .. rm -rf libopencm3 - - name: deploy + - name: archive ${{ matrix.arch_name.image }}-${{ env.HOST_ARCH }} + if: matrix.arch_name.multiarch == 'yes' + run: | + mkdir -p cache-${{ matrix.arch_name.image }}-${{ env.HOST_ARCH }} + docker export dockcross/${{ matrix.arch_name.image }}:latest-${{ env.HOST_ARCH }} | xz -e9 -T0 > ./cache/${{ matrix.arch_name.image }}-${{ env.HOST_ARCH }}.tar.xz + + - name: save ${{ matrix.arch_name.image }}-${{ matrix.os }} + uses: actions/upload-artifact@v4 + if: matrix.arch_name.multiarch == 'yes' + with: + name: cache-${{ matrix.arch_name.image }}-${{ env.HOST_ARCH }} + path: ./cache/${{ matrix.arch_name.image }}-${{ env.HOST_ARCH }}.tar.xz + retention-days: 3 + + - name: Login to Docker Hub + if: github.ref == 'refs/heads/master' && matrix.arch_name.multiarch != 'yes' && env.HOST_ARCH == 'amd64' + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USER }} + password: ${{ secrets.DOCKER_PASS }} + + - name: deploy-not-multi-arch + if: github.ref == 'refs/heads/master' && matrix.arch_name.multiarch != 'yes' && env.HOST_ARCH == 'amd64' + run: | + make ${{ matrix.arch_name.image }}.push + + deploy-multi-arch-images: + needs: + - images + runs-on: ubuntu-22.04 + strategy: + fail-fast: false + matrix: + image_name: ["linux-arm64", "web-wasm", "web-wasi", "web-wasi-threads"] + steps: + - name: checkout code + uses: actions/checkout@v4 + with: + submodules: "recursive" + fetch-depth: 1 + + - name: download ${{ matrix.image_name }}-amd64 + uses: actions/download-artifact@v4 + with: + name: cache-${{ matrix.image_name }}-amd64 + path: ./cache/${{ matrix.image_name }}-amd64.tar.xz + + - name: download ${{ matrix.image_name }}-arm64 + uses: actions/download-artifact@v4 + with: + name: cache-${{ matrix.image_name }}-arm64 + path: ./cache/${{ matrix.image_name }}-arm64.tar.xz + + - name: load images + run: | + xz -d -k < ./cache/${{ matrix.image_name }}-amd64.tar.xz | docker import - dockcross/${{ matrix.image_name }}-amd64 + xz -d -k < ./cache/${{ matrix.image_name }}-arm64.tar.xz | docker import - dockcross/${{ matrix.image_name }}-arm64 + + - name: Login to Docker Hub + if: github.ref == 'refs/heads/master' + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USER }} + password: ${{ secrets.DOCKER_PASS }} + + - name: deploy-multi-arch if: github.ref == 'refs/heads/master' run: | - docker login -u ${{ secrets.DOCKER_USER }} -p ${{ secrets.DOCKER_PASS }} - docker image push dockcross/${{ matrix.arch_name.image }} --all-tags + + make ${{ matrix.image_name }}.tag-amd64 + make ${{ matrix.image_name }}.tag-arm64 + + make ${{ matrix.image_name }}.push-amd64 + make ${{ matrix.image_name }}.push-arm64 + + make ${{ matrix.image_name }}.push diff --git a/Makefile b/Makefile index 020942a..048dd45 100644 --- a/Makefile +++ b/Makefile @@ -3,8 +3,20 @@ # Parameters # -# Name of the docker executable +# Name of the docker-equivalent executable for building images. +# OCI: open container interface. +# Common values: docker, podman, buildah DOCKER := $(or $(OCI_EXE), docker) +BUILD_DOCKER := $(or $(BUILD_DOCKER), $(DOCKER)) +BUILDAH := $(or $(BUILDAH_EXE), buildah) +# Name of the docker-equivalent executable for running test containers. +# Supports the use case: +# +# DOCKER=buildah +# TEST_DOCKER=podman +# +# because buildah does not run containers. +TEST_DOCKER := $(or $(TEST_DOCKER), $(DOCKER)) # The build sub-command. Use: # @@ -12,21 +24,24 @@ DOCKER := $(or $(OCI_EXE), docker) # # to generate multi-platform images. BUILD_CMD := $(or $(BUILD_CMD), build) +TAG_FLAG := $(or $(TAG_FLAG), --tag) # Docker organization to pull the images from ORG = dockcross +# Host architecture +HOST_ARCH := $(shell uname -m | sed -e 's/x86_64/amd64/' -e 's/aarch64/arm64/') + # Directory where to generate the dockcross script for each images (e.g bin/dockcross-manylinux2014-x64) BIN = ./bin # These images are built using the "build implicit rule" STANDARD_IMAGES := android-arm android-arm64 android-x86 android-x86_64 \ - linux-i686 linux-x86 linux-x64 linux-x64-clang linux-arm64 linux-arm64-musl linux-arm64-full \ + linux-i686 linux-x86 linux-x64 linux-x64-clang linux-arm64-musl linux-arm64-full \ linux-armv5 linux-armv5-musl linux-armv5-uclibc linux-m68k-uclibc linux-s390x linux-x64-tinycc \ linux-armv6 linux-armv6-lts linux-armv6-musl linux-arm64-lts linux-mipsel-lts \ linux-armv7l-musl linux-armv7 linux-armv7a linux-armv7-lts linux-armv7a-lts linux-x86_64-full \ linux-mips linux-mips-uclibc linux-mips-lts linux-ppc linux-ppc64le linux-ppc64le-lts linux-riscv64 linux-riscv32 linux-xtensa-uclibc \ - web-wasi \ windows-static-x86 windows-static-x64 windows-static-x64-posix windows-armv7 \ windows-shared-x86 windows-shared-x64 windows-shared-x64-posix windows-arm64 \ bare-armv7emhf-nano_newlib @@ -37,7 +52,7 @@ GEN_IMAGES := android-arm android-arm64 \ manylinux_2_28-x64 \ manylinux2014-x64 manylinux2014-x86 \ manylinux2014-aarch64 linux-arm64-lts \ - web-wasm web-wasi web-wasi-threads linux-mips linux-mips-uclibc linux-mips-lts windows-arm64 windows-armv7 \ + web-wasm web-wasi web-wasi-emulated-threads 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 \ @@ -46,11 +61,15 @@ GEN_IMAGES := android-arm android-arm64 \ linux-riscv64 linux-riscv32 linux-m68k-uclibc linux-x64-tinycc linux-xtensa-uclibc \ bare-armv7emhf-nano_newlib +# Generate both amd64 and arm64 images +MULTIARCH_IMAGES := linux-arm64 \ + web-wasi web-wasi-emulated-threads + 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 web-wasi-threads + manylinux2014-aarch64 web-wasm web-wasi-emulated-threads web-wasi-threads # Docker composite files DOCKER_COMPOSITE_SOURCES = common.docker common.debian common.manylinux2014 common.manylinux_2_28 common.buildroot \ @@ -60,7 +79,7 @@ DOCKER_COMPOSITE_FOLDER_PATH = common/ DOCKER_COMPOSITE_PATH = $(addprefix $(DOCKER_COMPOSITE_FOLDER_PATH),$(DOCKER_COMPOSITE_SOURCES)) # This list all available images -IMAGES := $(STANDARD_IMAGES) $(NON_STANDARD_IMAGES) +IMAGES := $(STANDARD_IMAGES) $(NON_STANDARD_IMAGES) $(MULTIARCH_IMAGES) # Optional arguments for test runner (test/run.py) associated with "testing implicit rule" linux-x64-tinycc.test_ARGS = --languages C @@ -122,13 +141,20 @@ $(GEN_IMAGE_DOCKERFILES) Dockerfile: %Dockerfile: %Dockerfile.in $(DOCKER_COMPOS # # web-wasm # +ifeq ($(HOST_ARCH),amd64) + EMSCRIPTEN_HOST_ARCH_TAG = "" +endif +ifeq ($(HOST_ARCH),arm64) + EMSCRIPTEN_HOST_ARCH_TAG = "-arm64" +endif web-wasm: web-wasm/Dockerfile mkdir -p $@/imagefiles && cp -r imagefiles $@/ cp -r test web-wasm/ - $(DOCKER) $(BUILD_CMD) -t $(ORG)/web-wasm:$(TAG) \ - -t $(ORG)/web-wasm:latest \ + $(BUILD_DOCKER) $(BUILD_CMD) $(TAG_FLAG) $(ORG)/web-wasm:$(TAG)-$(HOST_ARCH) \ + $(TAG_FLAG) $(ORG)/web-wasm:latest-$(HOST_ARCH) \ --build-arg IMAGE=$(ORG)/web-wasm \ --build-arg VERSION=$(TAG) \ + --build-arg HOST_ARCH_TAG=$(EMSCRIPTEN_HOST_ARCH_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"` \ @@ -138,8 +164,8 @@ web-wasm: web-wasm/Dockerfile web-wasm.test: web-wasm cp -r test web-wasm/ - $(DOCKER) run $(RM) $(ORG)/web-wasm:latest > $(BIN)/dockcross-web-wasm && chmod +x $(BIN)/dockcross-web-wasm - $(BIN)/dockcross-web-wasm -i $(ORG)/web-wasm:latest python test/run.py --exe-suffix ".js" + $(TEST_DOCKER) run $(RM) $(ORG)/web-wasm:latest-$(HOST_ARCH) > $(BIN)/dockcross-web-wasm && chmod +x $(BIN)/dockcross-web-wasm + $(BIN)/dockcross-web-wasm -i $(ORG)/web-wasm:latest-$(HOST_ARCH) python test/run.py --exe-suffix ".js" rm -rf web-wasm/test # @@ -148,20 +174,16 @@ web-wasm.test: web-wasm 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_DOCKER) $(BUILD_CMD) $(TAG_FLAG) $(ORG)/web-wasi-threads:$(TAG)-$(HOST_ARCH) \ + -t $(ORG)/web-wasi-threads:latest-$(HOST_ARCH) \ --build-arg IMAGE=$(ORG)/web-wasi-threads \ --build-arg VERSION=$(TAG) \ + --build-arg HOST_ARCH=$(HOST_ARCH) \ --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 # @@ -171,8 +193,8 @@ manylinux2014-aarch64: manylinux2014-aarch64/Dockerfile manylinux2014-x64 @# Get libstdc++ from quay.io/pypa/manylinux2014_aarch64 container docker run -v `pwd`:/host --rm -e LIB_PATH=/host/$@/xc_script/ quay.io/pypa/manylinux2014_aarch64 bash -c "PASS=1 /host/$@/xc_script/docker_setup_scrpits/copy_libstd.sh" mkdir -p $@/imagefiles && cp -r imagefiles $@/ - $(DOCKER) build -t $(ORG)/manylinux2014-aarch64:$(TAG) \ - -t $(ORG)/manylinux2014-aarch64:latest \ + $(BUILD_DOCKER) $(BUILD_CMD) $(TAG_FLAG) $(ORG)/manylinux2014-aarch64:$(TAG) \ + $(TAG_FLAG) $(ORG)/manylinux2014-aarch64:latest \ --build-arg IMAGE=$(ORG)/manylinux2014-aarch64 \ --build-arg VERSION=$(TAG) \ --build-arg VCS_REF=`git rev-parse --short HEAD` \ @@ -184,7 +206,7 @@ manylinux2014-aarch64: manylinux2014-aarch64/Dockerfile manylinux2014-x64 docker run -v `pwd`:/host --rm quay.io/pypa/manylinux2014_aarch64 bash -c "rm -rf /host/$@/xc_script/usr" manylinux2014-aarch64.test: manylinux2014-aarch64 - $(DOCKER) run $(RM) $(ORG)/manylinux2014-aarch64:latest > $(BIN)/dockcross-manylinux2014-aarch64 \ + $(TEST_DOCKER) run $(RM) $(ORG)/manylinux2014-aarch64:latest > $(BIN)/dockcross-manylinux2014-aarch64 \ && chmod +x $(BIN)/dockcross-manylinux2014-aarch64 $(BIN)/dockcross-manylinux2014-aarch64 -i $(ORG)/manylinux2014-aarch64:latest /opt/python/cp38-cp38/bin/python test/run.py @@ -193,8 +215,8 @@ manylinux2014-aarch64.test: manylinux2014-aarch64 # manylinux_2_28-x64: manylinux_2_28-x64/Dockerfile mkdir -p $@/imagefiles && cp -r imagefiles $@/ - $(DOCKER) build -t $(ORG)/manylinux_2_28-x64:$(TAG) \ - -t $(ORG)/manylinux_2_28-x64:latest \ + $(BUILD_DOCKER) $(BUILD_CMD) $(TAG_FLAG) $(ORG)/manylinux_2_28-x64:$(TAG) \ + $(TAG_FLAG) $(ORG)/manylinux_2_28-x64:latest \ --build-arg IMAGE=$(ORG)/manylinux_2_28-x64 \ --build-arg VERSION=$(TAG) \ --build-arg VCS_REF=`git rev-parse --short HEAD` \ @@ -204,7 +226,7 @@ manylinux_2_28-x64: manylinux_2_28-x64/Dockerfile rm -rf $@/imagefiles manylinux_2_28-x64.test: manylinux_2_28-x64 - $(DOCKER) run $(RM) $(ORG)/manylinux_2_28-x64:latest > $(BIN)/dockcross-manylinux_2_28-x64 \ + $(TEST_DOCKER) run $(RM) $(ORG)/manylinux_2_28-x64:latest > $(BIN)/dockcross-manylinux_2_28-x64 \ && chmod +x $(BIN)/dockcross-manylinux_2_28-x64 $(BIN)/dockcross-manylinux_2_28-x64 -i $(ORG)/manylinux_2_28-x64:latest /opt/python/cp310-cp310/bin/python test/run.py @@ -213,8 +235,8 @@ manylinux_2_28-x64.test: manylinux_2_28-x64 # manylinux2014-x64: manylinux2014-x64/Dockerfile mkdir -p $@/imagefiles && cp -r imagefiles $@/ - $(DOCKER) build -t $(ORG)/manylinux2014-x64:$(TAG) \ - -t $(ORG)/manylinux2014-x64:latest \ + $(BUILD_DOCKER) $(BUILD_CMD) $(TAG_FLAG) $(ORG)/manylinux2014-x64:$(TAG) \ + $(TAG_FLAG) $(ORG)/manylinux2014-x64:latest \ --build-arg IMAGE=$(ORG)/manylinux2014-x64 \ --build-arg VERSION=$(TAG) \ --build-arg VCS_REF=`git rev-parse --short HEAD` \ @@ -224,7 +246,7 @@ manylinux2014-x64: manylinux2014-x64/Dockerfile rm -rf $@/imagefiles manylinux2014-x64.test: manylinux2014-x64 - $(DOCKER) run $(RM) $(ORG)/manylinux2014-x64:latest > $(BIN)/dockcross-manylinux2014-x64 \ + $(TEST_DOCKER) run $(RM) $(ORG)/manylinux2014-x64:latest > $(BIN)/dockcross-manylinux2014-x64 \ && chmod +x $(BIN)/dockcross-manylinux2014-x64 $(BIN)/dockcross-manylinux2014-x64 -i $(ORG)/manylinux2014-x64:latest /opt/python/cp38-cp38/bin/python test/run.py @@ -233,7 +255,7 @@ manylinux2014-x64.test: manylinux2014-x64 # manylinux2014-x86: manylinux2014-x86/Dockerfile mkdir -p $@/imagefiles && cp -r imagefiles $@/ - $(DOCKER) build -t $(ORG)/manylinux2014-x86:$(TAG) \ + $(BUILD_DOCKER) $(BUILD_CMD) $(TAG_FLAG) $(ORG)/manylinux2014-x86:$(TAG) \ -t $(ORG)/manylinux2014-x86:latest \ --build-arg IMAGE=$(ORG)/manylinux2014-x86 \ --build-arg VERSION=$(TAG) \ @@ -244,22 +266,32 @@ manylinux2014-x86: manylinux2014-x86/Dockerfile rm -rf $@/imagefiles manylinux2014-x86.test: manylinux2014-x86 - $(DOCKER) run $(RM) $(ORG)/manylinux2014-x86:latest > $(BIN)/dockcross-manylinux2014-x86 \ + $(TEST_DOCKER) run $(RM) $(ORG)/manylinux2014-x86:latest > $(BIN)/dockcross-manylinux2014-x86 \ && chmod +x $(BIN)/dockcross-manylinux2014-x86 $(BIN)/dockcross-manylinux2014-x86 -i $(ORG)/manylinux2014-x86:latest /opt/python/cp38-cp38/bin/python test/run.py # -# base +# base-$(HOST_ARCH) # +base-$(HOST_ARCH): Dockerfile imagefiles/ + $(BUILD_DOCKER) $(BUILD_CMD) $(TAG_FLAG) $(ORG)/base:latest-$(HOST_ARCH) \ + $(TAG_FLAG) $(ORG)/base:$(TAG)-$(HOST_ARCH) \ + --build-arg IMAGE=$(ORG)/base \ + --build-arg VCS_URL=`git config --get remote.origin.url` \ + . + +base-$(HOST_ARCH).test: base-$(HOST_ARCH) + $(TEST_DOCKER) run $(RM) $(ORG)/base:latest-$(HOST_ARCH) > $(BIN)/dockcross-base && chmod +x $(BIN)/dockcross-base + base: Dockerfile imagefiles/ - $(DOCKER) $(BUILD_CMD) -t $(ORG)/base:latest \ - -t $(ORG)/base:$(TAG) \ + $(BUILD_DOCKER) $(BUILD_CMD) $(TAG_FLAG) $(ORG)/base:latest \ + $(TAG_FLAG) $(ORG)/base:$(TAG) \ --build-arg IMAGE=$(ORG)/base \ --build-arg VCS_URL=`git config --get remote.origin.url` \ . base.test: base - $(DOCKER) run $(RM) $(ORG)/base:latest > $(BIN)/dockcross-base && chmod +x $(BIN)/dockcross-base + $(TEST_DOCKER) run $(RM) $(ORG)/base:latest > $(BIN)/dockcross-base && chmod +x $(BIN)/dockcross-base # display # @@ -274,8 +306,8 @@ $(VERBOSE).SILENT: display_images $(STANDARD_IMAGES): %: %/Dockerfile base mkdir -p $@/imagefiles && cp -r imagefiles $@/ - $(DOCKER) $(BUILD_CMD) -t $(ORG)/$@:latest \ - -t $(ORG)/$@:$(TAG) \ + $(BUILD_DOCKER) $(BUILD_CMD) $(TAG_FLAG) $(ORG)/$@:latest \ + $(TAG_FLAG) $(ORG)/$@:$(TAG) \ --build-arg ORG=$(ORG) \ --build-arg IMAGE=$(ORG)/$@ \ --build-arg VERSION=$(TAG) \ @@ -285,6 +317,20 @@ $(STANDARD_IMAGES): %: %/Dockerfile base $@ rm -rf $@/imagefiles +$(MULTIARCH_IMAGES): %: %/Dockerfile base-$(HOST_ARCH) + mkdir -p $@/imagefiles && cp -r imagefiles $@/ + $(BUILD_DOCKER) $(BUILD_CMD) $(TAG_FLAG) $(ORG)/$@:latest-$(HOST_ARCH) \ + $(TAG_FLAG) $(ORG)/$@:$(TAG)-$(HOST_ARCH) \ + --build-arg ORG=$(ORG) \ + --build-arg IMAGE=$(ORG)/$@ \ + --build-arg HOST_ARCH=$(HOST_ARCH) \ + --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"` \ + $@ + rm -rf $@/imagefiles + clean: for d in $(IMAGES) ; do rm -rf $$d/imagefiles ; done for d in $(IMAGES) ; do rm -rf $(BIN)/dockcross-$$d ; done @@ -293,9 +339,9 @@ clean: purge: clean # Remove all untagged images - $(DOCKER) container ls -aq | xargs -r $(DOCKER) container rm -f + $(TEST_DOCKER) container ls -aq | xargs -r $(DOCKER) container rm -f # Remove all images with organization (ex dockcross/*) - $(DOCKER) images --filter=reference='$(ORG)/*' --format='{{.Repository}}:{{.Tag}}' | xargs -r $(DOCKER) rmi -f + $(BUILD_DOCKER) images --filter=reference='$(ORG)/*' --format='{{.Repository}}:{{.Tag}}' | xargs -r $(DOCKER) rmi -f # Check bash syntax bash-check: @@ -307,10 +353,44 @@ bash-check: # .SECONDEXPANSION: $(addsuffix .test,$(STANDARD_IMAGES)): $$(basename $$@) - $(DOCKER) run $(RM) $(ORG)/$(basename $@):latest > $(BIN)/dockcross-$(basename $@) \ + $(TEST_DOCKER) run $(RM) $(ORG)/$(basename $@):latest > $(BIN)/dockcross-$(basename $@) \ && chmod +x $(BIN)/dockcross-$(basename $@) $(BIN)/dockcross-$(basename $@) -i $(ORG)/$(basename $@):latest python3 test/run.py $($@_ARGS) +.SECONDEXPANSION: +$(addsuffix .test,$(MULTIARCH_IMAGES) web-wasi-threads): $$(basename $$@) + $(TEST_DOCKER) run $(RM) $(ORG)/$(basename $@):latest-$(HOST_ARCH) > $(BIN)/dockcross-$(basename $@) \ + && chmod +x $(BIN)/dockcross-$(basename $@) + $(BIN)/dockcross-$(basename $@) -i $(ORG)/$(basename $@):latest-$(HOST_ARCH) python3 test/run.py $($@_ARGS) + +.SECONDEXPANSION: +$(addsuffix .tag-$(HOST_ARCH),$(MULTIARCH_IMAGES) web-wasi-threads web-wasm): $$(basename $$@) + $(BUILD_DOCKER) tag $(ORG)/$(basename $@):latest-$(HOST_ARCH) \ + $(ORG)/$(basename $@):$(TAG)-$(HOST_ARCH) + +.SECONDEXPANSION: +$(addsuffix .push-$(HOST_ARCH),$(MULTIARCH_IMAGES) web-wasi-threads web-wasm): $$(basename $$@) + $(BUILD_DOCKER) push $(ORG)/$(basename $@):latest-$(HOST_ARCH) \ + && $(BUILD_DOCKER) push $(ORG)/$(basename $@):$(TAG)-$(HOST_ARCH) + +.SECONDEXPANSION: +$(addsuffix .push,$(STANDARD_IMAGES) $(NON_STANDARD_IMAGES)): $$(basename $$@) + $(BUILD_DOCKER) push $(ORG)/$(basename $@):latest \ + && $(BUILD_DOCKER) push $(ORG)/$(basename $@):$(TAG) + +.SECONDEXPANSION: +$(addsuffix .manifest,$(MULTIARCH_IMAGES) web-wasi-threads web-wasm): $$(basename $$@) + if $(BUILDAH) manifest exists $(ORG)/$(basename $@); then \ + $(BUILDAH) manifest rm $(ORG)/$(basename $@); fi + $(BUILDAH) manifest create $(ORG)/$(basename $@) + $(BUILDAH) manifest add $(ORG)/$(basename $@) docker://$(ORG)/$(basename $@):latest-amd64 + $(BUILDAH) manifest add $(ORG)/$(basename $@) docker://$(ORG)/$(basename $@):latest-arm64 + +.SECONDEXPANSION: +$(addsuffix .push,$(MULTIARCH_IMAGES) web-wasi-threads web-wasm): $$(basename $$@).manifest + $(BUILDAH) manifest push --all --format v2s2 $(ORG)/$(basename $@) docker://$(ORG)/$(basename $@):latest + $(BUILDAH) manifest push --all --format v2s2 $(ORG)/$(basename $@) docker://$(ORG)/$(basename $@):$(TAG) + # # testing prerequisites implicit rule # diff --git a/common/common.webassembly b/common/common.webassembly index 91a4159..7cd5cd6 100644 --- a/common/common.webassembly +++ b/common/common.webassembly @@ -43,10 +43,10 @@ RUN git clone --recurse-submodules https://github.com/WebAssembly/wabt.git && \ cd ../ && \ rm -rf wabt* -RUN mkdir /wasi-runtimes +RUN mkdir -p /wasi-runtimes ENV WASMTIME_HOME=/wasi-runtimes/wasmtime -RUN mkdir ${WASMTIME_HOME} && curl https://wasmtime.dev/install.sh -sSf | bash +RUN mkdir -p ${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" diff --git a/linux-arm64/Dockerfile.in b/linux-arm64/Dockerfile.in index bb7ab54..aed2c14 100644 --- a/linux-arm64/Dockerfile.in +++ b/linux-arm64/Dockerfile.in @@ -1,12 +1,13 @@ ARG ORG=dockcross -FROM ${ORG}/base:latest +ARG HOST_ARCH=amd64 +FROM ${ORG}/base:latest-${HOST_ARCH} LABEL maintainer="Matt McCormick matt@mmmccormick.com" # This is for 64-bit ARM Linux machine # Crosstool-ng version 2024-05-04 -ENV CT_VERSION crosstool-ng-1.26.0 +ENV CT_VERSION=crosstool-ng-1.26.0 #include "common.crosstool" @@ -18,9 +19,9 @@ RUN apt-get update \ && apt-get clean --yes # The CROSS_TRIPLE is a configured alias of the "aarch64-unknown-linux-gnu" target. -ENV CROSS_TRIPLE aarch64-unknown-linux-gnu +ENV CROSS_TRIPLE=aarch64-unknown-linux-gnu -ENV CROSS_ROOT ${XCC_PREFIX}/${CROSS_TRIPLE} +ENV CROSS_ROOT=${XCC_PREFIX}/${CROSS_TRIPLE} ENV AS=${CROSS_ROOT}/bin/${CROSS_TRIPLE}-as \ AR=${CROSS_ROOT}/bin/${CROSS_TRIPLE}-ar \ CC=${CROSS_ROOT}/bin/${CROSS_TRIPLE}-gcc \ @@ -29,17 +30,17 @@ ENV AS=${CROSS_ROOT}/bin/${CROSS_TRIPLE}-as \ LD=${CROSS_ROOT}/bin/${CROSS_TRIPLE}-ld \ FC=${CROSS_ROOT}/bin/${CROSS_TRIPLE}-gfortran -ENV QEMU_LD_PREFIX "${CROSS_ROOT}/${CROSS_TRIPLE}/sysroot" -ENV QEMU_SET_ENV "LD_LIBRARY_PATH=${CROSS_ROOT}/lib:${QEMU_LD_PREFIX}" +ENV QEMU_LD_PREFIX="${CROSS_ROOT}/${CROSS_TRIPLE}/sysroot" +ENV QEMU_SET_ENV="LD_LIBRARY_PATH=${CROSS_ROOT}/lib:${QEMU_LD_PREFIX}" COPY Toolchain.cmake ${CROSS_ROOT}/ -ENV CMAKE_TOOLCHAIN_FILE ${CROSS_ROOT}/Toolchain.cmake +ENV CMAKE_TOOLCHAIN_FILE=${CROSS_ROOT}/Toolchain.cmake -ENV PKG_CONFIG_PATH /usr/lib/aarch64-linux-gnu/pkgconfig +ENV PKG_CONFIG_PATH=/usr/lib/aarch64-linux-gnu/pkgconfig # Linux kernel cross compilation variables -ENV PATH ${PATH}:${CROSS_ROOT}/bin -ENV CROSS_COMPILE ${CROSS_TRIPLE}- -ENV ARCH arm64 +ENV PATH=${PATH}:${CROSS_ROOT}/bin +ENV CROSS_COMPILE=${CROSS_TRIPLE}- +ENV ARCH=arm64 #include "common.label-and-env" diff --git a/tools/dockcross-cmake-builder.sh b/tools/dockcross-cmake-builder.sh index 8e3612c..b60c36c 100755 --- a/tools/dockcross-cmake-builder.sh +++ b/tools/dockcross-cmake-builder.sh @@ -1,12 +1,20 @@ #!/usr/bin/env bash +set -x + if (( $# >= 1 )); then - image_complet=$1 - image=${image_complet%:*} - tag=${image_complet#*:} + image_complete=$1 + image=${image_complete%:*} + tag=${image_complete#*:} build_file=build-$image + host_arch=$(uname -m | sed -e 's/x86_64/amd64/' -e 's/aarch64/arm64/') if test $tag = $image; then - tag="latest" + # use multiarch image if available + if docker images | grep dockcross/${image} | grep latest-${host_arch} >/dev/null; then + tag="latest-${host_arch}" + else + tag="latest" + fi fi shift 1 @@ -17,7 +25,7 @@ if (( $# >= 1 )); then # docker pull "dockcross/$image:$tag" echo "Make script dockcross-$image" - docker run --rm dockcross/"$image" > ./dockcross-"$image" + docker run --rm dockcross/"$image:$tag" > ./dockcross-"$image" chmod +x ./dockcross-"$image" echo "Build $build_file" diff --git a/tools/dockcross-command.sh b/tools/dockcross-command.sh index df7bd6e..e8d2a01 100755 --- a/tools/dockcross-command.sh +++ b/tools/dockcross-command.sh @@ -4,8 +4,14 @@ if (( $# >= 2 )); then image_complet=$1 image=${image_complet%:*} tag=${image_complet#*:} + host_arch=$(uname -m | sed -e 's/x86_64/amd64/' -e 's/aarch64/arm64/') if test $tag = $image; then - tag="latest" + # use multiarch image if available + if docker images | grep dockcross/${image} | grep latest-${host_arch} >/dev/null; then + tag="latest-${host_arch}" + else + tag="latest" + fi fi shift 1 @@ -16,7 +22,7 @@ if (( $# >= 2 )); then # docker pull "dockcross/$image:$tag" echo "Make script dockcross-$image" - docker run --rm dockcross/"$image" > ./dockcross-"$image" + docker run --rm dockcross/"$image:$tag" > ./dockcross-"$image" chmod +x ./dockcross-"$image" echo "Run command in dockcross-$image" diff --git a/tools/dockcross-make-builder.sh b/tools/dockcross-make-builder.sh index c22c5ec..e353481 100755 --- a/tools/dockcross-make-builder.sh +++ b/tools/dockcross-make-builder.sh @@ -1,10 +1,19 @@ #!/usr/bin/env bash if (( $# >= 1 )); then - image_complet=$1 - image=${image_complet%:*} - tag=${image_complet#*:} + image_complete=$1 + image=${image_complete%:*} + tag=${image_complete#*:} build_file=build-$image + host_arch=$(uname -m | sed -e 's/x86_64/amd64/' -e 's/aarch64/arm64/') + if test $tag = $image; then + # use multiarch image if available + if docker images | grep dockcross/${image} | grep latest-${host_arch} >/dev/null; then + tag="latest-${host_arch}" + else + tag="latest" + fi + fi shift 1 make_arg=$* @@ -14,11 +23,11 @@ if (( $# >= 1 )); then # docker pull "dockcross/$image:$tag" echo "Make script dockcross-$image" - docker run --rm dockcross/"$image" > ./dockcross-"$image" + docker run --rm dockcross/"$image:$tag" > ./dockcross-"$image" chmod +x ./dockcross-"$image" echo "Build $build_file" - ./dockcross-"$image" -i dockcross/"$image":latest bash -c 'make CXX=${CXX} CC=${CC} AR=${AR} AS=${AS} LD=${LD} CPP=${CPP} FC=${FC} '"$make_arg" + ./dockcross-"$image" -i dockcross/"$image:$tag" bash -c 'make CXX=${CXX} CC=${CC} AR=${AR} AS=${AS} LD=${LD} CPP=${CPP} FC=${FC} '"$make_arg" else echo "Usage: ${0##*/} " exit 1 diff --git a/web-wasi-emulated-threads/CheckTypeSize.c.in b/web-wasi-emulated-threads/CheckTypeSize.c.in new file mode 100644 index 0000000..ce19444 --- /dev/null +++ b/web-wasi-emulated-threads/CheckTypeSize.c.in @@ -0,0 +1,37 @@ +@headers@ + +#undef KEY +#if defined(__i386) +# define KEY '_','_','i','3','8','6' +#elif defined(__x86_64) +# define KEY '_','_','x','8','6','_','6','4' +#elif defined(__ppc__) +# define KEY '_','_','p','p','c','_','_' +#elif defined(__ppc64__) +# define KEY '_','_','p','p','c','6','4','_','_' +#endif + +#define SIZE (sizeof(@type@)) +char info_size[] = {'I', 'N', 'F', 'O', ':', 's','i','z','e','[', + ('0' + ((SIZE / 10000)%10)), + ('0' + ((SIZE / 1000)%10)), + ('0' + ((SIZE / 100)%10)), + ('0' + ((SIZE / 10)%10)), + ('0' + (SIZE % 10)), + ']', +#ifdef KEY + ' ','k','e','y','[', KEY, ']', +#endif + '\0'}; + +#ifdef __CLASSIC_C__ +int main(argc, argv) int argc; char *argv[]; +#else +int main(int argc, char *argv[]) +#endif +{ + int require = 0; + require += info_size[argc]; + (void)argv; + return SIZE; +} diff --git a/web-wasi-emulated-threads/CheckTypeSize.cmake b/web-wasi-emulated-threads/CheckTypeSize.cmake new file mode 100644 index 0000000..e277605 --- /dev/null +++ b/web-wasi-emulated-threads/CheckTypeSize.cmake @@ -0,0 +1,231 @@ +#.rst: +# CheckTypeSize +# ------------- +# +# Check sizeof a type +# +# :: +# +# CHECK_TYPE_SIZE(TYPE VARIABLE [BUILTIN_TYPES_ONLY] +# [LANGUAGE ]) +# +# Check if the type exists and determine its size. On return, +# "HAVE_${VARIABLE}" holds the existence of the type, and "${VARIABLE}" +# holds one of the following: +# +# :: +# +# = type has non-zero size +# "0" = type has arch-dependent size (see below) +# "" = type does not exist +# +# Both ``HAVE_${VARIABLE}`` and ``${VARIABLE}`` will be created as internal +# cache variables. +# +# Furthermore, the variable "${VARIABLE}_CODE" holds C preprocessor code +# to define the macro "${VARIABLE}" to the size of the type, or leave +# the macro undefined if the type does not exist. +# +# The variable "${VARIABLE}" may be "0" when CMAKE_OSX_ARCHITECTURES has +# multiple architectures for building OS X universal binaries. This +# indicates that the type size varies across architectures. In this +# case "${VARIABLE}_CODE" contains C preprocessor tests mapping from +# each architecture macro to the corresponding type size. The list of +# architecture macros is stored in "${VARIABLE}_KEYS", and the value for +# each key is stored in "${VARIABLE}-${KEY}". +# +# If the BUILTIN_TYPES_ONLY option is not given, the macro checks for +# headers , , and , and saves results +# in HAVE_SYS_TYPES_H, HAVE_STDINT_H, and HAVE_STDDEF_H. The type size +# check automatically includes the available headers, thus supporting +# checks of types defined in the headers. +# +# If LANGUAGE is set, the specified compiler will be used to perform the +# check. Acceptable values are C and CXX +# +# Despite the name of the macro you may use it to check the size of more +# complex expressions, too. To check e.g. for the size of a struct +# member you can do something like this: +# +# :: +# +# check_type_size("((struct something*)0)->member" SIZEOF_MEMBER) +# +# +# +# The following variables may be set before calling this macro to modify +# the way the check is run: +# +# :: +# +# CMAKE_REQUIRED_FLAGS = string of compile command line flags +# CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar) +# CMAKE_REQUIRED_INCLUDES = list of include directories +# CMAKE_REQUIRED_LIBRARIES = list of libraries to link +# CMAKE_REQUIRED_QUIET = execute quietly without messages +# CMAKE_EXTRA_INCLUDE_FILES = list of extra headers to include + +#============================================================================= +# Copyright 2002-2009 Kitware, Inc. +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +include(CheckIncludeFile) +include(CheckIncludeFileCXX) + +cmake_policy(PUSH) +cmake_policy(VERSION 3.0) + +get_filename_component(__check_type_size_dir "${CMAKE_CURRENT_LIST_FILE}" PATH) + +#----------------------------------------------------------------------------- +# Helper function. DO NOT CALL DIRECTLY. +function(__check_type_size_impl type var map builtin language) + if(NOT CMAKE_REQUIRED_QUIET) + message(STATUS "Check size of ${type}") + endif() + + # Include header files. + set(headers) + if(builtin) + if(HAVE_SYS_TYPES_H) + set(headers "${headers}#include \n") + endif() + if(HAVE_STDINT_H) + set(headers "${headers}#include \n") + endif() + if(HAVE_STDDEF_H) + set(headers "${headers}#include \n") + endif() + endif() + foreach(h ${CMAKE_EXTRA_INCLUDE_FILES}) + set(headers "${headers}#include \"${h}\"\n") + endforeach() + + # Perform the check. + + if("${language}" STREQUAL "C") + set(src ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CheckTypeSize/${var}.c) + elseif("${language}" STREQUAL "CXX") + set(src ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CheckTypeSize/${var}.cpp) + else() + message(FATAL_ERROR "Unknown language:\n ${language}\nSupported languages: C, CXX.\n") + endif() + set(bin ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CheckTypeSize/${var}.bin) + configure_file(${__check_type_size_dir}/CheckTypeSize.c.in ${src} @ONLY) + try_run(${var}_run_result HAVE_${var} ${CMAKE_BINARY_DIR} ${src} + COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} + LINK_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} + CMAKE_FLAGS + "-DCOMPILE_DEFINITIONS:STRING=${CMAKE_REQUIRED_FLAGS}" + "-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}" + RUN_OUTPUT_VARIABLE ${var}_run_output + COMPILE_OUTPUT_VARIABLE output + ) + + if(${HAVE_${var}} AND NOT "${${var}_run_result}" STREQUAL "FAILED_TO_RUN") + set(${var} ${${var}_run_result}) + if(NOT CMAKE_REQUIRED_QUIET) + message(STATUS "Check size of ${type} - done") + endif() + file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log + "Determining size of ${type} passed with the following output:\n${output}\n\n") + set(${var} "${${var}}" CACHE INTERNAL "CHECK_TYPE_SIZE: sizeof(${type})") + else() + # The check failed to compile. + if(NOT CMAKE_REQUIRED_QUIET) + message(STATUS "Check size of ${type} - failed") + endif() + file(READ ${src} content) + file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log + "Determining size of ${type} failed with the following output:\n${output}\n${src}:\n${content}\n\n") + set(${var} "" CACHE INTERNAL "CHECK_TYPE_SIZE: ${type} unknown") + file(REMOVE ${map}) + endif() +endfunction() + +#----------------------------------------------------------------------------- +macro(CHECK_TYPE_SIZE TYPE VARIABLE) + # parse arguments + unset(doing) + foreach(arg ${ARGN}) + if("x${arg}" STREQUAL "xBUILTIN_TYPES_ONLY") + set(_CHECK_TYPE_SIZE_${arg} 1) + unset(doing) + elseif("x${arg}" STREQUAL "xLANGUAGE") # change to MATCHES for more keys + set(doing "${arg}") + set(_CHECK_TYPE_SIZE_${doing} "") + elseif("x${doing}" STREQUAL "xLANGUAGE") + set(_CHECK_TYPE_SIZE_${doing} "${arg}") + unset(doing) + else() + message(FATAL_ERROR "Unknown argument:\n ${arg}\n") + endif() + endforeach() + if("x${doing}" MATCHES "^x(LANGUAGE)$") + message(FATAL_ERROR "Missing argument:\n ${doing} arguments requires a value\n") + endif() + if(DEFINED _CHECK_TYPE_SIZE_LANGUAGE) + if(NOT "x${_CHECK_TYPE_SIZE_LANGUAGE}" MATCHES "^x(C|CXX)$") + message(FATAL_ERROR "Unknown language:\n ${_CHECK_TYPE_SIZE_LANGUAGE}.\nSupported languages: C, CXX.\n") + endif() + set(_language ${_CHECK_TYPE_SIZE_LANGUAGE}) + else() + set(_language C) + endif() + + # Optionally check for standard headers. + if(_CHECK_TYPE_SIZE_BUILTIN_TYPES_ONLY) + set(_builtin 0) + else() + set(_builtin 1) + if("${_language}" STREQUAL "C") + check_include_file(sys/types.h HAVE_SYS_TYPES_H) + check_include_file(stdint.h HAVE_STDINT_H) + check_include_file(stddef.h HAVE_STDDEF_H) + elseif("${_language}" STREQUAL "CXX") + check_include_file_cxx(sys/types.h HAVE_SYS_TYPES_H) + check_include_file_cxx(stdint.h HAVE_STDINT_H) + check_include_file_cxx(stddef.h HAVE_STDDEF_H) + endif() + endif() + unset(_CHECK_TYPE_SIZE_BUILTIN_TYPES_ONLY) + unset(_CHECK_TYPE_SIZE_LANGUAGE) + + # Compute or load the size or size map. + set(${VARIABLE}_KEYS) + set(_map_file ${CMAKE_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/CheckTypeSize/${VARIABLE}.cmake) + if(NOT DEFINED HAVE_${VARIABLE}) + __check_type_size_impl(${TYPE} ${VARIABLE} ${_map_file} ${_builtin} ${_language}) + endif() + include(${_map_file} OPTIONAL) + set(_map_file) + set(_builtin) + + # Create preprocessor code. + if(${VARIABLE}_KEYS) + set(${VARIABLE}_CODE) + set(_if if) + foreach(key ${${VARIABLE}_KEYS}) + set(${VARIABLE}_CODE "${${VARIABLE}_CODE}#${_if} defined(${key})\n# define ${VARIABLE} ${${VARIABLE}-${key}}\n") + set(_if elif) + endforeach() + set(${VARIABLE}_CODE "${${VARIABLE}_CODE}#else\n# error ${VARIABLE} unknown\n#endif") + set(_if) + elseif(${VARIABLE}) + set(${VARIABLE}_CODE "#define ${VARIABLE} ${${VARIABLE}}") + else() + set(${VARIABLE}_CODE "/* #undef ${VARIABLE} */") + endif() +endmacro() + +#----------------------------------------------------------------------------- +cmake_policy(POP) diff --git a/web-wasi-emulated-threads/Dockerfile.in b/web-wasi-emulated-threads/Dockerfile.in new file mode 100644 index 0000000..486023a --- /dev/null +++ b/web-wasi-emulated-threads/Dockerfile.in @@ -0,0 +1,42 @@ +ARG ORG=dockcross +ARG HOST_ARCH=amd64 +FROM ${ORG}/base:latest-${HOST_ARCH} + +LABEL maintainer="Matt McCormick matt@mmmccormick.com" + +ENV LLVM_VERSION=19 +ENV WASI_VERSION=25 +ENV WASI_VERSION_FULL=${WASI_VERSION}.0 + +ENV WASMTIME_HOME=/wasi-runtimes/wasmtime +RUN mkdir -p ${WASMTIME_HOME} && curl https://wasmtime.dev/install.sh -sSf | bash +ENV PATH="$WASMTIME_HOME/bin:$PATH" + +COPY download-build-install-wasi-sdk.sh /usr/local/bin/ +RUN /usr/local/bin/download-build-install-wasi-sdk.sh + +ENV WASI_SYSROOT=/opt/wasi-sdk/share/wasi-sysroot +ENV WASI_SDK_PATH=/opt/wasi-sdk + +COPY clang-wasi-sysroot.sh clang++-wasi-sysroot.sh /usr/local/bin/ + +ENV CROSS_TRIPLE=wasm32-wasi +ENV CROSS_ROOT=${WASI_SDK_PATH} +ENV AR=${WASI_SDK_PATH}/bin/llvm-ar \ + CC=clang-wasi-sysroot.sh \ + CXX=clang++-wasi-sysroot.sh \ + LD=${WASI_SDK_PATH}/bin/wasm-ld \ + RANLIB=${WASI_SDK_PATH}/bin/llvm-ranlib + +#include "common.webassembly" + +COPY WASI.cmake /usr/src/ +RUN mv /usr/src/WASI.cmake /usr/share/cmake-*/Modules/Platform/ +COPY *.cmake /usr/src/ +RUN mv /usr/src/*.cmake /usr/share/cmake-*/Modules/ +COPY CheckTypeSize.c.in /usr/src/ +RUN mv /usr/src/CheckTypeSize.c.in /usr/share/cmake-*/Modules/ +COPY Toolchain.cmake ${CROSS_ROOT}/ +ENV CMAKE_TOOLCHAIN_FILE=${CROSS_ROOT}/Toolchain.cmake + +#include "common.label-and-env" diff --git a/web-wasi-emulated-threads/FindOpenAL.cmake b/web-wasi-emulated-threads/FindOpenAL.cmake new file mode 100644 index 0000000..3ba6cc8 --- /dev/null +++ b/web-wasi-emulated-threads/FindOpenAL.cmake @@ -0,0 +1,25 @@ +# Locate OpenAL +# This module defines +# OPENAL_LIBRARY +# OPENAL_FOUND, if false, do not try to link to OpenAL +# OPENAL_INCLUDE_DIR, where to find the headers + +# The implementation is based on the standard FindOpenAL.cmake provided with CMake, +# but customized for targeting Emscripten only. + +if (NOT OPENAL_FOUND) + SET(OPENAL_FOUND TRUE) + + # For Emscripten-compiled apps in the test suite (test_alut), this is expected... + SET(OPENAL_INCLUDE_DIR "${EMSCRIPTEN_ROOT_PATH}/system/include") + # ... but the stock FindOpenAL.cmake would have returned this. + #SET(OPENAL_INCLUDE_DIR "${EMSCRIPTEN_ROOT_PATH}/system/include/AL") + + # Returning "-lopenal" is now considered mandatory + SET(OPENAL_LIBRARY "-lopenal") + SET(OPENAL_LIB "-lopenal") + + set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "${EMSCRIPTEN_ROOT_PATH}/system/include" "${EMSCRIPTEN_ROOT_PATH}/system/include/AL") + + MARK_AS_ADVANCED(OPENAL_LIBRARY OPENAL_INCLUDE_DIR) +endif() diff --git a/web-wasi-emulated-threads/FindOpenGL.cmake b/web-wasi-emulated-threads/FindOpenGL.cmake new file mode 100644 index 0000000..f348ba2 --- /dev/null +++ b/web-wasi-emulated-threads/FindOpenGL.cmake @@ -0,0 +1,34 @@ +# Locate OpenGL +# This module defines: +# OPENGL_FOUND - system has OpenGL +# OPENGL_XMESA_FOUND - system has XMESA +# OPENGL_GLU_FOUND - system has GLU +# OPENGL_INCLUDE_DIR - the GL include directory +# OPENGL_LIBRARIES - Link these to use OpenGL and GLU +# OPENGL_gl_LIBRARY - Path to OpenGL Library +# OPENGL_glu_LIBRARY - Path to GLU Library + +# The implementation is based on the standard FindOpenGL.cmake provided with CMake, +# but customized for targeting Emscripten only. + +# These libraries are provided with Emscripten +SET(OPENGL_FOUND TRUE) +SET(OPENGL_GLU_FOUND TRUE) + +# Doesn't look like this one is part of Emscripten +SET(OPENGL_XMESA_FOUND FALSE) + +# This is the path where is found +SET(OPENGL_INCLUDE_DIR "${EMSCRIPTEN_ROOT_PATH}/system/include") + +# No library to link against for OpenGL, since Emscripten picks it up automatically from library_webgl.js, +# but need to report something, or CMake thinks we failed in the search. +SET(OPENGL_LIBRARIES "nul") +SET(OPENGL_gl_LIBRARY "nul") +SET(OPENGL_glu_LIBRARY "nul") + +mark_as_advanced( + OPENGL_INCLUDE_DIR + OPENGL_glu_LIBRARY + OPENGL_gl_LIBRARY +) diff --git a/web-wasi-emulated-threads/TestBigEndian.cmake b/web-wasi-emulated-threads/TestBigEndian.cmake new file mode 100644 index 0000000..81d4789 --- /dev/null +++ b/web-wasi-emulated-threads/TestBigEndian.cmake @@ -0,0 +1,30 @@ +#.rst: +# TestBigEndian +# ------------- +# +# The TestBigEndian.cmake module that ships with CMake, which +# checks if the system is big endian or little endian, assumes +# that a binary is produced that will have bytes that correspond to the +# endianness on the target system. Since emscripten produces Javascript, we +# override the default behavior and always return little endian. +# +# :: +# +# TEST_BIG_ENDIAN(VARIABLE) +# VARIABLE - variable to store the result to +#============================================================================= +# Copyright 2002-2009 Kitware, Inc. +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +function(TEST_BIG_ENDIAN VARIABLE) + set(${VARIABLE} 0 CACHE INTERNAL "Result of TEST_BIG_ENDIAN" FORCE) +endfunction() diff --git a/web-wasi-emulated-threads/Toolchain.cmake b/web-wasi-emulated-threads/Toolchain.cmake new file mode 100644 index 0000000..23b245e --- /dev/null +++ b/web-wasi-emulated-threads/Toolchain.cmake @@ -0,0 +1,14 @@ +set(WASI_SDK_PREFIX $ENV{WASI_SDK_PATH}) +include($ENV{WASI_SDK_PATH}/share/cmake/wasi-sdk.cmake) + +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_WASI_EMULATED_PTHREAD") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_WASI_EMULATED_PTHREAD") +set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lwasi-emulated-pthread") + +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_CROSSCOMPILING_EMULATOR /wasi-runtimes/wasmtime/bin/wasmtime-pwd.sh) diff --git a/web-wasi-emulated-threads/WASI.cmake b/web-wasi-emulated-threads/WASI.cmake new file mode 100644 index 0000000..8bb6cb7 --- /dev/null +++ b/web-wasi-emulated-threads/WASI.cmake @@ -0,0 +1,2 @@ +set(WASI 1) +set(UNIX 1) diff --git a/web-wasi-emulated-threads/clang++-wasi-sysroot.sh b/web-wasi-emulated-threads/clang++-wasi-sysroot.sh new file mode 100755 index 0000000..795e06c --- /dev/null +++ b/web-wasi-emulated-threads/clang++-wasi-sysroot.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env sh + +exec ${WASI_SDK_PATH}/bin/clang++ -D_WASI_EMULATED_PTHREAD --target=wasm32-wasi --sysroot=${WASI_SYSROOT} "$@" diff --git a/web-wasi-emulated-threads/clang-wasi-sysroot.sh b/web-wasi-emulated-threads/clang-wasi-sysroot.sh new file mode 100755 index 0000000..8b2cf09 --- /dev/null +++ b/web-wasi-emulated-threads/clang-wasi-sysroot.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env sh + +exec ${WASI_SDK_PATH}/bin/clang -D_WASI_EMULATED_PTHREAD --target=wasm32-wasi --sysroot=${WASI_SYSROOT} "$@" diff --git a/web-wasi-emulated-threads/download-build-install-wasi-sdk.sh b/web-wasi-emulated-threads/download-build-install-wasi-sdk.sh new file mode 100755 index 0000000..1a35663 --- /dev/null +++ b/web-wasi-emulated-threads/download-build-install-wasi-sdk.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash + +set -eox pipefail + +mkdir /tmp/dl +cd /tmp/dl + +wasi_sdk_dir=/opt/wasi-sdk +mkdir -p $wasi_sdk_dir + +curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y +export PATH=$HOME/.cargo/bin:$PATH + +git clone --recurse-submodules -b enable-libcxx-threads https://github.com/thewtex/wasi-sdk +cd wasi-sdk +git fetch origin --tags +git remote add upstream https://github.com/WebAssembly/wasi-sdk +git fetch upstream wasi-sdk-${WASI_VERSION} + +./ci/build.sh +cd build/dist +tar xzf wasi-toolchain-*.tar.gz --strip-components=1 -C /opt/wasi-sdk +mkdir -p /opt/wasi-sdk/share/wasi-sysroot +tar xzf wasi-sysroot-*.tar.gz --strip-components=1 -C /opt/wasi-sdk/share/wasi-sysroot +for wasi_toolchain in wasi wasip1 wasip2; do + libclang_rt_out_dir=/opt/wasi-sdk/lib/clang/${LLVM_VERSION}/${wasi_toolchain} + mkdir -p $libclang_rt_out_dir + tar xzf ./libclang_rt.builtins-*.tar.gz --strip-components=1 -C $libclang_rt_out_dir +done +mkdir -p /opt/wasi-sdk/lib/clang/${LLVM_VERSION}/lib/wasm32-unknown-wasi +cp ${libclang_rt_out_dir}/libclang_rt.builtins-wasm32.a /opt/wasi-sdk/lib/clang/${LLVM_VERSION}/lib/wasm32-unknown-wasi/libclang_rt.builtins.a + +cd /tmp/ +rm -rf /tmp/dl +rm -rf $HOME/.cargo + diff --git a/web-wasi-threads/Dockerfile.in b/web-wasi-threads/Dockerfile.in index 163fd27..d1fb440 100644 --- a/web-wasi-threads/Dockerfile.in +++ b/web-wasi-threads/Dockerfile.in @@ -1,5 +1,6 @@ ARG ORG=dockcross -FROM ${ORG}/web-wasi:latest +ARG HOST_ARCH=amd64 +FROM ${ORG}/web-wasi:latest-${HOST_ARCH} LABEL maintainer="Matt McCormick matt@mmmccormick.com" @@ -10,6 +11,6 @@ ENV CC=clang-wasi-threads-sysroot.sh \ CXX=clang++-wasi-threads-sysroot.sh COPY Toolchain.cmake ${CROSS_ROOT}/ -ENV CMAKE_TOOLCHAIN_FILE ${CROSS_ROOT}/Toolchain.cmake +ENV CMAKE_TOOLCHAIN_FILE=${CROSS_ROOT}/Toolchain.cmake #include "common.label-and-env" diff --git a/web-wasi/Dockerfile.in b/web-wasi/Dockerfile.in index df9d477..43ae696 100644 --- a/web-wasi/Dockerfile.in +++ b/web-wasi/Dockerfile.in @@ -1,5 +1,6 @@ ARG ORG=dockcross -FROM ${ORG}/base:latest +ARG HOST_ARCH=amd64 +FROM ${ORG}/base:latest-${HOST_ARCH} LABEL maintainer="Matt McCormick matt@mmmccormick.com" diff --git a/web-wasm/Dockerfile.in b/web-wasm/Dockerfile.in index 1091ff2..d0146fc 100644 --- a/web-wasm/Dockerfile.in +++ b/web-wasm/Dockerfile.in @@ -1,5 +1,6 @@ ARG DOCKER_IMAGE_VERSION=3.1.74 -FROM emscripten/emsdk:$DOCKER_IMAGE_VERSION +ARG HOST_ARCH_TAG +FROM emscripten/emsdk:$DOCKER_IMAGE_VERSION$HOST_ARCH_TAG LABEL maintainer="Matt McCormick matt@mmmccormick.com" @@ -57,15 +58,15 @@ RUN ln -s /usr/bin/python3 /usr/bin/python #include "common.webassembly" -ENV EMSCRIPTEN_VERSION $DOCKER_IMAGE_VERSION +ENV EMSCRIPTEN_VERSION=$DOCKER_IMAGE_VERSION -ENV PATH /emsdk:/emsdk/upstream/bin/:/emsdk/upstream/emscripten:${PATH} +ENV PATH=/emsdk:/emsdk/upstream/bin/:/emsdk/upstream/emscripten:${PATH} ENV CC=/emsdk/upstream/emscripten/emcc \ CXX=/emsdk/upstream/emscripten/em++ \ AR=/emsdk/upstream/emscripten/emar RUN chmod -R 777 /emsdk/upstream/emscripten/cache -ENV CMAKE_TOOLCHAIN_FILE /emsdk/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake +ENV CMAKE_TOOLCHAIN_FILE=/emsdk/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake #include "common.label-and-env"