From f7854252c7f68ca58fea3430fe9083205cf5bbe5 Mon Sep 17 00:00:00 2001 From: Justin Smith Date: Fri, 5 Sep 2025 07:38:17 -0400 Subject: [PATCH 1/3] Support zig compiler --- .github/workflows/zig.yml | 84 +++++++++++++++++++++++++++++++++++++++ util/zig-c++ | 35 ++++++++++++++++ util/zig-cc | 35 ++++++++++++++++ 3 files changed, 154 insertions(+) create mode 100644 .github/workflows/zig.yml create mode 100755 util/zig-c++ create mode 100755 util/zig-cc diff --git a/.github/workflows/zig.yml b/.github/workflows/zig.yml new file mode 100644 index 00000000000..9ce5d5bb7dc --- /dev/null +++ b/.github/workflows/zig.yml @@ -0,0 +1,84 @@ +name: Zig compiler +on: + push: + branches: [ '*' ] + pull_request: + branches: [ '*' ] +concurrency: + group: ${{ github.workflow }}-${{ github.ref_name }} + cancel-in-progress: true +jobs: + zig: + if: github.repository_owner == 'aws' + runs-on: ${{ matrix.config.host }} + env: + CFLAGS: "-fno-sanitize=all" + CXXFLAGS: "-fno-sanitize=all" + strategy: + fail-fast: false + matrix: + config: + - host: windows-latest + target_arch: x86_64 + target_system: Windows + - host: ubuntu-latest + target_arch: x86_64 + target_system: Linux + - host: macos-latest + target_arch: aarch64 + target_system: Darwin + steps: + - name: Install NASM + uses: ilammy/setup-nasm@v1.5.1 + - name: Checkout + uses: actions/checkout@v4 + - name: Install ninja-build tool + uses: seanmiddleditch/gha-setup-ninja@v4 + - uses: actions/setup-python@v5 + with: + python-version: '3.13' + - uses: actions/setup-go@v4 + with: + go-version: '>= 1.18' + - name: Install zigcc + uses: jiacai2050/my-works@main + with: + zig-version: 0.15.1 + - name: Locate zig not on Windows + if: matrix.os.name != 'windows-latest' + shell: bash + run: | + echo "ZIGCC=${PWD}/util/zig-cc" >> $GITHUB_ENV + echo "ZIGCXX=${PWD}/util/zig-c++" >> $GITHUB_ENV + - name: Locate zig on Windows + if: matrix.os.name == 'windows-latest' + shell: bash + run: | + ZIGCC="python3 $(cygpath -m $(which zigcc))" + ZIGCXX="python3 $(cygpath -m $(which zigcxx))" + echo "ZIGCC=${ZIGCC}" >> $GITHUB_ENV + echo "ZIGCXX=${ZIGCXX}" >> $GITHUB_ENV + - name: Create toolchain + shell: bash + run: | + cat < ./toolchain.cmake + set(CMAKE_C_COMPILER ${ZIGCC}) + set(CMAKE_SYSTEM_NAME ${{ matrix.config.target_system }}) + set(CMAKE_SYSTEM_PROCESSOR ${{ matrix.config.target_arch }}) + set(CMAKE_CXX_COMPILER ${ZIGCXX}) + set(CMAKE_ASM_COMPILER ${ZIGCC}) + set(CMAKE_VERBOSE_MAKEFILE ON) + set(CMAKE_MESSAGE_LOG_LEVEL DEBUG) + EOF + - name: Setup CMake + shell: bash + run: | + printenv | sort + which zigcc + which zigcxx + cat ./toolchain.cmake + cmake '.' -B ./build -G Ninja -DCMAKE_TOOLCHAIN_FILE=./toolchain.cmake -DCMAKE_BUILD_TYPE=Release + - name: Build Project + shell: bash + run: | + cmake --build ./build --target run_tests --verbose diff --git a/util/zig-c++ b/util/zig-c++ new file mode 100755 index 00000000000..bf76a10578f --- /dev/null +++ b/util/zig-c++ @@ -0,0 +1,35 @@ +#!/usr/bin/env bash +# Zig C++ compiler wrapper + +# Check if zig is available +if ! command -v zig &> /dev/null; then + echo "Error: zig compiler not found in PATH" >&2 + echo "Please install zig from https://ziglang.org/download/" >&2 + exit 1 +fi + +# Function to map problematic architecture flags to zig equivalents +filter_problematic_flags() { + local args=() + + for arg in "$@"; do + case "$arg" in + -march=armv8.4-a+sha3) + # Replace the specific problematic flag with a compatible one + args+=("-mcpu=generic" "-mattr=+v8.4a,+sha3") + ;; + *) + # Keep all other arguments including mcpu, mtune, and other march flags + args+=("$arg") + ;; + esac + done + + printf '%s\n' "${args[@]}" +} + +# Process arguments to filter only problematic architecture flags +filtered_args=($(filter_problematic_flags "$@")) + +# Execute zig c++ with sanitizers disabled by default and filtered arguments +exec zig c++ -fno-sanitize=undefined -fno-sanitize=address -fno-sanitize=memory "${filtered_args[@]}" diff --git a/util/zig-cc b/util/zig-cc new file mode 100755 index 00000000000..7d6ee04ab76 --- /dev/null +++ b/util/zig-cc @@ -0,0 +1,35 @@ +#!/usr/bin/env bash +# Zig C compiler wrapper + +# Check if zig is available +if ! command -v zig &> /dev/null; then + echo "Error: zig compiler not found in PATH" >&2 + echo "Please install zig from https://ziglang.org/download/" >&2 + exit 1 +fi + +# Function to map problematic architecture flags to zig equivalents +filter_problematic_flags() { + local args=() + + for arg in "$@"; do + case "$arg" in + -march=armv8.4-a+sha3) + # Replace the specific problematic flag with a compatible one + args+=("-mcpu=generic" "-mattr=+v8.4a,+sha3") + ;; + *) + # Keep all other arguments + args+=("$arg") + ;; + esac + done + + printf '%s\n' "${args[@]}" +} + +# Process arguments to filter only problematic architecture flags +filtered_args=($(filter_problematic_flags "$@")) + +# Execute zig cc with sanitizers disabled by default and filtered arguments +exec zig cc -fno-sanitize=undefined -fno-sanitize=address -fno-sanitize=memory "${filtered_args[@]}" From 1737632407bc5556485f590ff2e951961054e2bb Mon Sep 17 00:00:00 2001 From: Justin Smith Date: Fri, 5 Sep 2025 07:49:28 -0400 Subject: [PATCH 2/3] Fix windows; fix '-mcpu' arg --- .github/workflows/zig.yml | 7 +++---- util/zig-c++ | 2 +- util/zig-cc | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/.github/workflows/zig.yml b/.github/workflows/zig.yml index 9ce5d5bb7dc..09fc668e072 100644 --- a/.github/workflows/zig.yml +++ b/.github/workflows/zig.yml @@ -11,9 +11,6 @@ jobs: zig: if: github.repository_owner == 'aws' runs-on: ${{ matrix.config.host }} - env: - CFLAGS: "-fno-sanitize=all" - CXXFLAGS: "-fno-sanitize=all" strategy: fail-fast: false matrix: @@ -48,10 +45,12 @@ jobs: if: matrix.os.name != 'windows-latest' shell: bash run: | + echo "CFLAGS=${CFLAGS} -fno-sanitize=all" + echo "CXXFLAGS=${CXXFLAGS} -fno-sanitize=all" echo "ZIGCC=${PWD}/util/zig-cc" >> $GITHUB_ENV echo "ZIGCXX=${PWD}/util/zig-c++" >> $GITHUB_ENV - name: Locate zig on Windows - if: matrix.os.name == 'windows-latest' + if: matrix.config.host == 'windows-latest' shell: bash run: | ZIGCC="python3 $(cygpath -m $(which zigcc))" diff --git a/util/zig-c++ b/util/zig-c++ index bf76a10578f..2439f7d00ab 100755 --- a/util/zig-c++ +++ b/util/zig-c++ @@ -16,7 +16,7 @@ filter_problematic_flags() { case "$arg" in -march=armv8.4-a+sha3) # Replace the specific problematic flag with a compatible one - args+=("-mcpu=generic" "-mattr=+v8.4a,+sha3") + args+=("-mcpu=generic+v8.4a+sha3") ;; *) # Keep all other arguments including mcpu, mtune, and other march flags diff --git a/util/zig-cc b/util/zig-cc index 7d6ee04ab76..ad771637d6b 100755 --- a/util/zig-cc +++ b/util/zig-cc @@ -16,7 +16,7 @@ filter_problematic_flags() { case "$arg" in -march=armv8.4-a+sha3) # Replace the specific problematic flag with a compatible one - args+=("-mcpu=generic" "-mattr=+v8.4a,+sha3") + args+=("-mcpu=generic+v8.4a+sha3") ;; *) # Keep all other arguments From 5a9277954ca4dccf963c37c05a42b5741f0f27a3 Mon Sep 17 00:00:00 2001 From: Justin Smith Date: Wed, 17 Sep 2025 13:50:05 -0400 Subject: [PATCH 3/3] Also target ARM64 --- .github/workflows/zig.yml | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/.github/workflows/zig.yml b/.github/workflows/zig.yml index 09fc668e072..5e1f2e82e3f 100644 --- a/.github/workflows/zig.yml +++ b/.github/workflows/zig.yml @@ -15,6 +15,12 @@ jobs: fail-fast: false matrix: config: + - host: windows-11-arm + target_arch: aarch64 + target_system: Windows + - host: ubuntu-24.04-arm + target_arch: aarch64 + target_system: Linux - host: windows-latest target_arch: x86_64 target_system: Windows @@ -30,7 +36,7 @@ jobs: - name: Checkout uses: actions/checkout@v4 - name: Install ninja-build tool - uses: seanmiddleditch/gha-setup-ninja@v4 + uses: seanmiddleditch/gha-setup-ninja@v6 - uses: actions/setup-python@v5 with: python-version: '3.13' @@ -42,7 +48,7 @@ jobs: with: zig-version: 0.15.1 - name: Locate zig not on Windows - if: matrix.os.name != 'windows-latest' + if: matrix.config.target_system != 'Windows' shell: bash run: | echo "CFLAGS=${CFLAGS} -fno-sanitize=all" @@ -50,7 +56,7 @@ jobs: echo "ZIGCC=${PWD}/util/zig-cc" >> $GITHUB_ENV echo "ZIGCXX=${PWD}/util/zig-c++" >> $GITHUB_ENV - name: Locate zig on Windows - if: matrix.config.host == 'windows-latest' + if: matrix.config.target_system == 'Windows' shell: bash run: | ZIGCC="python3 $(cygpath -m $(which zigcc))"