From 858a3d8755820fd9bea1b1cc1e85041de3f1882e Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Thu, 4 Apr 2024 06:02:44 -0400 Subject: [PATCH 01/40] ci: add arm_host to arch_name matrix option Define whether we will also build for an ARM64 host. "yes" - yes "no" - explicitly do not build "" - have not tried yet --- .github/workflows/main.yml | 58 +++++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f1a49d5..608ac21 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -65,6 +65,7 @@ jobs: # Android images - { image: "android-arm", + arm_host: "", stockfish: "yes", stockfish_arg: "ARCH=armv7 COMP=ndk", ninja: "no", @@ -86,6 +87,7 @@ jobs: } - { image: "android-arm64", + arm_host: "", stockfish: "yes", stockfish_arg: "ARCH=armv8 COMP=ndk", ninja: "no", @@ -107,6 +109,7 @@ jobs: } - { image: "android-x86", + arm_host: "", stockfish: "yes", stockfish_arg: "ARCH=x86-32 COMP=ndk", ninja: "no", @@ -128,6 +131,7 @@ jobs: } - { image: "android-x86_64", + arm_host: "", stockfish: "yes", stockfish_arg: "ARCH=x86-64 COMP=ndk", ninja: "no", @@ -150,6 +154,7 @@ jobs: # Linux arm64/armv8 images - { image: "linux-arm64", + arm_host: "", stockfish: "yes", stockfish_arg: "ARCH=armv8", ninja: "yes", @@ -171,6 +176,7 @@ jobs: } - { image: "linux-arm64-lts", + arm_host: "", stockfish: "yes", stockfish_arg: "ARCH=armv8", ninja: "yes", @@ -192,6 +198,7 @@ jobs: } - { image: "linux-arm64-musl", + arm_host: "", stockfish: "yes", stockfish_arg: "ARCH=armv8", ninja: "yes", @@ -213,6 +220,7 @@ jobs: } - { image: "linux-arm64-full", + arm_host: "", stockfish: "yes", stockfish_arg: "ARCH=armv8", ninja: "yes", @@ -235,6 +243,7 @@ jobs: # Linux mipel images - { image: "linux-mipsel-lts", + arm_host: "", stockfish: "no", stockfish_arg: "", ninja: "no", @@ -257,6 +266,7 @@ jobs: # Linux armv5 images - { image: "linux-armv5", + arm_host: "", stockfish: "no", stockfish_arg: "", ninja: "yes", @@ -278,6 +288,7 @@ jobs: } - { image: "linux-armv5-musl", + arm_host: "", stockfish: "no", stockfish_arg: "", ninja: "yes", @@ -299,6 +310,7 @@ jobs: } - { image: "linux-armv5-uclibc", + arm_host: "", stockfish: "no", stockfish_arg: "", ninja: "yes", @@ -321,6 +333,7 @@ jobs: # Linux armv6 images - { image: "linux-armv6", + arm_host: "", stockfish: "no", stockfish_arg: "", ninja: "yes", @@ -342,6 +355,7 @@ jobs: } - { image: "linux-armv6-lts", + arm_host: "", stockfish: "no", stockfish_arg: "", ninja: "yes", @@ -363,6 +377,7 @@ jobs: } - { image: "linux-armv6-musl", + arm_host: "", stockfish: "no", stockfish_arg: "", ninja: "yes", @@ -385,6 +400,7 @@ jobs: # Linux armv7 images - { image: "linux-armv7", + arm_host: "", stockfish: "yes", stockfish_arg: "ARCH=armv7", ninja: "yes", @@ -406,6 +422,7 @@ jobs: } - { image: "linux-armv7a", + arm_host: "", stockfish: "yes", stockfish_arg: "ARCH=armv7-neon", ninja: "yes", @@ -427,6 +444,7 @@ jobs: } - { image: "linux-armv7a-lts", + arm_host: "", stockfish: "yes", stockfish_arg: "ARCH=armv7-neon", ninja: "yes", @@ -448,6 +466,7 @@ jobs: } - { image: "linux-armv7-lts", + arm_host: "", stockfish: "yes", stockfish_arg: "ARCH=armv7", ninja: "yes", @@ -469,6 +488,7 @@ jobs: } - { image: "linux-armv7l-musl", + arm_host: "", stockfish: "yes", stockfish_arg: "ARCH=armv7", ninja: "yes", @@ -491,6 +511,7 @@ jobs: # Linux x86 images - { image: "linux-x86", + arm_host: "", stockfish: "yes", stockfish_arg: "ARCH=x86-32-sse41-popcnt", ninja: "yes", @@ -513,6 +534,7 @@ jobs: # Linux i686 images - { image: "linux-i686", + arm_host: "", stockfish: "no", stockfish_arg: "", ninja: "yes", @@ -535,6 +557,7 @@ jobs: # Linux x86_64 images - { image: "linux-x64", + arm_host: "", stockfish: "yes", stockfish_arg: "ARCH=x86-64-modern", ninja: "yes", @@ -556,6 +579,7 @@ jobs: } - { image: "linux-x64-tinycc", + arm_host: "", stockfish: "yes", stockfish_arg: "ARCH=x86-64-modern", ninja: "yes", @@ -577,6 +601,7 @@ jobs: } - { image: "linux-x64-clang", + arm_host: "", stockfish: "yes", stockfish_arg: "ARCH=x86-64-modern COMP=clang", ninja: "yes", @@ -598,6 +623,7 @@ jobs: } - { image: "linux-x86_64-full", + arm_host: "", stockfish: "yes", stockfish_arg: "ARCH=x86-64-modern", ninja: "yes", @@ -620,6 +646,7 @@ jobs: # Linux riscv images - { image: "linux-riscv32", + arm_host: "", stockfish: "no", stockfish_arg: "", ninja: "yes", @@ -641,6 +668,7 @@ jobs: } - { image: "linux-riscv64", + arm_host: "", stockfish: "no", stockfish_arg: "", ninja: "yes", @@ -663,6 +691,7 @@ jobs: # Linux s390x images - { image: "linux-s390x", + arm_host: "", stockfish: "no", stockfish_arg: "", ninja: "yes", @@ -685,6 +714,7 @@ jobs: # Linux mips images - { image: "linux-mips", + arm_host: "", stockfish: "no", stockfish_arg: "", ninja: "yes", @@ -706,6 +736,7 @@ jobs: } - { image: "linux-mips-uclibc", + arm_host: "", stockfish: "no", stockfish_arg: "", ninja: "yes", @@ -728,6 +759,7 @@ jobs: # Linux mips images - { image: "linux-mips-lts", + arm_host: "", stockfish: "no", stockfish_arg: "", ninja: "yes", @@ -772,6 +804,7 @@ jobs: # Linux ppc64le images - { image: "linux-ppc64le", + arm_host: "", stockfish: "yes", stockfish_arg: "ARCH=ppc-64", ninja: "yes", @@ -794,6 +827,7 @@ jobs: # Linux ppc64le-lts images - { image: "linux-ppc64le-lts", + arm_host: "", stockfish: "yes", stockfish_arg: "ARCH=ppc-64", ninja: "yes", @@ -816,6 +850,7 @@ jobs: # Linux m68k images - { image: "linux-m68k-uclibc", + arm_host: "", stockfish: "no", stockfish_arg: "", ninja: "no", @@ -838,6 +873,7 @@ jobs: # Linux xtensa images - { image: "linux-xtensa-uclibc", + arm_host: "", stockfish: "no", stockfish_arg: "", ninja: "yes", @@ -860,6 +896,7 @@ jobs: # Windows x86_x64 images - { image: "windows-static-x64", + arm_host: "", stockfish: "yes", stockfish_arg: "ARCH=x86-64-modern COMP=mingw", ninja: "no", @@ -881,6 +918,7 @@ jobs: } - { image: "windows-static-x64-posix", + arm_host: "", stockfish: "yes", stockfish_arg: "ARCH=x86-64-modern COMP=mingw", ninja: "no", @@ -902,6 +940,7 @@ jobs: } - { image: "windows-shared-x64", + arm_host: "", stockfish: "no", stockfish_arg: "", ninja: "no", @@ -923,6 +962,7 @@ jobs: } - { image: "windows-shared-x64-posix", + arm_host: "", stockfish: "no", stockfish_arg: "", ninja: "no", @@ -945,6 +985,7 @@ jobs: # Windows x86 images - { image: "windows-static-x86", + arm_host: "", stockfish: "yes", stockfish_arg: "ARCH=x86-32-sse41-popcnt COMP=mingw", ninja: "no", @@ -966,6 +1007,7 @@ jobs: } - { image: "windows-shared-x86", + arm_host: "", stockfish: "no", stockfish_arg: "", ninja: "no", @@ -988,6 +1030,7 @@ jobs: # Windows arm images - { image: "windows-armv7", + arm_host: "", stockfish: "no", stockfish_arg: "ARCH=armv7-neon COMP=clang", ninja: "yes", @@ -1009,6 +1052,7 @@ jobs: } - { image: "windows-arm64", + arm_host: "", stockfish: "no", stockfish_arg: "ARCH=armv8 COMP=clang", ninja: "yes", @@ -1031,6 +1075,7 @@ jobs: # manylinux_2_28 images - { image: "manylinux_2_28-x64", + arm_host: "", stockfish: "yes", stockfish_arg: "ARCH=x86-64-modern", ninja: "yes", @@ -1053,6 +1098,7 @@ jobs: # manylinux2014 images - { image: "manylinux2014-x86", + arm_host: "", stockfish: "yes", stockfish_arg: "ARCH=x86-32-sse41-popcnt", ninja: "yes", @@ -1074,6 +1120,7 @@ jobs: } - { image: "manylinux2014-x64", + arm_host: "", stockfish: "yes", stockfish_arg: "ARCH=x86-64-modern", ninja: "yes", @@ -1095,6 +1142,7 @@ jobs: } - { image: "manylinux2014-aarch64", + arm_host: "", stockfish: "no", stockfish_arg: "", ninja: "no", @@ -1117,6 +1165,7 @@ jobs: # web-wasm images - { image: "web-wasm", + arm_host: "", stockfish: "no", stockfish_arg: "", ninja: "no", @@ -1138,6 +1187,7 @@ jobs: } - { image: "web-wasi", + arm_host: "", stockfish: "no", stockfish_arg: "", ninja: "no", @@ -1159,6 +1209,7 @@ jobs: } - { image: "web-wasi-threads", + arm_host: "", stockfish: "no", stockfish_arg: "", ninja: "no", @@ -1181,6 +1232,7 @@ jobs: # Bare metal images - { image: "bare-armv7emhf-nano_newlib", + arm_host: "", stockfish: "no", stockfish_arg: "", ninja: "no", @@ -1222,7 +1274,11 @@ jobs: - 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.arm_host }}" = "yes"; then + export BUILD_CMD="buildx build --platform linux/amd64,linux/arm64" + fi + make ${{ matrix.arch_name.image }} - name: basic test run: make ${{ matrix.arch_name.image }}.test From 7a62133ff73804cb97a80b8e10ad185484486ebc Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Thu, 4 Apr 2024 06:08:29 -0400 Subject: [PATCH 02/40] web-wasi: enable arm_host --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 608ac21..52b32ac 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1187,7 +1187,7 @@ jobs: } - { image: "web-wasi", - arm_host: "", + arm_host: "yes", stockfish: "no", stockfish_arg: "", ninja: "no", From b4592652434e341b060e23b30f4ab8874e15174d Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Fri, 5 Apr 2024 08:29:49 -0400 Subject: [PATCH 03/40] ci: setup qemu, buildx for standard image builds --- .github/workflows/main.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 52b32ac..9dc3b84 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1270,6 +1270,11 @@ jobs: - name: load base run: xz -d -k < ./cache/base.tar.xz | docker import - dockcross/base:latest + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 - name: build env: From 285ba494bf14e3c67141fec79fcecf9cb303322e Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Thu, 8 Aug 2024 12:54:18 -0400 Subject: [PATCH 04/40] Makefile: separate BUILD_DOCKER from TEST_DOCKER Enabling building with buildah, which only builds, and testing with podman. --- Makefile | 62 +++++++++++++++++++++++++++++++++----------------------- 1 file changed, 37 insertions(+), 25 deletions(-) diff --git a/Makefile b/Makefile index 020942a..a2e0d95 100644 --- a/Makefile +++ b/Makefile @@ -3,8 +3,19 @@ # 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)) +# 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,6 +23,7 @@ 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 @@ -125,8 +137,8 @@ $(GEN_IMAGE_DOCKERFILES) Dockerfile: %Dockerfile: %Dockerfile.in $(DOCKER_COMPOS 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) \ + $(TAG_FLAG) $(ORG)/web-wasm:latest \ --build-arg IMAGE=$(ORG)/web-wasm \ --build-arg VERSION=$(TAG) \ --build-arg VCS_REF=`git rev-parse --short HEAD` \ @@ -138,7 +150,7 @@ 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 + $(TEST_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" rm -rf web-wasm/test @@ -148,7 +160,7 @@ 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) \ + $(BUILD_DOCKER) $(BUILD_CMD) $(TAG_FLAG) $(ORG)/web-wasi-threads:$(TAG) \ -t $(ORG)/web-wasi-threads:latest \ --build-arg IMAGE=$(ORG)/web-wasi-threads \ --build-arg VERSION=$(TAG) \ @@ -158,7 +170,7 @@ web-wasi-threads: web-wasi web-wasi-threads/Dockerfile web-wasi-threads web-wasi-threads.test: web-wasi-threads - $(DOCKER) run $(RM) $(ORG)/web-wasi-threads:latest > $(BIN)/dockcross-web-wasi-threads \ + $(TEST_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 @@ -171,8 +183,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 +196,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 +205,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 +216,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 +225,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 +236,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 +245,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,7 +256,7 @@ 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 @@ -252,14 +264,14 @@ manylinux2014-x86.test: manylinux2014-x86 # 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 +286,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) \ @@ -293,9 +305,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,7 +319,7 @@ 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) From d0e5a437dd2588ddebe9c6fb76ac79d41b6f7bcf Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Thu, 26 Dec 2024 07:57:27 -0500 Subject: [PATCH 05/40] ci: bump runner to ubuntu-24.04 --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9dc3b84..4399ecc 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -12,7 +12,7 @@ on: jobs: base: name: base - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 steps: - name: checkout code uses: actions/checkout@v4 @@ -55,7 +55,7 @@ jobs: image: name: ${{ matrix.arch_name.image }} needs: base - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 env: OCI_EXE: docker strategy: From d9696e44b7759ca0060f96cb300bdfeb690227d1 Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Sun, 29 Dec 2024 16:12:33 -0500 Subject: [PATCH 06/40] add base-$(HOST_ARCH) and base-$(HOST_ARCH).test image targets These can be invoked via make base-amd64 make base-amd64.test make base-arm64 make base-arm64.test targets. Generates architecture specific flags. --- Makefile | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index a2e0d95..097a6ca 100644 --- a/Makefile +++ b/Makefile @@ -28,6 +28,9 @@ 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 @@ -58,6 +61,9 @@ 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 := web-wasi web-wasi-threads + GEN_IMAGE_DOCKERFILES = $(addsuffix /Dockerfile,$(GEN_IMAGES)) # These images are expected to have explicit rules for *both* build and testing @@ -261,8 +267,18 @@ manylinux2014-x86.test: 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/ $(BUILD_DOCKER) $(BUILD_CMD) $(TAG_FLAG) $(ORG)/base:latest \ $(TAG_FLAG) $(ORG)/base:$(TAG) \ From 88f3aa6c31031af1514b2e5caa43ce47cf82fdcf Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Sun, 29 Dec 2024 16:50:20 -0500 Subject: [PATCH 07/40] web-wasi: build as MULTIARCH_IMAGE --- Makefile | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 097a6ca..4189f8b 100644 --- a/Makefile +++ b/Makefile @@ -41,7 +41,6 @@ STANDARD_IMAGES := android-arm android-arm64 android-x86 android-x86_64 \ 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 @@ -62,7 +61,7 @@ GEN_IMAGES := android-arm android-arm64 \ bare-armv7emhf-nano_newlib # Generate both amd64 and arm64 images -MULTIARCH_IMAGES := web-wasi web-wasi-threads +MULTIARCH_IMAGES := web-wasi GEN_IMAGE_DOCKERFILES = $(addsuffix /Dockerfile,$(GEN_IMAGES)) @@ -78,7 +77,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 @@ -313,6 +312,19 @@ $(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 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 From 96d423101ca0d27eb0eba3ff0052db65c21adf6f Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Sun, 29 Dec 2024 17:25:34 -0500 Subject: [PATCH 08/40] web-wasi: add multiarch .test target --- Makefile | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Makefile b/Makefile index 4189f8b..b4d57ec 100644 --- a/Makefile +++ b/Makefile @@ -351,6 +351,12 @@ $(addsuffix .test,$(STANDARD_IMAGES)): $$(basename $$@) && chmod +x $(BIN)/dockcross-$(basename $@) $(BIN)/dockcross-$(basename $@) -i $(ORG)/$(basename $@):latest python3 test/run.py $($@_ARGS) +.SECONDEXPANSION: +$(addsuffix .test,$(MULTIARCH_IMAGES)): $$(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) + # # testing prerequisites implicit rule # From 72e51cae18bc6a1525c76f3f96958d542989fd01 Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Sun, 29 Dec 2024 17:38:54 -0500 Subject: [PATCH 09/40] Add web-wasi.push-amd64, web-wasi.push-arm64 targets --- Makefile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Makefile b/Makefile index b4d57ec..1ef2db8 100644 --- a/Makefile +++ b/Makefile @@ -357,6 +357,10 @@ $(addsuffix .test,$(MULTIARCH_IMAGES)): $$(basename $$@) && chmod +x $(BIN)/dockcross-$(basename $@) $(BIN)/dockcross-$(basename $@) -i $(ORG)/$(basename $@):latest-$(HOST_ARCH) python3 test/run.py $($@_ARGS) +.SECONDEXPANSION: +$(addsuffix .push-$(HOST_ARCH),$(MULTIARCH_IMAGES)): $$(basename $$@) + $(BUILD_DOCKER) push $(ORG)/$(basename $@):latest-$(HOST_ARCH) \ + && $(BUILD_DOCKER) push $(ORG)/$(basename $@):$(TAG)-$(HOST_ARCH) # # testing prerequisites implicit rule # From 5370aa6fe94fae3c5364e7523ec5c2d0bcb6baa7 Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Sun, 29 Dec 2024 17:54:08 -0500 Subject: [PATCH 10/40] web-wasi: add web-wasi.manifest command The docker executable currently has some of these `manifest` subcommands, but not all, and they are marked experimental, so use buildah. --- Makefile | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Makefile b/Makefile index 1ef2db8..35fd826 100644 --- a/Makefile +++ b/Makefile @@ -8,6 +8,7 @@ # 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: # @@ -361,6 +362,14 @@ $(addsuffix .test,$(MULTIARCH_IMAGES)): $$(basename $$@) $(addsuffix .push-$(HOST_ARCH),$(MULTIARCH_IMAGES)): $$(basename $$@) $(BUILD_DOCKER) push $(ORG)/$(basename $@):latest-$(HOST_ARCH) \ && $(BUILD_DOCKER) push $(ORG)/$(basename $@):$(TAG)-$(HOST_ARCH) + +.SECONDEXPANSION: +$(addsuffix .manifest,$(MULTIARCH_IMAGES)): $$(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 # # testing prerequisites implicit rule # From 508213170590d5dd3cb23ccb3dfdfdfe6f755def Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Sun, 29 Dec 2024 17:59:37 -0500 Subject: [PATCH 11/40] web-wasi: add web-wasi.push targets Pushes the complete manifest using the v2s2 format, which is required for proper architecture display in container registries. The --format v2s2 flag ensures compatibility with Docker Hub and other container registries. The --all flag ensures that both architecture variants are pushed along with the manifest. --- Makefile | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Makefile b/Makefile index 35fd826..5b44e26 100644 --- a/Makefile +++ b/Makefile @@ -370,6 +370,12 @@ $(addsuffix .manifest,$(MULTIARCH_IMAGES)): $$(basename $$@) $(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)): $$(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 # From 8cda4cf9621aacd84e7bbecf87dba859b4877942 Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Sun, 29 Dec 2024 18:59:52 -0500 Subject: [PATCH 12/40] web-wasi-threads: add .test, .push-$(HOST_ARCH) targets --- Makefile | 13 ++++--------- web-wasi-threads/Dockerfile.in | 2 +- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 5b44e26..b26ab02 100644 --- a/Makefile +++ b/Makefile @@ -166,8 +166,8 @@ 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/ - $(BUILD_DOCKER) $(BUILD_CMD) $(TAG_FLAG) $(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 VCS_REF=`git rev-parse --short HEAD` \ @@ -175,11 +175,6 @@ web-wasi-threads: web-wasi web-wasi-threads/Dockerfile --build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \ web-wasi-threads -web-wasi-threads.test: web-wasi-threads - $(TEST_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 # @@ -353,13 +348,13 @@ $(addsuffix .test,$(STANDARD_IMAGES)): $$(basename $$@) $(BIN)/dockcross-$(basename $@) -i $(ORG)/$(basename $@):latest python3 test/run.py $($@_ARGS) .SECONDEXPANSION: -$(addsuffix .test,$(MULTIARCH_IMAGES)): $$(basename $$@) +$(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 .push-$(HOST_ARCH),$(MULTIARCH_IMAGES)): $$(basename $$@) +$(addsuffix .push-$(HOST_ARCH),$(MULTIARCH_IMAGES) web-wasi-threads): $$(basename $$@) $(BUILD_DOCKER) push $(ORG)/$(basename $@):latest-$(HOST_ARCH) \ && $(BUILD_DOCKER) push $(ORG)/$(basename $@):$(TAG)-$(HOST_ARCH) diff --git a/web-wasi-threads/Dockerfile.in b/web-wasi-threads/Dockerfile.in index 5f75c21..3f471ee 100644 --- a/web-wasi-threads/Dockerfile.in +++ b/web-wasi-threads/Dockerfile.in @@ -6,6 +6,6 @@ LABEL maintainer="Matt McCormick matt@mmmccormick.com" ENV CROSS_TRIPLE=wasm32-wasi-threads 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" From 6bf03cc540462cd4c7a438ff80742f1c52d4e800 Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Sun, 29 Dec 2024 19:10:17 -0500 Subject: [PATCH 13/40] web-wasi-threads: FROM uses HOST_ARCH --- Makefile | 1 + web-wasi-threads/Dockerfile.in | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index b26ab02..69552b1 100644 --- a/Makefile +++ b/Makefile @@ -170,6 +170,7 @@ web-wasi-threads: web-wasi web-wasi-threads/Dockerfile -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"` \ diff --git a/web-wasi-threads/Dockerfile.in b/web-wasi-threads/Dockerfile.in index 3f471ee..7a09eef 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" From 599f950297c9f3e5bf7dfe0f3eede61e3fef849d Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Sun, 29 Dec 2024 19:14:15 -0500 Subject: [PATCH 14/40] web-wasi-threads: add .push, .manifest targets --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 69552b1..f74b7b6 100644 --- a/Makefile +++ b/Makefile @@ -360,7 +360,7 @@ $(addsuffix .push-$(HOST_ARCH),$(MULTIARCH_IMAGES) web-wasi-threads): $$(basenam && $(BUILD_DOCKER) push $(ORG)/$(basename $@):$(TAG)-$(HOST_ARCH) .SECONDEXPANSION: -$(addsuffix .manifest,$(MULTIARCH_IMAGES)): $$(basename $$@) +$(addsuffix .manifest,$(MULTIARCH_IMAGES) web-wasi-threads): $$(basename $$@) if $(BUILDAH) manifest exists $(ORG)/$(basename $@); then \ $(BUILDAH) manifest rm $(ORG)/$(basename $@); fi $(BUILDAH) manifest create $(ORG)/$(basename $@) @@ -368,7 +368,7 @@ $(addsuffix .manifest,$(MULTIARCH_IMAGES)): $$(basename $$@) $(BUILDAH) manifest add $(ORG)/$(basename $@) docker://$(ORG)/$(basename $@):latest-arm64 .SECONDEXPANSION: -$(addsuffix .push,$(MULTIARCH_IMAGES)): $$(basename $$@).manifest +$(addsuffix .push,$(MULTIARCH_IMAGES) web-wasi-threads): $$(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) From d3dc3ed8e8b6dc6362f5a988f2c7d28fed6adb8b Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Sun, 29 Dec 2024 19:36:29 -0500 Subject: [PATCH 15/40] web-wasm: support arm64 builds --- Makefile | 15 +++++++++++---- web-wasm/Dockerfile.in | 3 ++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index f74b7b6..3053fe3 100644 --- a/Makefile +++ b/Makefile @@ -140,13 +140,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/ - $(BUILD_DOCKER) $(BUILD_CMD) $(TAG_FLAG) $(ORG)/web-wasm:$(TAG) \ - $(TAG_FLAG) $(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"` \ @@ -156,8 +163,8 @@ web-wasm: web-wasm/Dockerfile web-wasm.test: web-wasm cp -r test web-wasm/ - $(TEST_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 # diff --git a/web-wasm/Dockerfile.in b/web-wasm/Dockerfile.in index 1091ff2..4f23eac 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" From c1cf751a3168b3333d17af6d3a82ffac9342a0a2 Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Sun, 29 Dec 2024 19:39:10 -0500 Subject: [PATCH 16/40] web-wasm: use = for ENV Dockerfile commands --- web-wasm/Dockerfile.in | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/web-wasm/Dockerfile.in b/web-wasm/Dockerfile.in index 4f23eac..d0146fc 100644 --- a/web-wasm/Dockerfile.in +++ b/web-wasm/Dockerfile.in @@ -58,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" From 8cdda7ec644ecddc922b7c9106368c8d52924296 Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Sun, 29 Dec 2024 19:46:32 -0500 Subject: [PATCH 17/40] web-wasm: add .push-$(HOST_ARCH), .manifest, .push targets --- Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 3053fe3..64b0bf0 100644 --- a/Makefile +++ b/Makefile @@ -362,12 +362,12 @@ $(addsuffix .test,$(MULTIARCH_IMAGES) web-wasi-threads): $$(basename $$@) $(BIN)/dockcross-$(basename $@) -i $(ORG)/$(basename $@):latest-$(HOST_ARCH) python3 test/run.py $($@_ARGS) .SECONDEXPANSION: -$(addsuffix .push-$(HOST_ARCH),$(MULTIARCH_IMAGES) web-wasi-threads): $$(basename $$@) +$(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 .manifest,$(MULTIARCH_IMAGES) web-wasi-threads): $$(basename $$@) +$(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 $@) @@ -375,7 +375,7 @@ $(addsuffix .manifest,$(MULTIARCH_IMAGES) web-wasi-threads): $$(basename $$@) $(BUILDAH) manifest add $(ORG)/$(basename $@) docker://$(ORG)/$(basename $@):latest-arm64 .SECONDEXPANSION: -$(addsuffix .push,$(MULTIARCH_IMAGES) web-wasi-threads): $$(basename $$@).manifest +$(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) From 180160da5055da830b59fdb4c521b4c32b803a49 Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Sun, 29 Dec 2024 19:57:20 -0500 Subject: [PATCH 18/40] linux-arm64: use new ENV syntax --- linux-arm64/Dockerfile.in | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/linux-arm64/Dockerfile.in b/linux-arm64/Dockerfile.in index bb7ab54..c1d7aeb 100644 --- a/linux-arm64/Dockerfile.in +++ b/linux-arm64/Dockerfile.in @@ -6,7 +6,7 @@ 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 +18,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 +29,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" From 7631cba894d66297b8a2b725d3b670c89f3e1ce9 Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Sun, 29 Dec 2024 19:57:58 -0500 Subject: [PATCH 19/40] linux-arm64: build as multiarch image --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 64b0bf0..a6c3aa1 100644 --- a/Makefile +++ b/Makefile @@ -37,7 +37,7 @@ 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 \ @@ -62,7 +62,7 @@ GEN_IMAGES := android-arm android-arm64 \ bare-armv7emhf-nano_newlib # Generate both amd64 and arm64 images -MULTIARCH_IMAGES := web-wasi +MULTIARCH_IMAGES := web-wasi linux-arm64 GEN_IMAGE_DOCKERFILES = $(addsuffix /Dockerfile,$(GEN_IMAGES)) From 306612b685fff451a4d6d954d2b115960040b986 Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Sun, 29 Dec 2024 20:19:33 -0500 Subject: [PATCH 20/40] ci: define base-multiarch job And remove buildx emulated multiarch build. --- .github/workflows/main.yml | 66 +++++++++++++++++++++++++++++++++----- 1 file changed, 58 insertions(+), 8 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4399ecc..bb403bc 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -20,18 +20,12 @@ 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 + env: + OCI_EXE: docker run: make base.test - name: archive base @@ -52,6 +46,62 @@ jobs: docker login -u ${{ secrets.DOCKER_USER }} -p ${{ secrets.DOCKER_PASS }} docker image push dockcross/base --all-tags + base-multiarch: + name: base-multiarch + runs-on: ${{ matrix.os }} + strategy: + max-parallel: 5 + matrix: + os: [ubuntu-22.04, macos-15] + steps: + - name: checkout code + uses: actions/checkout@v4 + with: + submodules: "recursive" + fetch-depth: 1 + + - name: setup macos docker + if: ${{ matrix.os == 'macos-15' }} + run: | + # https://github.com/abiosoft/colima/issues/970 + brew install qemu docker colima + LIMACTL_PATH=$(brew --prefix)/bin/limactl + sudo curl -L -o $LIMACTL_PATH https://github.com/mikekazakov/lima-nohvf/raw/master/limactl + sudo chmod +x $LIMACTL_PATH + colima start --network-address --arch arm64 --cpu 3 --memory 6 + + - name: build multiarch + run: | + host_arch=$(uname -m | sed -e 's/x86_64/amd64/' -e 's/aarch64/arm64/') + make base-${host_arch} + + - name: test multiarch + env: + OCI_EXE: docker + run: | + host_arch=$(uname -m | sed -e 's/x86_64/amd64/' -e 's/aarch64/arm64/') + mkdir -p bin + make base-${host_arch}.test + + - name: archive base + run: | + host_arch=$(uname -m | sed -e 's/x86_64/amd64/' -e 's/aarch64/arm64/') + mkdir -p cache + docker export dockcross/base:latest-${host_arch} | xz -e9 -T0 > ./cache/base.tar.xz + + - name: save base + uses: actions/upload-artifact@v4 + with: + name: cache-${{ matrix.os }} + path: ./cache + retention-days: 3 + + - 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 From 10b1c1d579efe32ed285a0648ab6961a0febda69 Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Mon, 6 Jan 2025 15:21:00 -0500 Subject: [PATCH 21/40] wasi: fix threads option specification for wasmtime In recent wasmtime, `-S` flags need to come after `run`. Also add `-W threads=y` following the wasmtime test suite, - https://github.com/bytecodealliance/wasmtime/blob/fc3c868b13bccf5d7ed26de4cfd1a2dc4c689360/tests/all/cli_tests.rs#L580-L581 Also explicity enable the `cli` feature because this is used for CMake try_run. --- imagefiles/wasmtime-pwd-threads.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imagefiles/wasmtime-pwd-threads.sh b/imagefiles/wasmtime-pwd-threads.sh index b9f8a98..62b160c 100755 --- a/imagefiles/wasmtime-pwd-threads.sh +++ b/imagefiles/wasmtime-pwd-threads.sh @@ -1,4 +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/ "$@" +exec ${WASMTIME_HOME}/bin/wasmtime run -W threads=y -S threads=y,cli=y --dir=. --dir=$PWD --dir=/work/ "$@" From 741af4cb067b31f7f0711f848f6d3878ee1bd1ad Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Mon, 6 Jan 2025 15:53:16 -0500 Subject: [PATCH 22/40] web-wasi: FROM base:latest-${HOST_ARCH} --- web-wasi/Dockerfile.in | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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" From 86044ff4b3df84afdfd3659f0e18276bb4a4871d Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Mon, 6 Jan 2025 16:12:13 -0500 Subject: [PATCH 23/40] linux-arm64: FROM base:latest-${HOST_ARCH} --- linux-arm64/Dockerfile.in | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/linux-arm64/Dockerfile.in b/linux-arm64/Dockerfile.in index c1d7aeb..aed2c14 100644 --- a/linux-arm64/Dockerfile.in +++ b/linux-arm64/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" From 96e8620255b795b79e3413c6126a71655e753446 Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Mon, 6 Jan 2025 16:13:59 -0500 Subject: [PATCH 24/40] multiarch: pass HOST_ARCH build-arg --- Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index a6c3aa1..d89f87c 100644 --- a/Makefile +++ b/Makefile @@ -62,7 +62,8 @@ GEN_IMAGES := android-arm android-arm64 \ bare-armv7emhf-nano_newlib # Generate both amd64 and arm64 images -MULTIARCH_IMAGES := web-wasi linux-arm64 +MULTIARCH_IMAGES := linux-arm64 \ + web-wasi GEN_IMAGE_DOCKERFILES = $(addsuffix /Dockerfile,$(GEN_IMAGES)) @@ -322,6 +323,7 @@ $(MULTIARCH_IMAGES): %: %/Dockerfile base-$(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` \ From aac97dfb18afe850840b5e72190637c3444a3ffc Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Tue, 7 Jan 2025 10:59:10 -0500 Subject: [PATCH 25/40] web-wasi-threads: use target wasm32-wasi-threads in sysroot wrapper And add -pthread flag. --- web-wasi-threads/Dockerfile.in | 4 ++++ web-wasi-threads/Toolchain.cmake | 4 ++-- web-wasi-threads/clang++-wasi-threads-sysroot.sh | 3 +++ web-wasi-threads/clang-wasi-threads-sysroot.sh | 3 +++ 4 files changed, 12 insertions(+), 2 deletions(-) create mode 100755 web-wasi-threads/clang++-wasi-threads-sysroot.sh create mode 100755 web-wasi-threads/clang-wasi-threads-sysroot.sh diff --git a/web-wasi-threads/Dockerfile.in b/web-wasi-threads/Dockerfile.in index 7a09eef..d1fb440 100644 --- a/web-wasi-threads/Dockerfile.in +++ b/web-wasi-threads/Dockerfile.in @@ -4,7 +4,11 @@ FROM ${ORG}/web-wasi:latest-${HOST_ARCH} LABEL maintainer="Matt McCormick matt@mmmccormick.com" +COPY clang-wasi-threads-sysroot.sh clang++-wasi-threads-sysroot.sh /usr/local/bin/ + ENV CROSS_TRIPLE=wasm32-wasi-threads +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 diff --git a/web-wasi-threads/Toolchain.cmake b/web-wasi-threads/Toolchain.cmake index 53985b4..326702c 100644 --- a/web-wasi-threads/Toolchain.cmake +++ b/web-wasi-threads/Toolchain.cmake @@ -4,7 +4,7 @@ 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_C_COMPILER /usr/local/bin/clang-wasi-threads-sysroot.sh) +set(CMAKE_CXX_COMPILER /usr/local/bin/clang++-wasi-threads-sysroot.sh) set(CMAKE_CROSSCOMPILING_EMULATOR /wasi-runtimes/wasmtime/bin/wasmtime-pwd-threads.sh) diff --git a/web-wasi-threads/clang++-wasi-threads-sysroot.sh b/web-wasi-threads/clang++-wasi-threads-sysroot.sh new file mode 100755 index 0000000..1d9cdff --- /dev/null +++ b/web-wasi-threads/clang++-wasi-threads-sysroot.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env sh + +exec ${WASI_SDK_PATH}/bin/clang++ -pthread --target=wasm32-wasi-threads --sysroot=${WASI_SYSROOT} "$@" diff --git a/web-wasi-threads/clang-wasi-threads-sysroot.sh b/web-wasi-threads/clang-wasi-threads-sysroot.sh new file mode 100755 index 0000000..8728f23 --- /dev/null +++ b/web-wasi-threads/clang-wasi-threads-sysroot.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env sh + +exec ${WASI_SDK_PATH}/bin/clang -pthread --target=wasm32-wasi-threads --sysroot=${WASI_SYSROOT} "$@" From 1d459d9fbc8b0973c3db44ca764df036c3957b5e Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Fri, 17 Jan 2025 14:54:47 -0500 Subject: [PATCH 26/40] ci: build multiarch base with ubuntu-22.04-arm macos-15 (arm) still requires emulation and is too slow. --- .github/workflows/main.yml | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index bb403bc..7778bea 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -52,7 +52,7 @@ jobs: strategy: max-parallel: 5 matrix: - os: [ubuntu-22.04, macos-15] + os: [ubuntu-22.04, ubuntu-22.04-arm] steps: - name: checkout code uses: actions/checkout@v4 @@ -60,16 +60,6 @@ jobs: submodules: "recursive" fetch-depth: 1 - - name: setup macos docker - if: ${{ matrix.os == 'macos-15' }} - run: | - # https://github.com/abiosoft/colima/issues/970 - brew install qemu docker colima - LIMACTL_PATH=$(brew --prefix)/bin/limactl - sudo curl -L -o $LIMACTL_PATH https://github.com/mikekazakov/lima-nohvf/raw/master/limactl - sudo chmod +x $LIMACTL_PATH - colima start --network-address --arch arm64 --cpu 3 --memory 6 - - name: build multiarch run: | host_arch=$(uname -m | sed -e 's/x86_64/amd64/' -e 's/aarch64/arm64/') From c0efd5bf10dd7678172194c7c02885486e07a05f Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Wed, 22 Jan 2025 16:26:14 -0500 Subject: [PATCH 27/40] web-wasi-emulated-threads: initial addition Todos: - Add to CI if possible (builds LLVM/Clang) - Add to README --- Makefile | 6 +- common/common.webassembly | 4 +- web-wasi-emulated-threads/CheckTypeSize.c.in | 37 +++ web-wasi-emulated-threads/CheckTypeSize.cmake | 231 ++++++++++++++++++ web-wasi-emulated-threads/Dockerfile.in | 42 ++++ web-wasi-emulated-threads/FindOpenAL.cmake | 25 ++ web-wasi-emulated-threads/FindOpenGL.cmake | 34 +++ web-wasi-emulated-threads/TestBigEndian.cmake | 30 +++ web-wasi-emulated-threads/Toolchain.cmake | 14 ++ web-wasi-emulated-threads/WASI.cmake | 2 + .../clang++-wasi-sysroot.sh | 3 + .../clang-wasi-sysroot.sh | 3 + .../download-build-install-wasi-sdk.sh | 36 +++ 13 files changed, 462 insertions(+), 5 deletions(-) create mode 100644 web-wasi-emulated-threads/CheckTypeSize.c.in create mode 100644 web-wasi-emulated-threads/CheckTypeSize.cmake create mode 100644 web-wasi-emulated-threads/Dockerfile.in create mode 100644 web-wasi-emulated-threads/FindOpenAL.cmake create mode 100644 web-wasi-emulated-threads/FindOpenGL.cmake create mode 100644 web-wasi-emulated-threads/TestBigEndian.cmake create mode 100644 web-wasi-emulated-threads/Toolchain.cmake create mode 100644 web-wasi-emulated-threads/WASI.cmake create mode 100755 web-wasi-emulated-threads/clang++-wasi-sysroot.sh create mode 100755 web-wasi-emulated-threads/clang-wasi-sysroot.sh create mode 100755 web-wasi-emulated-threads/download-build-install-wasi-sdk.sh diff --git a/Makefile b/Makefile index d89f87c..8e5805a 100644 --- a/Makefile +++ b/Makefile @@ -52,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 \ @@ -63,13 +63,13 @@ GEN_IMAGES := android-arm android-arm64 \ # Generate both amd64 and arm64 images MULTIARCH_IMAGES := linux-arm64 \ - web-wasi + 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 \ 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/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 + From 2b491aeb9a3731df3697dcc53147ae188db52459 Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Tue, 21 Jan 2025 13:36:14 -0500 Subject: [PATCH 28/40] ci: build multiarch images --- .github/workflows/main.yml | 188 ++++++++++++++++++++----------------- 1 file changed, 102 insertions(+), 86 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7778bea..296ebbf 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 @@ -24,8 +27,6 @@ jobs: run: make base - name: test - env: - OCI_EXE: docker run: make base.test - name: archive base @@ -60,24 +61,23 @@ jobs: 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: | - host_arch=$(uname -m | sed -e 's/x86_64/amd64/' -e 's/aarch64/arm64/') - make base-${host_arch} + make base-${{ env.HOST_ARCH }} - name: test multiarch - env: - OCI_EXE: docker run: | - host_arch=$(uname -m | sed -e 's/x86_64/amd64/' -e 's/aarch64/arm64/') mkdir -p bin - make base-${host_arch}.test + make base-${{ env.HOST_ARCH }}.test - name: archive base run: | - host_arch=$(uname -m | sed -e 's/x86_64/amd64/' -e 's/aarch64/arm64/') mkdir -p cache - docker export dockcross/base:latest-${host_arch} | xz -e9 -T0 > ./cache/base.tar.xz + docker export dockcross/base:latest-${{ env.HOST_ARCH }} | xz -e9 -T0 > ./cache/base.tar.xz - name: save base uses: actions/upload-artifact@v4 @@ -93,19 +93,18 @@ jobs: docker image push dockcross/base --all-tags image: - name: ${{ matrix.arch_name.image }} - needs: base - runs-on: ubuntu-24.04 - env: - OCI_EXE: docker + name: ${{ matrix.arch_name.image }}_on_${{ matrix.os }} + needs: [base, base-multiarch] + runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: + os: [ubuntu-22.04, ubuntu-22.04-arm] arch_name: # Android images - { image: "android-arm", - arm_host: "", + multiarch: "", stockfish: "yes", stockfish_arg: "ARCH=armv7 COMP=ndk", ninja: "no", @@ -127,7 +126,7 @@ jobs: } - { image: "android-arm64", - arm_host: "", + multiarch: "", stockfish: "yes", stockfish_arg: "ARCH=armv8 COMP=ndk", ninja: "no", @@ -149,7 +148,7 @@ jobs: } - { image: "android-x86", - arm_host: "", + multiarch: "", stockfish: "yes", stockfish_arg: "ARCH=x86-32 COMP=ndk", ninja: "no", @@ -171,7 +170,7 @@ jobs: } - { image: "android-x86_64", - arm_host: "", + multiarch: "", stockfish: "yes", stockfish_arg: "ARCH=x86-64 COMP=ndk", ninja: "no", @@ -194,7 +193,7 @@ jobs: # Linux arm64/armv8 images - { image: "linux-arm64", - arm_host: "", + multiarch: "", stockfish: "yes", stockfish_arg: "ARCH=armv8", ninja: "yes", @@ -216,7 +215,7 @@ jobs: } - { image: "linux-arm64-lts", - arm_host: "", + multiarch: "", stockfish: "yes", stockfish_arg: "ARCH=armv8", ninja: "yes", @@ -238,7 +237,7 @@ jobs: } - { image: "linux-arm64-musl", - arm_host: "", + multiarch: "", stockfish: "yes", stockfish_arg: "ARCH=armv8", ninja: "yes", @@ -260,7 +259,7 @@ jobs: } - { image: "linux-arm64-full", - arm_host: "", + multiarch: "", stockfish: "yes", stockfish_arg: "ARCH=armv8", ninja: "yes", @@ -283,7 +282,7 @@ jobs: # Linux mipel images - { image: "linux-mipsel-lts", - arm_host: "", + multiarch: "", stockfish: "no", stockfish_arg: "", ninja: "no", @@ -306,7 +305,7 @@ jobs: # Linux armv5 images - { image: "linux-armv5", - arm_host: "", + multiarch: "", stockfish: "no", stockfish_arg: "", ninja: "yes", @@ -328,7 +327,7 @@ jobs: } - { image: "linux-armv5-musl", - arm_host: "", + multiarch: "", stockfish: "no", stockfish_arg: "", ninja: "yes", @@ -350,7 +349,7 @@ jobs: } - { image: "linux-armv5-uclibc", - arm_host: "", + multiarch: "", stockfish: "no", stockfish_arg: "", ninja: "yes", @@ -373,7 +372,7 @@ jobs: # Linux armv6 images - { image: "linux-armv6", - arm_host: "", + multiarch: "", stockfish: "no", stockfish_arg: "", ninja: "yes", @@ -395,7 +394,7 @@ jobs: } - { image: "linux-armv6-lts", - arm_host: "", + multiarch: "", stockfish: "no", stockfish_arg: "", ninja: "yes", @@ -417,7 +416,7 @@ jobs: } - { image: "linux-armv6-musl", - arm_host: "", + multiarch: "", stockfish: "no", stockfish_arg: "", ninja: "yes", @@ -440,7 +439,7 @@ jobs: # Linux armv7 images - { image: "linux-armv7", - arm_host: "", + multiarch: "", stockfish: "yes", stockfish_arg: "ARCH=armv7", ninja: "yes", @@ -462,7 +461,7 @@ jobs: } - { image: "linux-armv7a", - arm_host: "", + multiarch: "", stockfish: "yes", stockfish_arg: "ARCH=armv7-neon", ninja: "yes", @@ -484,7 +483,7 @@ jobs: } - { image: "linux-armv7a-lts", - arm_host: "", + multiarch: "", stockfish: "yes", stockfish_arg: "ARCH=armv7-neon", ninja: "yes", @@ -506,7 +505,7 @@ jobs: } - { image: "linux-armv7-lts", - arm_host: "", + multiarch: "", stockfish: "yes", stockfish_arg: "ARCH=armv7", ninja: "yes", @@ -528,7 +527,7 @@ jobs: } - { image: "linux-armv7l-musl", - arm_host: "", + multiarch: "", stockfish: "yes", stockfish_arg: "ARCH=armv7", ninja: "yes", @@ -551,7 +550,7 @@ jobs: # Linux x86 images - { image: "linux-x86", - arm_host: "", + multiarch: "", stockfish: "yes", stockfish_arg: "ARCH=x86-32-sse41-popcnt", ninja: "yes", @@ -574,7 +573,7 @@ jobs: # Linux i686 images - { image: "linux-i686", - arm_host: "", + multiarch: "", stockfish: "no", stockfish_arg: "", ninja: "yes", @@ -597,7 +596,7 @@ jobs: # Linux x86_64 images - { image: "linux-x64", - arm_host: "", + multiarch: "", stockfish: "yes", stockfish_arg: "ARCH=x86-64-modern", ninja: "yes", @@ -619,7 +618,7 @@ jobs: } - { image: "linux-x64-tinycc", - arm_host: "", + multiarch: "", stockfish: "yes", stockfish_arg: "ARCH=x86-64-modern", ninja: "yes", @@ -641,7 +640,7 @@ jobs: } - { image: "linux-x64-clang", - arm_host: "", + multiarch: "", stockfish: "yes", stockfish_arg: "ARCH=x86-64-modern COMP=clang", ninja: "yes", @@ -663,7 +662,7 @@ jobs: } - { image: "linux-x86_64-full", - arm_host: "", + multiarch: "", stockfish: "yes", stockfish_arg: "ARCH=x86-64-modern", ninja: "yes", @@ -686,7 +685,7 @@ jobs: # Linux riscv images - { image: "linux-riscv32", - arm_host: "", + multiarch: "", stockfish: "no", stockfish_arg: "", ninja: "yes", @@ -708,7 +707,7 @@ jobs: } - { image: "linux-riscv64", - arm_host: "", + multiarch: "", stockfish: "no", stockfish_arg: "", ninja: "yes", @@ -731,7 +730,7 @@ jobs: # Linux s390x images - { image: "linux-s390x", - arm_host: "", + multiarch: "", stockfish: "no", stockfish_arg: "", ninja: "yes", @@ -754,7 +753,7 @@ jobs: # Linux mips images - { image: "linux-mips", - arm_host: "", + multiarch: "", stockfish: "no", stockfish_arg: "", ninja: "yes", @@ -776,7 +775,7 @@ jobs: } - { image: "linux-mips-uclibc", - arm_host: "", + multiarch: "", stockfish: "no", stockfish_arg: "", ninja: "yes", @@ -799,7 +798,7 @@ jobs: # Linux mips images - { image: "linux-mips-lts", - arm_host: "", + multiarch: "", stockfish: "no", stockfish_arg: "", ninja: "yes", @@ -844,7 +843,7 @@ jobs: # Linux ppc64le images - { image: "linux-ppc64le", - arm_host: "", + multiarch: "", stockfish: "yes", stockfish_arg: "ARCH=ppc-64", ninja: "yes", @@ -867,7 +866,7 @@ jobs: # Linux ppc64le-lts images - { image: "linux-ppc64le-lts", - arm_host: "", + multiarch: "", stockfish: "yes", stockfish_arg: "ARCH=ppc-64", ninja: "yes", @@ -890,7 +889,7 @@ jobs: # Linux m68k images - { image: "linux-m68k-uclibc", - arm_host: "", + multiarch: "", stockfish: "no", stockfish_arg: "", ninja: "no", @@ -913,7 +912,7 @@ jobs: # Linux xtensa images - { image: "linux-xtensa-uclibc", - arm_host: "", + multiarch: "", stockfish: "no", stockfish_arg: "", ninja: "yes", @@ -936,7 +935,7 @@ jobs: # Windows x86_x64 images - { image: "windows-static-x64", - arm_host: "", + multiarch: "", stockfish: "yes", stockfish_arg: "ARCH=x86-64-modern COMP=mingw", ninja: "no", @@ -958,7 +957,7 @@ jobs: } - { image: "windows-static-x64-posix", - arm_host: "", + multiarch: "", stockfish: "yes", stockfish_arg: "ARCH=x86-64-modern COMP=mingw", ninja: "no", @@ -980,7 +979,7 @@ jobs: } - { image: "windows-shared-x64", - arm_host: "", + multiarch: "", stockfish: "no", stockfish_arg: "", ninja: "no", @@ -1002,7 +1001,7 @@ jobs: } - { image: "windows-shared-x64-posix", - arm_host: "", + multiarch: "", stockfish: "no", stockfish_arg: "", ninja: "no", @@ -1025,7 +1024,7 @@ jobs: # Windows x86 images - { image: "windows-static-x86", - arm_host: "", + multiarch: "", stockfish: "yes", stockfish_arg: "ARCH=x86-32-sse41-popcnt COMP=mingw", ninja: "no", @@ -1047,7 +1046,7 @@ jobs: } - { image: "windows-shared-x86", - arm_host: "", + multiarch: "", stockfish: "no", stockfish_arg: "", ninja: "no", @@ -1070,7 +1069,7 @@ jobs: # Windows arm images - { image: "windows-armv7", - arm_host: "", + multiarch: "", stockfish: "no", stockfish_arg: "ARCH=armv7-neon COMP=clang", ninja: "yes", @@ -1092,7 +1091,7 @@ jobs: } - { image: "windows-arm64", - arm_host: "", + multiarch: "", stockfish: "no", stockfish_arg: "ARCH=armv8 COMP=clang", ninja: "yes", @@ -1115,7 +1114,7 @@ jobs: # manylinux_2_28 images - { image: "manylinux_2_28-x64", - arm_host: "", + multiarch: "", stockfish: "yes", stockfish_arg: "ARCH=x86-64-modern", ninja: "yes", @@ -1138,7 +1137,7 @@ jobs: # manylinux2014 images - { image: "manylinux2014-x86", - arm_host: "", + multiarch: "", stockfish: "yes", stockfish_arg: "ARCH=x86-32-sse41-popcnt", ninja: "yes", @@ -1160,7 +1159,7 @@ jobs: } - { image: "manylinux2014-x64", - arm_host: "", + multiarch: "", stockfish: "yes", stockfish_arg: "ARCH=x86-64-modern", ninja: "yes", @@ -1182,7 +1181,7 @@ jobs: } - { image: "manylinux2014-aarch64", - arm_host: "", + multiarch: "", stockfish: "no", stockfish_arg: "", ninja: "no", @@ -1205,7 +1204,7 @@ jobs: # web-wasm images - { image: "web-wasm", - arm_host: "", + multiarch: "", stockfish: "no", stockfish_arg: "", ninja: "no", @@ -1227,7 +1226,7 @@ jobs: } - { image: "web-wasi", - arm_host: "yes", + multiarch: "yes", stockfish: "no", stockfish_arg: "", ninja: "no", @@ -1249,7 +1248,7 @@ jobs: } - { image: "web-wasi-threads", - arm_host: "", + multiarch: "", stockfish: "no", stockfish_arg: "", ninja: "no", @@ -1272,7 +1271,7 @@ jobs: # Bare metal images - { image: "bare-armv7emhf-nano_newlib", - arm_host: "", + multiarch: "", stockfish: "no", stockfish_arg: "", ninja: "no", @@ -1303,6 +1302,9 @@ jobs: submodules: "recursive" fetch-depth: 1 + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - uses: actions/download-artifact@v4 with: name: cache @@ -1310,27 +1312,41 @@ jobs: - name: load base run: xz -d -k < ./cache/base.tar.xz | docker import - dockcross/base:latest - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 + - uses: actions/download-artifact@v4 + with: + name: cache-${{ matrix.os }} + path: ./cache + + - name: load multiarch base + run: xz -d -k < ./cache/base.tar.xz | docker import - dockcross/base:latest + + - name: load base + run: xz -d -k < ./cache/base.tar.xz | docker import - dockcross/base:latest + + - name: set host_arch + run: | + echo "HOST_ARCH=$(uname -m | sed -e 's/x86_64/amd64/' -e 's/aarch64/arm64/')" >> $GITHUB_ENV - name: build env: BUILD_CMD: build --cache-from type=gha --cache-to type=gha,mode=max run: | - if test "${{ matrix.arch_name.arm_host }}" = "yes"; then - export BUILD_CMD="buildx build --platform linux/amd64,linux/arm64" + 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 - make ${{ matrix.arch_name.image }} - 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 @@ -1341,7 +1357,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 @@ -1349,7 +1365,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 @@ -1362,7 +1378,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 @@ -1373,7 +1389,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 @@ -1384,7 +1400,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 @@ -1395,7 +1411,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 @@ -1405,7 +1421,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 @@ -1416,7 +1432,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 @@ -1427,7 +1443,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 @@ -1438,7 +1454,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 From 07ac7479b5bd769b932bba20aaa41485db89ec6c Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Fri, 24 Jan 2025 16:50:59 -0500 Subject: [PATCH 29/40] Makefile: add .push target for STANDARD and NON_STANDARD images The same .push target that MULTIARCH_IMAGES uses can be used for these images. --- Makefile | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Makefile b/Makefile index 8e5805a..9e90efc 100644 --- a/Makefile +++ b/Makefile @@ -368,6 +368,11 @@ $(addsuffix .push-$(HOST_ARCH),$(MULTIARCH_IMAGES) web-wasi-threads web-wasm): $ $(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 \ From f473b99340a240650c962744c8bf5eb44071fd14 Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Fri, 7 Feb 2025 16:28:46 -0500 Subject: [PATCH 30/40] ci: multi-arch deploy Upload artifacts for the multi-arch images, then download, load them, and deploy them along with multi-arch manifests after both finished building. --- .github/workflows/main.yml | 83 ++++++++++++++++++++++++++++++++++++-- Makefile | 5 +++ 2 files changed, 85 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 296ebbf..3ca9db5 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -126,7 +126,7 @@ jobs: } - { image: "android-arm64", - multiarch: "", + multiarch: "yes", stockfish: "yes", stockfish_arg: "ARCH=armv8 COMP=ndk", ninja: "no", @@ -1469,8 +1469,85 @@ jobs: cd .. rm -rf libopencm3 - - name: deploy + - name: archive ${{ matrix.arch_name.image }}-${{ matrix.os }} + 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 + fi + + - 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: deploy-not-multi-arch + if: github.ref == 'refs/heads/master' && matrix.arch_name.multiarch != 'yes' && env.HOST_ARCH == 'amd64' + run: | + docker login -u ${{ secrets.DOCKER_USER }} -p ${{ secrets.DOCKER_PASS }} + make ${{ matrix.arch_name.image }}.push + + deploy-multi-arch-images: + name: ${{ matrix.arch_name.image }} + needs: [${{ matrix.arch_name.image }}_on_ubuntu-22.04, ${{ matrix.arch_name.image }}_on_ubuntu-22.04-arm] + runs-on: ubuntu-22.04 + strategy: + fail-fast: false + matrix: + arch_name: + - { + image: "android-arm64" + } + - { + image: "web-wasm", + } + - { + image: "web-wasi", + } + - { + image: "web-wasi-threads", + } + + - 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: download ${{ matrix.arch_name.image }}-amd64 + uses: actions/download-artifact@v4 + with: + name: cache-${{ matrix.arch_name.image }}-amd64 + path: ./cache/${{ matrix.arch_name.image }}-amd64.tar.xz + + - name: download ${{ matrix.arch_name.image }}-arm64 + uses: actions/download-artifact@v4 + with: + name: cache-${{ matrix.arch_name.image }}-arm64 + path: ./cache/${{ matrix.arch_name.image }}-arm64.xz + + - name: load images + run: | + xz -d -k < ./cache/${{ matrix.arch_name.image }}-amd64.tar.xz | docker import - dockcross/${{ matrix.arch_name.image }}-amd64 + xz -d -k < ./cache/${{ matrix.arch_name.image }}-arm64.tar.xz | docker import - dockcross/${{ matrix.arch_name.image }}-arm64 + + - 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.arch_name.image }}.tag-amd64 + make ${{ matrix.arch_name.image }}.tag-arm64 + + make ${{ matrix.arch_name.image }}.push-amd64 + make ${{ matrix.arch_name.image }}.push-arm64 + + make ${{ matrix.arch_name.image }}.push diff --git a/Makefile b/Makefile index 9e90efc..048dd45 100644 --- a/Makefile +++ b/Makefile @@ -363,6 +363,11 @@ $(addsuffix .test,$(MULTIARCH_IMAGES) web-wasi-threads): $$(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) \ From 8d3f1362c22dd6fe65f056ff328cbf91f4df878a Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Mon, 17 Feb 2025 15:37:31 -0500 Subject: [PATCH 31/40] ci: use more unique deploy job name, add steps: --- .github/workflows/main.yml | 49 +++++++++++++------------------------- 1 file changed, 16 insertions(+), 33 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 86b6961..4d1376a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1494,62 +1494,45 @@ jobs: make ${{ matrix.arch_name.image }}.push deploy-multi-arch-images: - name: ${{ matrix.arch_name.image }} - needs: [${{ matrix.arch_name.image }}_on_ubuntu-22.04, ${{ matrix.arch_name.image }}_on_ubuntu-22.04-arm] + needs: ["${{ matrix.image_name }}_on_ubuntu-22.04", "${{ matrix.image_name }}_on_ubuntu-22.04-arm"] runs-on: ubuntu-22.04 strategy: fail-fast: false matrix: - arch_name: - - { - image: "android-arm64" - } - - { - image: "web-wasm", - } - - { - image: "web-wasi", - } - - { - image: "web-wasi-threads", - } - + image_name: ["android-arm64", "web-wasm", "web-wasi", "web-wasi-threads"] + 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: download ${{ matrix.arch_name.image }}-amd64 + - name: download ${{ matrix.image_name }}-amd64 uses: actions/download-artifact@v4 with: - name: cache-${{ matrix.arch_name.image }}-amd64 - path: ./cache/${{ matrix.arch_name.image }}-amd64.tar.xz + name: cache-${{ matrix.image_name }}-amd64 + path: ./cache/${{ matrix.image_name }}-amd64.tar.xz - - name: download ${{ matrix.arch_name.image }}-arm64 + - name: download ${{ matrix.image_name }}-arm64 uses: actions/download-artifact@v4 with: - name: cache-${{ matrix.arch_name.image }}-arm64 - path: ./cache/${{ matrix.arch_name.image }}-arm64.xz + name: cache-${{ matrix.image_name }}-arm64 + path: ./cache/${{ matrix.image_name }}-arm64.xz - name: load images run: | - xz -d -k < ./cache/${{ matrix.arch_name.image }}-amd64.tar.xz | docker import - dockcross/${{ matrix.arch_name.image }}-amd64 - xz -d -k < ./cache/${{ matrix.arch_name.image }}-arm64.tar.xz | docker import - dockcross/${{ matrix.arch_name.image }}-arm64 + 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: deploy-multi-arch if: github.ref == 'refs/heads/master' run: | docker login -u ${{ secrets.DOCKER_USER }} -p ${{ secrets.DOCKER_PASS }} - make ${{ matrix.arch_name.image }}.tag-amd64 - make ${{ matrix.arch_name.image }}.tag-arm64 + make ${{ matrix.image_name }}.tag-amd64 + make ${{ matrix.image_name }}.tag-arm64 - make ${{ matrix.arch_name.image }}.push-amd64 - make ${{ matrix.arch_name.image }}.push-arm64 + make ${{ matrix.image_name }}.push-amd64 + make ${{ matrix.image_name }}.push-arm64 - make ${{ matrix.arch_name.image }}.push + make ${{ matrix.image_name }}.push From 85496b648d4f60f3e7cad0b308d60ff5cb6df145 Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Mon, 17 Feb 2025 16:06:00 -0500 Subject: [PATCH 32/40] ci: login to DockerHub via official Action --- .github/workflows/main.yml | 44 ++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4d1376a..65d5cd7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -41,10 +41,16 @@ 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 base-multiarch: @@ -86,10 +92,16 @@ 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: @@ -192,7 +204,7 @@ 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: "", @@ -752,7 +764,7 @@ 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: "", @@ -1471,12 +1483,11 @@ jobs: cd .. rm -rf libopencm3 - - name: archive ${{ matrix.arch_name.image }}-${{ matrix.os }} - if: matrix.arch_name.multiarch != 'yes' + - 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 - fi + 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 @@ -1486,11 +1497,16 @@ jobs: 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: | - docker login -u ${{ secrets.DOCKER_USER }} -p ${{ secrets.DOCKER_PASS }} make ${{ matrix.arch_name.image }}.push deploy-multi-arch-images: @@ -1517,17 +1533,23 @@ jobs: uses: actions/download-artifact@v4 with: name: cache-${{ matrix.image_name }}-arm64 - path: ./cache/${{ matrix.image_name }}-arm64.xz + 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 }} make ${{ matrix.image_name }}.tag-amd64 make ${{ matrix.image_name }}.tag-arm64 From 9dea22ab64e1f837d8d34d2ad16ab3efd810ea3d Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Mon, 17 Feb 2025 21:14:24 -0500 Subject: [PATCH 33/40] ci: use explicit deploy-multi-arch-images needs: dynamic job references not supported. --- .github/workflows/main.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 65d5cd7..1192fc6 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -104,10 +104,9 @@ jobs: run: | docker image push dockcross/base --all-tags - image: - name: ${{ matrix.arch_name.image }} - needs: base - runs-on: ubuntu-22.04 + images: + needs: [base, base-multiarch] + runs-on: ${{ matrix.os }} env: OCI_EXE: docker strategy: @@ -1510,7 +1509,8 @@ jobs: make ${{ matrix.arch_name.image }}.push deploy-multi-arch-images: - needs: ["${{ matrix.image_name }}_on_ubuntu-22.04", "${{ matrix.image_name }}_on_ubuntu-22.04-arm"] + needs: + - images runs-on: ubuntu-22.04 strategy: fail-fast: false From 1afd48ee6a6e55543b5dbbc2e021beee833f8b73 Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Mon, 17 Feb 2025 22:53:54 -0500 Subject: [PATCH 34/40] ci: switch from android-arm64 to linux-arm64 for multi-arch --- .github/workflows/main.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1192fc6..646d90c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -139,7 +139,7 @@ jobs: } - { image: "android-arm64", - multiarch: "yes", + multiarch: "", stockfish: "yes", stockfish_arg: "ARCH=armv8 COMP=ndk", ninja: "no", @@ -206,7 +206,7 @@ jobs: # inux arm64/armv8 images - { image: "linux-arm64", - multiarch: "", + multiarch: "yes", stockfish: "yes", stockfish_arg: "ARCH=armv8", ninja: "yes", @@ -1515,7 +1515,7 @@ jobs: strategy: fail-fast: false matrix: - image_name: ["android-arm64", "web-wasm", "web-wasi", "web-wasi-threads"] + image_name: ["linux-arm64", "web-wasm", "web-wasi", "web-wasi-threads"] steps: - name: checkout code uses: actions/checkout@v4 From 27edf0f8a9257918e48182116b203d2c8bf8e009 Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Tue, 18 Feb 2025 17:18:11 -0500 Subject: [PATCH 35/40] ci: improve multiarch base load --- .github/workflows/main.yml | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 646d90c..399a21c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -83,7 +83,7 @@ jobs: - name: archive base run: | mkdir -p cache - docker export dockcross/base:latest-${{ env.HOST_ARCH }} | xz -e9 -T0 > ./cache/base.tar.xz + docker export dockcross/base:latest-${{ env.HOST_ARCH }} | xz -e9 -T0 > ./cache/base-multiarch.tar.xz - name: save base uses: actions/upload-artifact@v4 @@ -1318,6 +1318,10 @@ jobs: - 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 @@ -1332,14 +1336,7 @@ jobs: path: ./cache - name: load multiarch base - run: xz -d -k < ./cache/base.tar.xz | docker import - dockcross/base:latest - - - name: load base - run: xz -d -k < ./cache/base.tar.xz | docker import - dockcross/base:latest - - - name: set host_arch - run: | - echo "HOST_ARCH=$(uname -m | sed -e 's/x86_64/amd64/' -e 's/aarch64/arm64/')" >> $GITHUB_ENV + run: xz -d -k < ./cache/base-multiarch.tar.xz | docker import - dockcross/base:latest-${{ env.HOST_ARCH }} - name: build env: From 7577ed208d0bf374fe76b595ef5d2fd59382b4c7 Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Wed, 19 Feb 2025 13:44:54 -0500 Subject: [PATCH 36/40] linux-arm64: disable openssl in CIo Strage failure in the ARM host build: ``` /usr/xcc/aarch64-unknown-linux-gnu/bin/aarch64-unknown-linux-gnu-gcc -Iinclude -pthread -Wall -O3 -DNDEBUG -c -o test/x509aux.o test/x509aux.c /usr/bin/perl "-I." -Mconfigdata "util/dofile.pl" \ "-oMakefile" apps/CA.pl.in > "apps/CA.pl" /usr/bin/perl "-I." -Mconfigdata "util/dofile.pl" \ "-oMakefile" apps/tsget.in > "apps/tsget.pl" /usr/bin/perl "-I." -Mconfigdata "util/dofile.pl" \ "-oMakefile" tools/c_rehash.in > "tools/c_rehash" /usr/bin/perl "-I." -Mconfigdata "util/dofile.pl" \ "-oMakefile" util/shlib_wrap.sh.in > "util/shlib_wrap.sh" ./dockcross-linux-arm64: line 249: 615634 Killed $OCI_EXE run $TTY_ARGS --name $CONTAINER_NAME -v "$HOST_PWD":/work $HOST_VOLUMES "${USER_IDS[@]}" $FINAL_ARGS $FINAL_IMAGE "$@" ``` --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 399a21c..f4563ea 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -211,7 +211,7 @@ jobs: stockfish_arg: "ARCH=armv8", ninja: "yes", ninja_arg: "", - openssl: "yes", + openssl: "no", openssl_arg: "linux-aarch64", C: "yes", C_arg: "", From 055c60ebabf10d25552db9ec65bc5e7a92e8c5d4 Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Thu, 20 Feb 2025 16:45:45 -0500 Subject: [PATCH 37/40] dockcross-cmake-builder.sh: use multiarch image when available --- tools/dockcross-cmake-builder.sh | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) 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" From de6a4b0be32fad6a629d0c3c32a1c766dbe8a820 Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Fri, 21 Feb 2025 15:51:36 -0500 Subject: [PATCH 38/40] dockcross-command.sh: support multi-arch tags --- tools/dockcross-command.sh | 10 ++++++++-- tools/dockcross-make-builder.sh | 19 ++++++++++++++----- 2 files changed, 22 insertions(+), 7 deletions(-) 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 From 5887d4c55c877795b77d8e891cdb49675d048be9 Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Sat, 22 Feb 2025 17:27:44 -0500 Subject: [PATCH 39/40] ci: upload multiarch artifacts --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f4563ea..6d3b2c3 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1487,7 +1487,7 @@ jobs: - name: save ${{ matrix.arch_name.image }}-${{ matrix.os }} uses: actions/upload-artifact@v4 - if: matrix.arch_name.multiarch != 'yes' + 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 From d75b3333c0cd08455d0e1e16b4d3ea587fc940f6 Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Mon, 24 Feb 2025 11:21:00 -0500 Subject: [PATCH 40/40] ci: mark web-wasm and web-wasi-threads as multiarch --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6d3b2c3..5a2f5b8 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1217,7 +1217,7 @@ jobs: # web-wasm images - { image: "web-wasm", - multiarch: "", + multiarch: "yes", stockfish: "no", stockfish_arg: "", ninja: "no", @@ -1261,7 +1261,7 @@ jobs: } - { image: "web-wasi-threads", - multiarch: "", + multiarch: "yes", stockfish: "no", stockfish_arg: "", ninja: "no",