From fa9586dd20e46552bf2b000cb04b3035d2d80117 Mon Sep 17 00:00:00 2001 From: Volker Mauel Date: Sat, 2 Aug 2025 08:43:37 +0200 Subject: [PATCH 1/3] Disable -march=native when cross-compiling to different CPU --- ggml/CMakeLists.txt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ggml/CMakeLists.txt b/ggml/CMakeLists.txt index e63520f015..db8168562d 100644 --- a/ggml/CMakeLists.txt +++ b/ggml/CMakeLists.txt @@ -50,7 +50,13 @@ else() set(GGML_BLAS_VENDOR_DEFAULT "Generic") endif() -if (CMAKE_CROSSCOMPILING) +# Disable native builds when cross-compiling or when the target processor +# differs from the host processor. In some environments (e.g. Windows +# arm64 cross-builds using clang), CMake does not set the +# CMAKE_CROSSCOMPILING flag even though the target architecture is +# different. Passing `-march=native` in such cases results in compiler +# errors, so explicitly check the processor as well. +if (CMAKE_CROSSCOMPILING OR NOT (CMAKE_SYSTEM_PROCESSOR STREQUAL CMAKE_HOST_SYSTEM_PROCESSOR)) set(GGML_NATIVE_DEFAULT OFF) else() set(GGML_NATIVE_DEFAULT ON) From d956d11108bf09d627a456e98c9d55bda12cb0e6 Mon Sep 17 00:00:00 2001 From: Volker Mauel Date: Sat, 2 Aug 2025 11:10:46 +0200 Subject: [PATCH 2/3] Prefer DWARF debug info when cross-compiling --- ggml/CMakeLists.txt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ggml/CMakeLists.txt b/ggml/CMakeLists.txt index db8168562d..ef3abbb3e3 100644 --- a/ggml/CMakeLists.txt +++ b/ggml/CMakeLists.txt @@ -58,8 +58,17 @@ endif() # errors, so explicitly check the processor as well. if (CMAKE_CROSSCOMPILING OR NOT (CMAKE_SYSTEM_PROCESSOR STREQUAL CMAKE_HOST_SYSTEM_PROCESSOR)) set(GGML_NATIVE_DEFAULT OFF) + set(GGML_CROSS_DIFFERENT_ARCH ON) else() set(GGML_NATIVE_DEFAULT ON) + set(GGML_CROSS_DIFFERENT_ARCH OFF) +endif() + +# When cross-compiling with clang for Windows the default CodeView debug +# info can trigger LLVM backend crashes. In that case, prefer DWARF +# debug info instead. +if (GGML_CROSS_DIFFERENT_ARCH AND WIN32 AND CMAKE_C_COMPILER_ID STREQUAL "Clang") + add_compile_options(-gdwarf-4) endif() # general From b1054e436908f70ad4cf14001b3dd9cac37b5abd Mon Sep 17 00:00:00 2001 From: Volker Mauel Date: Sat, 2 Aug 2025 11:25:49 +0200 Subject: [PATCH 3/3] Guard x86 intrinsics and strip CodeView when cross-compiling --- ggml/CMakeLists.txt | 4 ++++ ggml/src/iqk/iqk_quantize.cpp | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ggml/CMakeLists.txt b/ggml/CMakeLists.txt index ef3abbb3e3..d374245acc 100644 --- a/ggml/CMakeLists.txt +++ b/ggml/CMakeLists.txt @@ -69,6 +69,10 @@ endif() # debug info instead. if (GGML_CROSS_DIFFERENT_ARCH AND WIN32 AND CMAKE_C_COMPILER_ID STREQUAL "Clang") add_compile_options(-gdwarf-4) + foreach(lang C CXX) + string(REGEX REPLACE "-Xclang[ ]+-gcodeview" "" CMAKE_${lang}_FLAGS "${CMAKE_${lang}_FLAGS}") + set(CMAKE_${lang}_FLAGS "${CMAKE_${lang}_FLAGS}" CACHE STRING "" FORCE) + endforeach() endif() # general diff --git a/ggml/src/iqk/iqk_quantize.cpp b/ggml/src/iqk/iqk_quantize.cpp index ece0b7346e..6664f7af30 100644 --- a/ggml/src/iqk/iqk_quantize.cpp +++ b/ggml/src/iqk/iqk_quantize.cpp @@ -31,7 +31,7 @@ #include #include -#if defined(_MSC_VER) +#if defined(_MSC_VER) && (defined(_M_X64) || defined(_M_IX86)) #pragma warning(disable: 4244 4267) // possible loss of data #include #include