fix x86_64 arch detection when cross-compiling on macos arm64#6730
Conversation
|
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #6730 +/- ##
==========================================
- Coverage 95.98% 95.97% -0.01%
==========================================
Files 965 965
Lines 404957 404634 -323
==========================================
- Hits 388681 388352 -329
- Misses 16276 16282 +6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Fixes incorrect target architecture detection when cross-compiling ncnn for x86_64 on Apple Silicon (macOS arm64) with -DCMAKE_OSX_ARCHITECTURES=x86_64, which previously caused the build to be treated as ARM and skipped all x86 SIMD feature detection.
Changes:
- Adjust ARM-architecture detection on Apple platforms to avoid using
CMAKE_SYSTEM_PROCESSOR(host CPU) whenCMAKE_OSX_ARCHITECTURESis explicitly set to a non-ARM architecture. - Ensures x86_64 cross-compiles on macOS arm64 properly follow the x86 feature-probing path (SSE/AVX/etc.).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Thanks review. |
|
Thanks for your contribution ! |
Summary
Fix #6505 — when cross-compiling ncnn for x86_64 on macOS arm64 with
-DCMAKE_OSX_ARCHITECTURES=x86_64, the target architecture is incorrectlydetected as ARM, causing all x86 SIMD optimizations (SSE/AVX/AVX2/AVX512)
to be skipped.
Root cause
In
CMakeLists.txt:164,CMAKE_SYSTEM_PROCESSORalways reports the hostCPU (
arm64), even whenCMAKE_OSX_ARCHITECTURESis explicitly set tox86_64. This causes the ARM arch branch to match, settingNCNN_TARGET_ARCHtoarminstead ofx86.Fix
On Apple platforms, skip the
CMAKE_SYSTEM_PROCESSORarm match whenCMAKE_OSX_ARCHITECTURESis explicitly set to a non-arm architecture.Before / After