Skip to content

Commit 25d39a7

Browse files
committed
fix: avoid unsafe auto arch detection in builds
1 parent 77e3810 commit 25d39a7

2 files changed

Lines changed: 32 additions & 5 deletions

File tree

cmake/option.cmake

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,20 @@ set(ARCH_OPTIONS
3838
ENABLE_ARMV8.5A ENABLE_ARMV8.6A
3939
)
4040

41-
set(AUTO_DETECT_ARCH ON)
41+
option(AUTO_DETECT_ARCH
42+
"Auto-detect architecture flags when no explicit ENABLE_* arch option is set"
43+
ON)
44+
set(_EXPLICIT_ARCH_SELECTED OFF)
4245
foreach(opt IN LISTS ARCH_OPTIONS)
4346
if(${opt})
44-
set(AUTO_DETECT_ARCH OFF)
47+
set(_EXPLICIT_ARCH_SELECTED ON)
4548
break()
4649
endif()
4750
endforeach()
51+
if(_EXPLICIT_ARCH_SELECTED)
52+
# Explicit architecture options always win over auto-detection.
53+
set(AUTO_DETECT_ARCH OFF)
54+
endif()
4855

4956
include(CheckCCompilerFlag)
5057

@@ -89,11 +96,23 @@ function(_detect_armv8_best)
8996
endfunction()
9097

9198
function(_detect_x86_best)
99+
if(NOT CMAKE_CROSSCOMPILING)
100+
# For native builds, match the actual host CPU capabilities.
101+
check_c_compiler_flag("-march=native" _COMP_SUPP_native)
102+
if(_COMP_SUPP_native)
103+
_AppendFlags(CMAKE_C_FLAGS "-march=native")
104+
_AppendFlags(CMAKE_CXX_FLAGS "-march=native")
105+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" PARENT_SCOPE)
106+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" PARENT_SCOPE)
107+
return()
108+
endif()
109+
endif()
110+
92111
set(_x86_flags
93-
"graniterapids" "emeraldrapids" "sapphirerapids"
94-
"skylake-avx512" "skylake"
95-
"broadwell" "haswell" "sandybridge" "nehalem"
112+
"haswell" "broadwell" "skylake"
113+
"sandybridge" "nehalem"
96114
"znver3" "znver2" "znver1"
115+
"x86-64-v2" "x86-64"
97116
)
98117
foreach(_arch IN LISTS _x86_flags)
99118
check_c_compiler_flag("-march=${_arch}" _COMP_SUPP_${_arch})

pyproject.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,14 @@ manylinux-aarch64-image = "manylinux_2_28"
174174
# Skip 32-bit builds and musllinux
175175
skip = ["*-manylinux_i686", "*-musllinux*"]
176176

177+
[[tool.cibuildwheel.overrides]]
178+
select = "*-manylinux_x86_64"
179+
environment = { CMAKE_ARGS = "-DAUTO_DETECT_ARCH=OFF -DENABLE_HASWELL=ON" }
180+
181+
[[tool.cibuildwheel.overrides]]
182+
select = "*-manylinux_aarch64"
183+
environment = { CMAKE_ARGS = "-DAUTO_DETECT_ARCH=OFF -DENABLE_ARMV8A=ON" }
184+
177185
[tool.cibuildwheel.macos]
178186
archs = ["arm64"]
179187
environment = { MACOSX_DEPLOYMENT_TARGET = "11.0" }

0 commit comments

Comments
 (0)