Skip to content

Commit

Permalink
feat: build mac arm64
Browse files Browse the repository at this point in the history
  • Loading branch information
barry-ran committed Jan 10, 2025
1 parent 63c7c02 commit 0a50b18
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 9 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
11 changes: 11 additions & 0 deletions QtScrcpy/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 24 additions & 2 deletions ci/mac/build_for_mac.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

# 获取绝对路径,保证其他目录执行此脚本依然正确
{
Expand All @@ -22,6 +21,7 @@ cd $(dirname "$0")

# 启动参数声明
build_mode=RelWithDebInfo
cpu_arch=arm64

echo
echo
Expand All @@ -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
Expand All @@ -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"
Expand Down
24 changes: 22 additions & 2 deletions ci/mac/publish_for_mac.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

# 获取绝对路径,保证其他目录执行此脚本依然正确
{
Expand All @@ -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
Expand All @@ -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

Expand Down

0 comments on commit 0a50b18

Please sign in to comment.