build: target macos 13 for x86 binaries (#6221)

* build: target older macos

* cleanup

* Align xcode versions

* Simplify --x86-macos

* use cmake flag in compile.sh i.s.o. env var in yml

* more cleanups

* adress initial reviews

* generate triplet file in compile.sh

* fix triplet name

* pass matrix.target as version

* small refactor

* another minor refactor

* ci: fix ccache cleaning

* add more comments

* try passing triplets config as cmake variables

* Revert "try passing triplets config as cmake variables"

This reverts commit 77e83e8590.

* move logic inside runner == macos if

* move logic to env var

* simplify script

* format script

"I just thinks it looks better like this"

* make script work for arm as well, might be useful

* use hyphen

* use DVCPKG_HOST_TRIPLET instead of DVCPKG_TARGET_TRIPLET

* use DVCPKG_HOST_TRIPLET AND DVCPKG_TARGET_TRIPLET

---------

Co-authored-by: ebbit1q <ebbit1q@gmail.com>
This commit is contained in:
Bruno Alexandre Rosa 2025-10-21 20:00:25 -03:00 committed by GitHub
parent 8ebfc40de5
commit 817a3f979e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 44 additions and 6 deletions

View file

@ -11,7 +11,8 @@
# --debug or --release sets the build type ie CMAKE_BUILD_TYPE
# --ccache [<size>] uses ccache and shows stats, optionally provide size
# --dir <dir> sets the name of the build dir, default is "build"
# uses env: BUILDTYPE MAKE_INSTALL MAKE_PACKAGE PACKAGE_TYPE PACKAGE_SUFFIX MAKE_SERVER MAKE_TEST USE_CCACHE CCACHE_SIZE BUILD_DIR CMAKE_GENERATOR
# --target-macos-version <version> sets the min os version - only used for macOS builds
# uses env: BUILDTYPE MAKE_INSTALL MAKE_PACKAGE PACKAGE_TYPE PACKAGE_SUFFIX MAKE_SERVER MAKE_TEST USE_CCACHE CCACHE_SIZE BUILD_DIR CMAKE_GENERATOR TARGET_MACOS_VERSION
# (correspond to args: --debug/--release --install --package <package type> --suffix <suffix> --server --test --ccache <ccache_size> --dir <dir>)
# exitcode: 1 for failure, 3 for invalid arguments
@ -79,6 +80,15 @@ while [[ $# != 0 ]]; do
BUILD_DIR="$1"
shift
;;
'--target-macos-version')
shift
if [[ $# == 0 ]]; then
echo "::error file=$0::--target-macos-version expects an argument"
exit 3
fi
TARGET_MACOS_VERSION="$1"
shift
;;
*)
echo "::error file=$0::unrecognized option: $1"
exit 3
@ -139,9 +149,34 @@ function ccachestatsverbose() {
# Compile
if [[ $RUNNER_OS == macOS ]]; then
if [[ $TARGET_MACOS_VERSION ]]; then
# CMAKE_OSX_DEPLOYMENT_TARGET is a vanilla cmake flag needed to compile to target macOS version
flags+=("-DCMAKE_OSX_DEPLOYMENT_TARGET=$TARGET_MACOS_VERSION")
# vcpkg dependencies need a vcpkg triplet file to compile to the target macOS version
# an easy way is to copy the x64-osx.cmake file and modify it
triplets_dir="/tmp/cmake/triplets"
triplet_version="custom-triplet"
triplet_file="$triplets_dir/$triplet_version.cmake"
arch=$(uname -m)
if [[ $arch == x86_64 ]]; then
arch="x64"
fi
mkdir -p "$triplets_dir"
cp "../vcpkg/triplets/$arch-osx.cmake" "$triplet_file"
echo "set(VCPKG_CMAKE_SYSTEM_VERSION $TARGET_MACOS_VERSION)" >>"$triplet_file"
echo "set(VCPKG_OSX_DEPLOYMENT_TARGET $TARGET_MACOS_VERSION)" >>"$triplet_file"
flags+=("-DVCPKG_OVERLAY_TRIPLETS=$triplets_dir")
flags+=("-DVCPKG_HOST_TRIPLET=$triplet_version")
flags+=("-DVCPKG_TARGET_TRIPLET=$triplet_version")
echo "::group::Generated triplet $triplet_file"
cat "$triplet_file"
echo "::endgroup::"
fi
echo "::group::Signing Certificate"
if [[ -n "$MACOS_CERTIFICATE_NAME" ]]; then
echo "$MACOS_CERTIFICATE" | base64 --decode > certificate.p12
echo "$MACOS_CERTIFICATE" | base64 --decode >"certificate.p12"
security create-keychain -p "$MACOS_CI_KEYCHAIN_PWD" build.keychain
security default-keychain -s build.keychain
security set-keychain-settings -t 3600 -l build.keychain

View file

@ -4,6 +4,7 @@ permissions:
contents: write
id-token: write
attestations: write
actions: write # needed for ccache action to be able to delete gha caches
on:
push:
@ -245,10 +246,11 @@ jobs:
include:
- target: 13
soc: Intel
os: macos-13
xcode: "14.3.1"
os: macos-15-intel
xcode: "16.4"
type: Release
make_package: 1
override_target: 13
- target: 14
soc: Apple
@ -260,14 +262,14 @@ jobs:
- target: 15
soc: Apple
os: macos-15
xcode: "16.2"
xcode: "16.4"
type: Release
make_package: 1
- target: 15
soc: Apple
os: macos-15
xcode: "16.2"
xcode: "16.4"
type: Debug
name: macOS ${{matrix.target}}${{ matrix.soc == 'Intel' && ' Intel' || '' }}${{ matrix.type == 'Debug' && ' Debug' || '' }}
@ -331,6 +333,7 @@ jobs:
CMAKE_GENERATOR: '${{env.CMAKE_GENERATOR}}'
VCPKG_DISABLE_METRICS: 1
VCPKG_BINARY_SOURCES: 'clear;files,${{ steps.vcpkg-cache.outputs.path }},readwrite'
TARGET_MACOS_VERSION: ${{ matrix.override_target }}
run: .ci/compile.sh --server --test --ccache "$CCACHE_SIZE" --vcpkg
- name: Sign app bundle