From 0a50b18e122b8f77a65ec068a72787c166bf08d8 Mon Sep 17 00:00:00 2001 From: rankun <870709864@qq.com> Date: Fri, 10 Jan 2025 13:11:47 +0800 Subject: [PATCH] feat: build mac arm64 --- .github/workflows/macos.yml | 10 +++++----- QtScrcpy/CMakeLists.txt | 11 +++++++++++ ci/mac/build_for_mac.sh | 26 ++++++++++++++++++++++++-- ci/mac/publish_for_mac.sh | 24 ++++++++++++++++++++++-- 4 files changed, 62 insertions(+), 9 deletions(-) diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 58f2fdbcb..fc247e98d 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -17,8 +17,8 @@ jobs: strategy: matrix: qt-ver: [6.5.3] - qt-arch-install: [clang_64] - clang-arch: [x64] + qt-arch-install: [arm64] + build-arch: [x64, arm64] env: target-name: QtScrcpy qt-install-path: ${{ github.workspace }}/${{ matrix.qt-ver }} @@ -47,7 +47,7 @@ jobs: ENV_QT_PATH: ${{ env.qt-install-path }} run: | python ci/generate-version.py - ci/mac/build_for_mac.sh RelWithDebInfo + ci/mac/build_for_mac.sh RelWithDebInfo ${{ matrix.build-arch }} # 获取ref最后一个/后的内容 - name: Get the version shell: bash @@ -59,9 +59,9 @@ jobs: id: package env: ENV_QT_PATH: ${{ env.qt-install-path }} - publish_name: ${{ env.target-name }}-${{ env.plantform-des }}-${{ matrix.clang-arch }}-${{ steps.get-version.outputs.version }} + publish_name: ${{ env.target-name }}-${{ env.plantform-des }}-${{ matrix.build-arch }}-${{ steps.get-version.outputs.version }} run: | - ci/mac/publish_for_mac.sh ../build + ci/mac/publish_for_mac.sh ../build ${{ matrix.build-arch }} ci/mac/package_for_mac.sh mv ci/build/QtScrcpy.app ci/build/${{ env.publish_name }}.app mv ci/build/QtScrcpy.dmg ci/build/${{ env.publish_name }}.dmg diff --git a/QtScrcpy/CMakeLists.txt b/QtScrcpy/CMakeLists.txt index 595003c1b..e6f8cf6fc 100755 --- a/QtScrcpy/CMakeLists.txt +++ b/QtScrcpy/CMakeLists.txt @@ -28,6 +28,17 @@ if(CMAKE_SIZEOF_VOID_P EQUAL 8) else() set(QC_CPU_ARCH x86) endif() + +# MacOS +if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") + # mac default arch arm64 + if(NOT CMAKE_OSX_ARCHITECTURES) + set(CMAKE_OSX_ARCHITECTURES arm64) + endif() + + set(QC_CPU_ARCH ${CMAKE_OSX_ARCHITECTURES}) +endif() + message(STATUS "[${PROJECT_NAME}] CPU_ARCH:${QC_CPU_ARCH}") # CMake set diff --git a/ci/mac/build_for_mac.sh b/ci/mac/build_for_mac.sh index 47910156d..df3a4ba08 100755 --- a/ci/mac/build_for_mac.sh +++ b/ci/mac/build_for_mac.sh @@ -8,7 +8,6 @@ echo --------------------------------------------------------------- # 从环境变量获取必要参数 # 例如 /Users/barry/Qt5.12.5/5.12.5 echo ENV_QT_PATH $ENV_QT_PATH -qt_cmake_path=$ENV_QT_PATH/clang_64/lib/cmake/Qt5 # 获取绝对路径,保证其他目录执行此脚本依然正确 { @@ -22,6 +21,7 @@ cd $(dirname "$0") # 启动参数声明 build_mode=RelWithDebInfo +cpu_arch=arm64 echo echo @@ -36,8 +36,30 @@ if [[ $build_mode != "Release" && $build_mode != "Debug" && $build_mode != "MinS exit 1 fi +echo +echo +echo --------------------------------------------------------------- +echo check cpu arch[x64/arm64] +echo --------------------------------------------------------------- + +cpu_arch=$(echo $2) +if [[ $cpu_arch != "x64" && $cpu_arch != "arm64" ]]; then + echo "error: unkonow cpu mode -- $2" + exit 1 +fi + # 提示 echo current build mode: $build_mode +echo current cpu mode: $cpu_arch + +cmake_arch=x86_64 +if [ $cpu_arch == "x64" ]; then + qt_cmake_path=$ENV_QT_PATH/clang_64/lib/cmake/Qt5 + cmake_arch=x86_64 +else + qt_cmake_path=$ENV_QT_PATH/macos/lib/cmake/Qt6 + cmake_arch=arm64 +fi echo echo @@ -58,7 +80,7 @@ fi mkdir $build_path cd $build_path -cmake_params="-DCMAKE_PREFIX_PATH=$qt_cmake_path -DCMAKE_BUILD_TYPE=$build_mode -DCMAKE_OSX_ARCHITECTURES=x86_64" +cmake_params="-DCMAKE_PREFIX_PATH=$qt_cmake_path -DCMAKE_BUILD_TYPE=$build_mode -DCMAKE_OSX_ARCHITECTURES=$cmake_arch" cmake $cmake_params ../.. if [ $? -ne 0 ] ;then echo "cmake failed" diff --git a/ci/mac/publish_for_mac.sh b/ci/mac/publish_for_mac.sh index c16b42600..01e671451 100755 --- a/ci/mac/publish_for_mac.sh +++ b/ci/mac/publish_for_mac.sh @@ -7,7 +7,6 @@ echo --------------------------------------------------------------- # 从环境变量获取必要参数 # 例如 /Users/barry/Qt5.12.5/5.12.5 echo ENV_QT_PATH $ENV_QT_PATH -qt_clang_path=$ENV_QT_PATH/clang_64 # 获取绝对路径,保证其他目录执行此脚本依然正确 { @@ -21,6 +20,27 @@ cd $(dirname "$0") # 启动参数声明 publish_dir=$1 +cpu_arch=$2 + +echo +echo +echo --------------------------------------------------------------- +echo check cpu arch[x64/arm64] +echo --------------------------------------------------------------- + +if [[ $cpu_arch != "x64" && $cpu_arch != "arm64" ]]; then + echo "error: unkonow cpu mode -- $2" + exit 1 +fi + +# 提示 +echo current cpu mode: $cpu_arch + +if [ $cpu_arch == "x64" ]; then + qt_clang_path=$ENV_QT_PATH/clang_64 +else + qt_clang_path=$ENV_QT_PATH/macos +fi # 提示 echo current publish dir: $publish_dir @@ -30,7 +50,7 @@ keymap_path=$script_path/../../keymap # config_path=$script_path/../../config publish_path=$script_path/$publish_dir -release_path=$script_path/../../output/x64/RelWithDebInfo +release_path=$script_path/../../output/$cpu_arch/RelWithDebInfo export PATH=$qt_clang_path/bin:$PATH