Skip to content

Commit 77bad86

Browse files
shijiashuaiqwencoder
andcommitted
ci: fix ARM macOS build compatibility
- Detect ARM architecture and use -mcpu=native instead of -march=native - Skip x86-specific flags (-mavx2, -mfma) on ARM, use NEON instead - Update CI matrix to use clang-17/18 instead of clang-15/16 Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
1 parent 5c2c03f commit 77bad86

2 files changed

Lines changed: 36 additions & 13 deletions

File tree

.github/workflows/ci.yml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ jobs:
3737

3838
# Ubuntu with Clang
3939
- os: ubuntu-latest
40-
compiler: clang-15
41-
cc: clang-15
42-
cxx: clang++-15
40+
compiler: clang-17
41+
cc: clang-17
42+
cxx: clang++-17
4343
- os: ubuntu-latest
44-
compiler: clang-16
45-
cc: clang-16
46-
cxx: clang++-16
44+
compiler: clang-18
45+
cc: clang-18
46+
cxx: clang++-18
4747

4848
# macOS
4949
- os: macos-latest
@@ -63,11 +63,13 @@ jobs:
6363
if [[ "${{ matrix.compiler }}" == "gcc-13" ]]; then
6464
sudo apt-get install -y gcc-13 g++-13
6565
fi
66-
if [[ "${{ matrix.compiler }}" == "clang-16" ]]; then
66+
if [[ "${{ matrix.compiler }}" == clang-* ]]; then
6767
wget https://apt.llvm.org/llvm.sh
6868
chmod +x llvm.sh
69-
sudo ./llvm.sh 16
69+
sudo ./llvm.sh ${CLANG_VERSION#clang-}
7070
fi
71+
env:
72+
CLANG_VERSION: ${{ matrix.compiler }}
7173

7274
- name: Install dependencies (macOS)
7375
if: runner.os == 'macOS'

cmake/CompilerOptions.cmake

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
# Uses target-based approach (modern CMake best practice)
44

55
#------------------------------------------------------------------------------
6-
# Detect compiler and set appropriate flags
6+
# Detect compiler and architecture
77
#------------------------------------------------------------------------------
88
set(HPC_IS_GCC FALSE)
99
set(HPC_IS_CLANG FALSE)
1010
set(HPC_IS_MSVC FALSE)
11+
set(HPC_IS_ARM FALSE)
1112

1213
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
1314
set(HPC_IS_GCC TRUE)
@@ -17,6 +18,11 @@ elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
1718
set(HPC_IS_MSVC TRUE)
1819
endif()
1920

21+
# Detect ARM architecture (Apple Silicon, Raspberry Pi, etc.)
22+
if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|arm64|ARM")
23+
set(HPC_IS_ARM TRUE)
24+
endif()
25+
2026
#------------------------------------------------------------------------------
2127
# hpc_set_compiler_options(target)
2228
# Sets warning levels and optimization flags for a target
@@ -50,7 +56,15 @@ function(hpc_set_compiler_options target)
5056
endif()
5157

5258
# Release optimization flags
53-
if(HPC_IS_GCC OR HPC_IS_CLANG)
59+
if(HPC_IS_ARM)
60+
# ARM uses -mcpu=native instead of -march=native
61+
target_compile_options(${target} PRIVATE
62+
$<$<CONFIG:Release>:-O3>
63+
$<$<CONFIG:Release>:-mcpu=native>
64+
$<$<CONFIG:RelWithDebInfo>:-O2>
65+
$<$<CONFIG:RelWithDebInfo>:-g>
66+
)
67+
elseif(HPC_IS_GCC OR HPC_IS_CLANG)
5468
target_compile_options(${target} PRIVATE
5569
$<$<CONFIG:Release>:-O3>
5670
$<$<CONFIG:Release>:-march=native>
@@ -103,8 +117,16 @@ endfunction()
103117
#------------------------------------------------------------------------------
104118
function(hpc_enable_simd target)
105119
cmake_parse_arguments(ARG "SSE;AVX;AVX2;AVX512" "" "" ${ARGN})
106-
107-
if(HPC_IS_GCC OR HPC_IS_CLANG)
120+
121+
if(HPC_IS_ARM)
122+
# ARM uses NEON instead of x86 SIMD
123+
if(HPC_IS_CLANG OR HPC_IS_GCC)
124+
# NEON is enabled by default on AArch64, but we can add march flag
125+
target_compile_options(${target} PRIVATE
126+
$<$<CONFIG:Release>:-mcpu=native>
127+
)
128+
endif()
129+
elseif(HPC_IS_GCC OR HPC_IS_CLANG)
108130
if(ARG_SSE)
109131
target_compile_options(${target} PRIVATE -msse4.2)
110132
endif()
@@ -124,7 +146,6 @@ function(hpc_enable_simd target)
124146
if(ARG_AVX2 OR ARG_AVX512)
125147
target_compile_options(${target} PRIVATE /arch:AVX2)
126148
endif()
127-
# Note: MSVC uses /arch:AVX512 only in newer versions
128149
endif()
129150
endfunction()
130151

0 commit comments

Comments
 (0)