]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
ci: Build macOS universal binary (#1240)
authorRaihaan Shouhell <raihaanhimself@gmail.com>
Fri, 27 Jan 2023 12:02:38 +0000 (20:02 +0800)
committerGitHub <noreply@github.com>
Fri, 27 Jan 2023 12:02:38 +0000 (13:02 +0100)
.github/workflows/build.yaml
CMakeLists.txt
ci/build-macos-binary [new file with mode: 0755]
cmake/Findzstd.cmake

index e7c099a6861c2ecbaa39920a4ccbe7949b711a4c..363afdcbb4de92698d5a6b94124e1bab43a60917 100644 (file)
@@ -220,6 +220,26 @@ jobs:
           name: ${{ matrix.config.sys}}-${{ matrix.config.env }}-${{ matrix.config.compiler }}-testdir.tar.xz
           path: testdir.tar.xz
 
+  build_macos_universal:
+    name: MacOS Universal Binary
+    runs-on: macos-12
+    env:
+      CMAKE_GENERATOR: Ninja
+    steps:
+      - name: Get source
+        uses: actions/checkout@v2
+      - name: Install Dependencies
+        run: |
+          HOMEBREW_NO_AUTO_UPDATE=1 HOMEBREW_NO_INSTALL_CLEANUP=1 \
+              brew install ninja
+      - name: Build macOS universal binary
+        run: ci/build-macos-binary
+      - name: Archive universal binary
+        uses: actions/upload-artifact@v3
+        with:
+          name: macOS-binary
+          path: build_universal/ccache
+
   specific_tests:
     name: ${{ matrix.config.name }}
     runs-on: ${{ matrix.config.os }}
index 6407690ec2de4d848c76716974034c320954c75f..06644f74fb09f3ea55c20b5ee1db1a1727ddd9a1 100644 (file)
@@ -117,6 +117,9 @@ option(ZSTD_FROM_INTERNET
 option(HIREDIS_FROM_INTERNET
   "Download and use libhiredis from the Internet if not available" ON)
 
+option(FORCE_INTERNET_ZSTD
+  "Only use libzstd from the Internet" OFF)
+
 find_package(zstd 1.1.2 MODULE REQUIRED)
 
 option(REDIS_STORAGE_BACKEND "Enable Redis remote storage" ON)
diff --git a/ci/build-macos-binary b/ci/build-macos-binary
new file mode 100755 (executable)
index 0000000..44381d3
--- /dev/null
@@ -0,0 +1,24 @@
+#!/bin/sh
+
+set -eu
+
+build() {
+    mkdir -p "build_$1"
+    cd "build_$1"
+    cmake -DFORCE_INTERNET_ZSTD=ON -DCMAKE_OSX_DEPLOYMENT_TARGET="10.15" -DCMAKE_OSX_ARCHITECTURES="$1" -DCMAKE_SYSTEM_PROCESSOR="$1" ..
+    cmake --build .
+    cd ..
+}
+
+FILES=""
+set -- x86_64 arm64
+
+for i in "$@"; do
+    echo "Building $i"
+    build "$i"
+    FILES="${FILES} build_$i/ccache"
+done
+
+mkdir -p build_universal
+lipo -create $FILES -output build_universal/ccache
+lipo -info build_universal/ccache
index a6d30a4f3759f9f313c93b4356031708a80deb1e..2ce763d5588f410c739ab39e3034243b7b995eae 100644 (file)
@@ -4,14 +4,16 @@ endif()
 
 set(zstd_FOUND FALSE)
 
-find_package(PkgConfig)
-if(PKG_CONFIG_FOUND)
-  pkg_search_module(PC_ZSTD libzstd)
-  find_library(ZSTD_LIBRARY zstd HINTS ${PC_ZSTD_LIBDIR} ${PC_ZSTD_LIBRARY_DIRS})
-  find_path(ZSTD_INCLUDE_DIR zstd.h HINTS ${PC_ZSTD_INCLUDEDIR} ${PC_ZSTD_INCLUDE_DIRS})
-else()
-  find_library(ZSTD_LIBRARY zstd)
-  find_path(ZSTD_INCLUDE_DIR zstd.h)
+if(NOT FORCE_INTERNET_ZSTD)
+  find_package(PkgConfig)
+  if(PKG_CONFIG_FOUND)
+    pkg_search_module(PC_ZSTD libzstd)
+    find_library(ZSTD_LIBRARY zstd HINTS ${PC_ZSTD_LIBDIR} ${PC_ZSTD_LIBRARY_DIRS})
+    find_path(ZSTD_INCLUDE_DIR zstd.h HINTS ${PC_ZSTD_INCLUDEDIR} ${PC_ZSTD_INCLUDE_DIRS})
+  else()
+    find_library(ZSTD_LIBRARY zstd)
+    find_path(ZSTD_INCLUDE_DIR zstd.h)
+  endif()
 endif()
 
 if(ZSTD_LIBRARY AND ZSTD_INCLUDE_DIR)