diff --git a/.github/workflows/build-syso.yml b/.github/workflows/build-syso.yml new file mode 100644 index 0000000..d0a0332 --- /dev/null +++ b/.github/workflows/build-syso.yml @@ -0,0 +1,94 @@ +name: Build syso files + +on: + workflow_dispatch: # Manual trigger + push: + paths: + - 'src/**' + +jobs: + build-syso: + name: Build ${{ matrix.settings.name }} + runs-on: ${{ matrix.settings.runner }} + strategy: + fail-fast: false + matrix: + settings: + - name: Linux x86 + runner: ubuntu-latest + syso_name: hashtree_linux_amd64.syso + - name: macOS arm64 + runner: macos-latest + syso_name: hashtree_darwin_arm64.syso + - name: Linux arm64 + runner: ubuntu-latest + cc: aarch64-linux-gnu-gcc + cross_pkg: gcc-aarch64-linux-gnu + syso_name: hashtree_linux_arm64.syso + - name: Windows x86 + runner: windows-latest + syso_name: hashtree_windows_amd64.syso + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version: '1.22.x' + + - name: Install cross-compiler + if: ${{ matrix.settings.cross_pkg }} + run: | + sudo apt-get update + sudo apt-get install -y ${{ matrix.settings.cross_pkg }} + + - name: Build (cross-compile) + if: ${{ matrix.settings.cc }} + shell: bash + run: | + CC=${{ matrix.settings.cc }} make go_bindings + mv -f hashtree.syso ${{ matrix.settings.syso_name }} + + - name: Build (native) + if: ${{ !matrix.settings.cc }} + shell: bash + run: | + make go_bindings + mv -f hashtree.syso ${{ matrix.settings.syso_name }} + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: ${{ matrix.settings.syso_name }} + path: ${{ matrix.settings.syso_name }} + + commit-syso: + name: Commit syso files + needs: build-syso + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Download all artifacts + uses: actions/download-artifact@v4 + with: + path: artifacts + + - name: Move syso files to root + run: | + for dir in artifacts/*/; do + mv "$dir"/*.syso . + done + ls -la *.syso + + - name: Commit and push + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git add *.syso + git diff --staged --quiet || git commit -m "Update syso files" + git push diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8301f44..f0687f9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -55,6 +55,10 @@ jobs: - name: MacOS arm64 target: aarch64-apple-darwin runner: macos-latest + - name: MacOS x86 + target: x86_64-apple-darwin + runner: macos-15-intel + generic_only: true - name: Linux x86 target: x86_64-unknown-linux-gnu runner: ubuntu-latest @@ -86,8 +90,11 @@ jobs: if: ${{ matrix.settings.cc != '' }} run: CC=${{ matrix.settings.cc }} make go_bindings - name: Build - if: ${{ !matrix.settings.cc }} + if: ${{ !matrix.settings.cc && !matrix.settings.generic_only }} run: make go_bindings + - name: Build (generic only) + if: ${{ matrix.settings.generic_only }} + run: go build . - name: Run tests run: go test . - name: Run benchmarks diff --git a/bindings_amd64.go b/bindings_amd64.go index 7d98ba4..19bee60 100644 --- a/bindings_amd64.go +++ b/bindings_amd64.go @@ -1,5 +1,5 @@ -//go:build amd64 -// +build amd64 +//go:build amd64 && !darwin +// +build amd64,!darwin package hashtree diff --git a/bindings_darwin_amd64.go b/bindings_darwin_amd64.go new file mode 100644 index 0000000..893a1a9 --- /dev/null +++ b/bindings_darwin_amd64.go @@ -0,0 +1,8 @@ +//go:build darwin && amd64 + +package hashtree + +// supportedCPU is false on darwin/amd64 because there is no native +// assembly implementation. The generic Go implementation will be used. +var supportedCPU = false + diff --git a/hashtree_amd64.syso b/hashtree_linux_amd64.syso similarity index 100% rename from hashtree_amd64.syso rename to hashtree_linux_amd64.syso diff --git a/wrapper_darwin_amd64.s b/wrapper_darwin_amd64.s new file mode 100644 index 0000000..2c17161 --- /dev/null +++ b/wrapper_darwin_amd64.s @@ -0,0 +1,7 @@ +// +build darwin,amd64 + +// Stub implementation - should never be called since supportedCPU = false +// on darwin/amd64. The generic Go implementation is used instead. +TEXT ·HashtreeHash(SB), 0, $0-24 + INT $3 // Trigger breakpoint/crash if ever called + RET