From 8a04e2558c0ee48e8637e454b54ebf76d6bcfdac Mon Sep 17 00:00:00 2001 From: Mateusz Charytoniuk Date: Thu, 27 Aug 2026 15:55:01 +0200 Subject: [PATCH 1/3] Name the crashing MSVC test with a serial run --- .github/workflows/unit-tests.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index f4d1bf12..792562c7 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -44,6 +44,10 @@ jobs: - uses: ./.github/actions/install-rust-toolchain + - name: DIAGNOSTIC - serial run to name the crashing test + if: runner.os == 'Windows' + run: cargo test -p llama-cpp-bindings --lib -- --test-threads=1 --nocapture + - run: make test.unit cppcheck: From b27f72c1a2bf830cb3fd93b5ee9ab81c09daad96 Mon Sep 17 00:00:00 2001 From: Mateusz Charytoniuk Date: Thu, 27 Aug 2026 16:12:05 +0200 Subject: [PATCH 2/3] Revert "Name the crashing MSVC test with a serial run" This reverts commit 8a04e2558c0ee48e8637e454b54ebf76d6bcfdac. --- .github/workflows/unit-tests.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 792562c7..f4d1bf12 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -44,10 +44,6 @@ jobs: - uses: ./.github/actions/install-rust-toolchain - - name: DIAGNOSTIC - serial run to name the crashing test - if: runner.os == 'Windows' - run: cargo test -p llama-cpp-bindings --lib -- --test-threads=1 --nocapture - - run: make test.unit cppcheck: From 38a7dcb2a9026354b11e47dd7433e7dbfb667a04 Mon Sep 17 00:00:00 2001 From: Mateusz Charytoniuk Date: Thu, 27 Aug 2026 16:12:59 +0200 Subject: [PATCH 3/3] Compile llama.cpp with unwind semantics on MSVC --- llama-cpp-bindings-build/src/cmake_config.rs | 42 ++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/llama-cpp-bindings-build/src/cmake_config.rs b/llama-cpp-bindings-build/src/cmake_config.rs index 66d2f996..37e83494 100644 --- a/llama-cpp-bindings-build/src/cmake_config.rs +++ b/llama-cpp-bindings-build/src/cmake_config.rs @@ -32,6 +32,7 @@ pub fn configure_and_build(context: &BuildContext) -> Result Option<&'static str> { } } +const fn msvc_exception_handling_flag(target_os: TargetOs) -> Option<&'static str> { + if target_os.is_msvc() { + Some("/EHsc") + } else { + None + } +} + +fn configure_msvc_exception_handling(config: &mut Config, target_os: TargetOs) { + let Some(flag) = msvc_exception_handling_flag(target_os) else { + return; + }; + + config.cxxflag(flag); +} + fn msvc_config_flags(target_os: TargetOs, profile: &str) -> Option<&'static str> { if !target_os.is_msvc() { return None; @@ -294,6 +311,31 @@ fn configure_system_ggml(config: &mut Config) -> Result<(), BuildError> { Ok(()) } +#[cfg(test)] +mod msvc_exception_handling_tests { + use crate::target_os::TargetOs; + use crate::windows_variant::WindowsVariant; + + use super::msvc_exception_handling_flag; + + #[test] + fn msvc_targets_compile_llama_cpp_with_unwind_semantics() { + assert_eq!( + msvc_exception_handling_flag(TargetOs::Windows(WindowsVariant::Msvc)), + Some("/EHsc") + ); + } + + #[test] + fn targets_without_msvc_keep_their_toolchain_default_exception_handling() { + assert_eq!(msvc_exception_handling_flag(TargetOs::Linux), None); + assert_eq!( + msvc_exception_handling_flag(TargetOs::Windows(WindowsVariant::Other)), + None + ); + } +} + #[cfg(test)] mod msvc_config_flag_tests { use crate::target_os::TargetOs;