diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml index eaece1d0..f8932726 100644 --- a/.github/release-drafter.yml +++ b/.github/release-drafter.yml @@ -66,6 +66,7 @@ template: | - `docker.elastic.co/beats-dev/golang-crossbuild:$RESOLVED_VERSION-mips-debian12(-fips)?` - linux/mips64, linux/mips64el - `docker.elastic.co/beats-dev/golang-crossbuild:$RESOLVED_VERSION-ppc-debian12(-fips)?` - linux/ppc64, linux/ppc64le - `docker.elastic.co/beats-dev/golang-crossbuild:$RESOLVED_VERSION-s390x-debian12(-fips)?` - linux/s390x + - `docker.elastic.co/beats-dev/golang-crossbuild:$RESOLVED_VERSION-windows-arm64-debian12(-fips)?` - linux/arm64, windows/arm64 ### Changes diff --git a/go/Makefile.debian12 b/go/Makefile.debian12 index a1c6cbc5..f56c4951 100644 --- a/go/Makefile.debian12 +++ b/go/Makefile.debian12 @@ -1,5 +1,5 @@ IMAGES := base main darwin armhf armel mips ppc s390x npcap -ARM_IMAGES := base-arm darwin-arm64 +ARM_IMAGES := base-arm darwin-arm64 windows-arm64 DEBIAN_VERSION := 12 TAG_EXTENSION := -debian12 diff --git a/go/windows-arm64/Dockerfile.tmpl b/go/windows-arm64/Dockerfile.tmpl new file mode 100644 index 00000000..9d71c5a1 --- /dev/null +++ b/go/windows-arm64/Dockerfile.tmpl @@ -0,0 +1,74 @@ +ARG REPOSITORY +ARG VERSION +ARG TAG_EXTENSION='' + +FROM ${REPOSITORY}/golang-crossbuild:${VERSION}-base-arm${TAG_EXTENSION} + +#ARG LLVM_MINGW64_VER=20250826 +ARG LLVM_MINGW64_VER=20250910 +ARG LLVM_MINGW_UBUNTU_REL='22.04' +ARG LLVM_MINGW64_SRC="https://github.com/mstorsjo/llvm-mingw/releases/download" +ENV LLVM_MINGW64_VER="${LLVM_MINGW64_VER}" +ENV LLVM_MINGW64_SRC="$LLVM_MINGW64_SRC" + +{{- if ne .DEBIAN_VERSION "12"}} +RUN echo "This Docker image will work only with Debian >12" && exit 1 +{{- end }} + +RUN \ + apt-get -o Acquire::Check-Valid-Until=false update \ + && apt-get install -qq -y --no-install-recommends --allow-unauthenticated \ + cmake \ + patch \ + libssl-dev \ + libxml2-dev \ + lzma-dev \ + uuid-dev \ + make \ + bash \ + wget \ + && rm -rf /var/lib/apt/lists/* + +WORKDIR /tmp +COPY --chmod=0755 scripts/setup-llvm-mingw64.sh /tmp/ +RUN /tmp/setup-llvm-mingw64.sh + +COPY --chmod=0755 scripts/install-llvm-mingw64.sh /tmp/install-llvm-mingw64.sh +RUN /tmp/install-llvm-mingw64.sh /tmp/llvm-mingw64 && rm -rf /tmp/* + +COPY rootfs / + +# Basic test +RUN which aarch64-w64-mingw32-gcc + +RUN cd / \ + && aarch64-w64-mingw32-gcc helloWorld.c -o helloWorld.arm64 \ + && file helloWorld.arm64 \ + && file helloWorld.arm64 | grep -c 'PE32+ executable (console) Aarch64, for MS Windows' + +RUN cd / \ + && aarch64-w64-mingw32uwp-gcc helloWorld.c -o helloWorld.arm64e \ + && file helloWorld.arm64e \ + && file helloWorld.arm64e | grep -c 'PE32+ executable (console) Aarch64, for MS Windows' + +ENV CGO_ENABLED 1 +#ENV CC aarch64-w64-mingw32-gcc +#ENV CXX aarch64-w64-mingw32-g++ +ENV CGO_FLAGS="$CGO_FLAGS -I/usr/generic-w64-mingw32/include" +ENV CGO_CFLAGS="-fno-addrsig" +RUN go env + +RUN aarch64-w64-mingw32-gcc --version + +RUN go clean -cache -modcache -i -r + +# Build-time metadata as defined at http://label-schema.org. +ARG BUILD_DATE +ARG IMAGE +ARG VCS_REF +ARG VCS_URL +LABEL org.label-schema.build-date=$BUILD_DATE \ + org.label-schema.name=$IMAGE \ + org.label-schema.vcs-ref=$VCS_REF \ + org.label-schema.vcs-url=$VCS_URL \ + org.label-schema.schema-version="1.0" diff --git a/go/windows-arm64/Makefile b/go/windows-arm64/Makefile new file mode 100644 index 00000000..a2e38ea2 --- /dev/null +++ b/go/windows-arm64/Makefile @@ -0,0 +1,10 @@ +include ../Makefile.common + +ifeq ($(DOCKER_MULTIARCH),1) +DOCKER_CMD := $(SELF_DIR)/../.buildkite/scripts/buildx.sh + +push: + @echo "Already done by buildx (.buildkite/scripts/buildx.sh)." +atomic-push: + @echo "Already done by buildx (.buildkite/scripts/buildx.sh)." +endif diff --git a/go/windows-arm64/rootfs/compilers.yaml b/go/windows-arm64/rootfs/compilers.yaml new file mode 100644 index 00000000..5d70e943 --- /dev/null +++ b/go/windows-arm64/rootfs/compilers.yaml @@ -0,0 +1,7 @@ +--- + +windows: + arm64: + CC: aarch64-w64-mingw32-gcc + CXX: aarch64-w64-mingw32-g++ + diff --git a/go/windows-arm64/rootfs/helloWorld.c b/go/windows-arm64/rootfs/helloWorld.c new file mode 100644 index 00000000..dcfb86bc --- /dev/null +++ b/go/windows-arm64/rootfs/helloWorld.c @@ -0,0 +1,5 @@ +#include +int main() { + printf("Hello, World!"); + return 0; +} diff --git a/go/windows-arm64/scripts/install-llvm-mingw64.sh b/go/windows-arm64/scripts/install-llvm-mingw64.sh new file mode 100755 index 00000000..567e6311 --- /dev/null +++ b/go/windows-arm64/scripts/install-llvm-mingw64.sh @@ -0,0 +1,53 @@ +#!/usr/bin/env bash +# +# Copied from: https://github.com/x1unix/docker-go-mingw/tree/20dfaff6efe8fe3a4ff588a58ccb31646cd2fd60 +# +set -e +set -o pipefail + +trap 'echo "$0: Error on line $LINENO" >&2' ERR + +src="$1" +if [ -z "$src" ]; then + echo "Error: missing source dir" + exit 1 +fi + +base_dir='/usr' + +echo ":: Installing llvm-mingw64..." +echo "Source dir: $src" + +cd "$src" || exit 1 +find . -mindepth 1 -maxdepth 1 -type d ! -name . | while read -r subdir; do + dst_dir="$(basename "$subdir")" + + case "$dst_dir" in + bin) + perm=755 + ;; + *) + perm=644 + ;; + esac + + find "$subdir" -type f | while read -r file; do + dst="$base_dir/${file/.\//}" + mkdir -p "$(dirname "$dst")" + install -m $perm "$file" "$dst" + done +done + +echo ":: Restoring symlinks..." +while IFS= read -r line; do + src=$(echo "$line" | awk '{print $1}') + src="$base_dir/$src" + + dest=$(echo "$line" | awk '{print $2}') + dest="$(realpath "$base_dir/$dest")" + ln -s "$dest" "$src" +done &2' ERR + +if [ -z "$LLVM_MINGW64_SRC" ]; then + echo "Error: LLVM_MINGW64_SRC is undefined" + env + exit 1 +fi + +if [ -z "$LLVM_MINGW_UBUNTU_REL" ]; then + echo "Error: LLVM_MINGW_UBUNTU_REL is undefined" + env + exit 1 +fi + +if [ -z "$LLVM_MINGW64_VER" ]; then + echo "Error: LLVM_MINGW64_VER is undefined" + env + exit 1 +fi + +apt update && apt install xz-utils --yes + +case "$(uname -m)" in +aarch64 | arm64) + m_arch="aarch64" + ;; +x86_64 | amd64) + m_arch="x86_64" + ;; +*) + echo "Error: unsupported architecture $(uname -m)" + exit 1 + ;; +esac + +pkg_dir="llvm-mingw-$LLVM_MINGW64_VER-ucrt-ubuntu-$LLVM_MINGW_UBUNTU_REL-$m_arch" +pkg_file="$pkg_dir.tar.xz" +src_url="$LLVM_MINGW64_SRC/$LLVM_MINGW64_VER/$pkg_file" +echo ":: Downloading $src_url ..." +wget "$src_url" +# wget -q --spider "$src_url" + +if [ ! -f "$pkg_file" ]; then + echo "Error: can't find downloaded file $pkg_file" + ls -la + exit 1 +fi + +echo ":: Extracting file..." +tar -xf "$pkg_file" +rm "$pkg_file" + +echo ":: Preparing file list..." +mv "$pkg_dir" llvm-mingw64 +cd llvm-mingw64 + +# Keep llvm-mingw64 only for arm target to avoid conflict with gcc-mingw64 +rm bin/x86_64* bin/i686* +rm -rf i686-w64-mingw32 x86_64-w64-mingw32 + +# Backup symlinks +find . -type l | while read -r symlink; do + src="${symlink/.\//}" + dst="$(dirname "$src")/$(readlink "$symlink")" + echo "$src $dst" >>symlinks.txt + rm "$symlink" +done