From fa042b130cdef939fe6b338f3ad31830ea66d8a3 Mon Sep 17 00:00:00 2001 From: Siavash Sameni Date: Fri, 10 Apr 2026 12:43:36 +0400 Subject: [PATCH] fix(windows): sed-patch cargo-xwin toolchain to enable SSE4.1/SSSE3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The CFLAGS_x86_64_pc_windows_msvc env-var approach from 990b6f1 did nothing — cargo-xwin ships its own clang-cl cmake toolchain file at ~/.cache/cargo-xwin/cmake/clang-cl/x86_64-pc-windows-msvc-toolchain.cmake which hardcodes COMPILE_FLAGS and FORCE-overrides CMAKE_C_FLAGS. Any env-var CFLAGS gets dropped before opus's cmake build sees it. The only place that actually makes it into every C file compilation in the libopus subbuild is the toolchain file itself. Patch it in place with an idempotent sed that appends /clang:-msse4.1 /clang:-mssse3 /clang:-msse3 /clang:-msse2 right before the closing paren of the COMPILE_FLAGS setter. The patch is marked with a WZP_SSE_PATCH comment so re-runs skip it. Confirmed the error message matches with/without the env var — same 20 clang errors from NSQ_del_dec_sse4_1.c / NSQ_sse4_1.c before and after 990b6f1, which is how we ruled out the env-var path. --- scripts/build-windows-docker.sh | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/scripts/build-windows-docker.sh b/scripts/build-windows-docker.sh index ba4ff98..e5e59bf 100755 --- a/scripts/build-windows-docker.sh +++ b/scripts/build-windows-docker.sh @@ -182,12 +182,20 @@ set -euo pipefail # feature sse4.1, but would be inlined into a function that is # compiled without support for sse4.1" # -# Workaround: set global CFLAGS for the Windows target so every C file -# in libopus (and any other cc-rs crate) compiles with SSE4.1/SSSE3 -# enabled. All x86_64 Windows CPUs shipped since 2008 support these, -# so the global enablement is safe for the target platform. -export CFLAGS_x86_64_pc_windows_msvc="/clang:-msse4.1 /clang:-mssse3 /clang:-msse3 /clang:-msse2" -export CXXFLAGS_x86_64_pc_windows_msvc="/clang:-msse4.1 /clang:-mssse3 /clang:-msse3 /clang:-msse2" +# env-var CFLAGS do NOT help here: cargo-xwin ships its own CMake +# toolchain file (~/.cache/cargo-xwin/cmake/clang-cl/x86_64-pc-windows-msvc-toolchain.cmake) +# which hardcodes COMPILE_FLAGS and FORCE-overrides CMAKE_C_FLAGS, +# so anything we export via CFLAGS_$TARGET gets dropped. The only +# place that actually reaches every C compilation inside the opus +# cmake build is the toolchain file itself. Patch it in place with +# a one-shot sed: append four /clang:-m* flags immediately before +# 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" +fi cd /build/source/desktop