From 234a798df2afe3c9ca84cb3de1d58aa8981770fd Mon Sep 17 00:00:00 2001 From: Siavash Sameni Date: Fri, 10 Apr 2026 12:50:00 +0400 Subject: [PATCH] fix(windows): append SSE flags as a pure-CMake block to xwin toolchain MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The previous sed-based patch didn't stick in the docker-bash-c heredoc (bash single-quoting made the newline escaping fragile). Switch to a much simpler approach: just 'cat >>' a pure-CMake block to the end of the cargo-xwin toolchain file. The block does: set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /clang:-msse4.1 ..." CACHE STRING "" FORCE) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /clang:-msse4.1 ..." CACHE STRING "" FORCE) Running AFTER the toolchain's own FORCE-set and AFTER cmake-rs's -DCMAKE_C_FLAGS= command-line override, it unconditionally wins. No sed, no awk, no python, no newline escaping — just CMake reading the toolchain file like it normally does. Idempotent via the WZP_SSE_PATCH sentinel grep in the comment block. --- scripts/build-windows-docker.sh | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/scripts/build-windows-docker.sh b/scripts/build-windows-docker.sh index e5e59bf..a208ea1 100755 --- a/scripts/build-windows-docker.sh +++ b/scripts/build-windows-docker.sh @@ -192,10 +192,31 @@ set -euo pipefail # the closing paren of the COMPILE_FLAGS setter. Idempotent across # runs — if the file already contains the sentinel line we skip. TOOLCHAIN_FILE=/home/builder/.cache/cargo-xwin/cmake/clang-cl/x86_64-pc-windows-msvc-toolchain.cmake -if ! grep -q "WZP_SSE_PATCH" "$TOOLCHAIN_FILE"; then - echo ">>> Patching cargo-xwin toolchain for SSE4.1 / SSSE3 intrinsics" - sed -i "s|/imsvc /home/builder/.cache/cargo-xwin/xwin/sdk/include/winrt)|/imsvc /home/builder/.cache/cargo-xwin/xwin/sdk/include/winrt\\n # WZP_SSE_PATCH — enable SSE4.1/SSSE3 so libopus (audiopus_sys) builds\\n /clang:-msse4.1\\n /clang:-mssse3\\n /clang:-msse3\\n /clang:-msse2)|" "$TOOLCHAIN_FILE" +echo ">>> Patching cargo-xwin toolchain for SSE4.1 / SSSE3 intrinsics" +if grep -q WZP_SSE_PATCH "$TOOLCHAIN_FILE"; then + echo " (already patched, skipping)" +else + # The cleanest way to add flags is to append a pure-CMake block to + # the end of the toolchain file. Both CMAKE_C_FLAGS and + # CMAKE_CXX_FLAGS were already FORCE-set earlier in the toolchain; + # we override them again with the same content plus our SSE flags. + # This runs AFTER the original set(... FORCE) and the CMAKE_ARGS + # from the cmake-rs invocation, so it wins. + cat >> "$TOOLCHAIN_FILE" <>> Toolchain tail after patch:" +tail -15 "$TOOLCHAIN_FILE" cd /build/source/desktop