mirror of
https://github.com/official-stockfish/Stockfish.git
synced 2026-07-22 20:57:10 +00:00
- Add new target `macos-lipo`.
- Created by compiling a universal x86 binary (no PGO) and a standard Apple silicon binary (with PGO), then combining them into a Mach-O fat binary
- To keep only one copy of the net, we add custom loading logic in the x86 section. The executable reads its own path and mmaps the net that's in the ARM section.
- The offset and size (from the executable base) of the mapping is injected after compilation in `patch_x86_slice.sh`
- avx512 on macOS isn't advertised in the xcr0 register by default. The simple solution I came up with is to execute a dummy AVX512 instruction, which sets up the register, before calling `__builtin_cpu_init`.
Some housekeeping as well:
- Rename `armv8-universal` -> `arm64-universal`.
- Add standard copyright headers to the files we've added recently.
Potential follow-ups:
- Disservin's Makefile cleanup
- Alternative ideas for the net loading. In particular, this will error out if the user strips the binary (since that'll invalidate the offset).
closes https://github.com/official-stockfish/Stockfish/pull/6860
No functional change
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
257 lines
8.5 KiB
YAML
257 lines
8.5 KiB
YAML
name: Universal Compilation
|
|
on:
|
|
workflow_call:
|
|
jobs:
|
|
UniversalLinux:
|
|
name: Linux
|
|
runs-on: ubuntu-22.04
|
|
defaults:
|
|
run:
|
|
shell: bash
|
|
steps:
|
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
|
with:
|
|
persist-credentials: false
|
|
fetch-depth: 0
|
|
|
|
- name: Install GCC 15
|
|
uses: egor-tensin/setup-gcc@a2861a8b8538f49cf2850980acccf6b05a1b2ae4 # v2.0
|
|
with:
|
|
version: 15
|
|
|
|
- name: Download SDE package
|
|
uses: petarpetrovt/setup-sde@d230e06df0ca06ced70000e4a7fa62afc9a2001e # v4.0
|
|
with:
|
|
environmentVariableName: SDE_DIR
|
|
sdeVersion: 9.58.0
|
|
|
|
- name: Build universal binary
|
|
run: make -j4 -C src ARCH=x86-64-universal profile-build RUN_PREFIX="$SDE_DIR/sde -future --"
|
|
|
|
- name: Strip binary
|
|
run: strip src/stockfish
|
|
|
|
- name: Rename binary
|
|
run: mv src/stockfish stockfish-linux-x86-64-universal
|
|
|
|
- name: Extract the bench number from the commit history
|
|
run: |
|
|
for hash in $(git rev-list -100 HEAD); do
|
|
benchref=$(git show -s $hash | tac | grep -m 1 -o -x '[[:space:]]*\b[Bb]ench[ :]\+[1-9][0-9]\{5,7\}\b[[:space:]]*' | sed 's/[^0-9]//g') && break || true
|
|
done
|
|
[[ -n "$benchref" ]] && echo "benchref=$benchref" >> $GITHUB_ENV && echo "From commit: $hash" && echo "Reference bench: $benchref" || echo "No bench found"
|
|
|
|
- name: Check arch selection under SDE
|
|
run: ./scripts/check_universal.sh ./stockfish-linux-x86-64-universal "$SDE_DIR/sde" "$benchref"
|
|
|
|
- name: Remove non-src files
|
|
run: git clean -fxd -- src
|
|
|
|
- name: Upload artifact for (pre)-release
|
|
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
|
with:
|
|
name: linux x86-64-universal
|
|
path: |
|
|
.
|
|
!.git
|
|
!.output
|
|
|
|
UniversalWindows:
|
|
name: Windows
|
|
runs-on: windows-2022
|
|
defaults:
|
|
run:
|
|
shell: msys2 {0}
|
|
steps:
|
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
|
with:
|
|
persist-credentials: false
|
|
fetch-depth: 0
|
|
|
|
- name: Setup msys and install required packages
|
|
uses: msys2/setup-msys2@e9898307ac31d1a803454791be09ab9973336e1c # v2.31.1
|
|
with:
|
|
msystem: mingw64
|
|
install: mingw-w64-x86_64-gcc make git zip
|
|
|
|
- name: Download SDE package
|
|
uses: petarpetrovt/setup-sde@d230e06df0ca06ced70000e4a7fa62afc9a2001e # v4.0
|
|
with:
|
|
environmentVariableName: SDE_DIR
|
|
sdeVersion: 9.58.0
|
|
|
|
- name: Build universal binary
|
|
run: |
|
|
SDE_PATH=$(cygpath "$SDE_DIR")
|
|
make -j4 -C src ARCH=x86-64-universal profile-build RUN_PREFIX="$SDE_PATH/sde.exe -future --"
|
|
|
|
- name: Strip binary
|
|
run: strip src/stockfish.exe
|
|
|
|
- name: Rename binary
|
|
run: mv src/stockfish.exe stockfish-windows-x86-64-universal.exe
|
|
|
|
- name: Extract the bench number from the commit history
|
|
run: |
|
|
for hash in $(git rev-list -100 HEAD); do
|
|
benchref=$(git show -s $hash | tac | grep -m 1 -o -x '[[:space:]]*\b[Bb]ench[ :]\+[1-9][0-9]\{5,7\}\b[[:space:]]*' | sed 's/[^0-9]//g') && break || true
|
|
done
|
|
[[ -n "$benchref" ]] && echo "benchref=$benchref" >> $GITHUB_ENV && echo "From commit: $hash" && echo "Reference bench: $benchref" || echo "No bench found"
|
|
|
|
- name: Check arch selection under SDE
|
|
run: ./scripts/check_universal.sh ./stockfish-windows-x86-64-universal.exe "$SDE_DIR/sde" "$benchref"
|
|
|
|
- name: Remove non-src files
|
|
run: git clean -fxd -- src
|
|
|
|
- name: Upload artifact for (pre)-release
|
|
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
|
with:
|
|
name: windows x86-64-universal
|
|
path: |
|
|
.
|
|
!.git
|
|
!.output
|
|
|
|
UniversalLinuxARM64:
|
|
name: Linux arm64
|
|
runs-on: ubuntu-22.04-arm
|
|
defaults:
|
|
run:
|
|
shell: bash
|
|
steps:
|
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
|
with:
|
|
persist-credentials: false
|
|
fetch-depth: 0
|
|
|
|
- name: Install GCC 15
|
|
uses: egor-tensin/setup-gcc@a2861a8b8538f49cf2850980acccf6b05a1b2ae4 # v2.0
|
|
with:
|
|
version: 15
|
|
|
|
- name: Install qemu-user
|
|
run: |
|
|
sudo apt-get update
|
|
sudo apt-get install -y qemu-user
|
|
|
|
- name: Build universal binary
|
|
run: make -j4 -C src ARCH=armv8-universal profile-build
|
|
|
|
- name: Strip binary
|
|
run: strip src/stockfish
|
|
|
|
- name: Rename binary
|
|
run: mv src/stockfish stockfish-linux-arm64-universal
|
|
|
|
- name: Extract the bench number from the commit history
|
|
run: |
|
|
for hash in $(git rev-list -100 HEAD); do
|
|
benchref=$(git show -s $hash | tac | grep -m 1 -o -x '[[:space:]]*\b[Bb]ench[ :]\+[1-9][0-9]\{5,7\}\b[[:space:]]*' | sed 's/[^0-9]//g') && break || true
|
|
done
|
|
[[ -n "$benchref" ]] && echo "benchref=$benchref" >> $GITHUB_ENV && echo "From commit: $hash" && echo "Reference bench: $benchref" || echo "No bench found"
|
|
|
|
- name: Check arch selection under qemu
|
|
run: ./scripts/check_universal_arm.sh ./stockfish-linux-arm64-universal "$benchref"
|
|
|
|
- name: Remove non-src files
|
|
run: git clean -fxd -- src
|
|
|
|
- name: Upload artifact for (pre)-release
|
|
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
|
with:
|
|
name: linux arm64-universal
|
|
path: |
|
|
.
|
|
!.git
|
|
!.output
|
|
|
|
UniversalWindowsARM64:
|
|
name: Windows arm64
|
|
runs-on: windows-11-arm
|
|
defaults:
|
|
run:
|
|
shell: msys2 {0}
|
|
steps:
|
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
|
with:
|
|
persist-credentials: false
|
|
fetch-depth: 0
|
|
|
|
- name: Setup msys and install required packages
|
|
uses: msys2/setup-msys2@e9898307ac31d1a803454791be09ab9973336e1c # v2.31.1
|
|
with:
|
|
msystem: clangarm64
|
|
install: mingw-w64-clang-aarch64-clang make git zip
|
|
|
|
- name: Build universal binary
|
|
run: make -j4 -C src ARCH=armv8-universal profile-build COMP=clang COMPCXX=clang++
|
|
|
|
- name: Strip binary
|
|
run: strip src/stockfish.exe
|
|
|
|
- name: Extract the bench number from the commit history
|
|
run: |
|
|
for hash in $(git rev-list -100 HEAD); do
|
|
benchref=$(git show -s $hash | tac | grep -m 1 -o -x '[[:space:]]*\b[Bb]ench[ :]\+[1-9][0-9]\{5,7\}\b[[:space:]]*' | sed 's/[^0-9]//g') && break || true
|
|
done
|
|
[[ -n "$benchref" ]] && echo "benchref=$benchref" >> $GITHUB_ENV && echo "From commit: $hash" && echo "Reference bench: $benchref" || echo "No bench found"
|
|
|
|
- name: Verify bench and compiler
|
|
working-directory: src
|
|
run: |
|
|
../tests/signature.sh $benchref
|
|
./stockfish compiler 2>&1 | grep -q DOTPROD || { echo "compiler output missing DOTPROD" >&2; exit 1; }
|
|
|
|
- name: Rename binary
|
|
run: mv src/stockfish.exe stockfish-windows-arm64-universal.exe
|
|
|
|
- name: Remove non-src files
|
|
run: git clean -fxd -- src
|
|
|
|
- name: Upload artifact for (pre)-release
|
|
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
|
with:
|
|
name: windows arm64-universal
|
|
path: |
|
|
.
|
|
!.git
|
|
!.output
|
|
|
|
UniversalMacOS:
|
|
name: macOS
|
|
runs-on: macos-15
|
|
defaults:
|
|
run:
|
|
shell: bash
|
|
steps:
|
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
|
with:
|
|
persist-credentials: false
|
|
fetch-depth: 0
|
|
|
|
# macos-15 is Apple silicon; Rosetta 2 is needed to exercise the x86-64 slice
|
|
- name: Install Rosetta 2
|
|
run: softwareupdate --install-rosetta --agree-to-license
|
|
|
|
- name: Build universal binary
|
|
run: make -j4 -C src macos-lipo COMP=clang
|
|
|
|
- name: Rename binary
|
|
run: mv src/stockfish stockfish-macos-universal
|
|
|
|
- name: Verify binary runs natively and under Rosetta
|
|
run: ./scripts/check_universal_macos.sh ./stockfish-macos-universal
|
|
|
|
- name: Remove non-src files
|
|
run: git clean -fxd -- src
|
|
|
|
- name: Upload artifact for (pre)-release
|
|
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
|
with:
|
|
name: macos universal
|
|
path: |
|
|
.
|
|
!.git
|
|
!.output
|