From e9c8a35f5aa7c441d8962dc7e67478af5ab21f55 Mon Sep 17 00:00:00 2001 From: can1357 Date: Fri, 24 Jul 2026 10:11:02 +0200 Subject: [PATCH] fix(natives): routed msvc sse flags through plain CFLAGS for cargo-xwin cargo-xwin overwrites CFLAGS_ on the cargo it spawns and only appends plain CFLAGS/CXXFLAGS into it, so the sse4 override must use those. --- packages/natives/scripts/build-native.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/natives/scripts/build-native.ts b/packages/natives/scripts/build-native.ts index 2778b87fe..194f9faea 100644 --- a/packages/natives/scripts/build-native.ts +++ b/packages/natives/scripts/build-native.ts @@ -376,11 +376,15 @@ if (crossTarget) { // enforces per-function target features: opus' silk/x86 SSE4.1 units fail to // build without the feature enabled globally. The win32 x64 addon floor is // x86-64-v2 (SSE4.2 inclusive), so enabling it for all C deps is safe. + // cargo-xwin overwrites `CFLAGS_` on the cargo it spawns but appends + // the plain `CFLAGS`/`CXXFLAGS` values into it, so those are the only knobs + // that survive. if (crossTarget.endsWith("-msvc") && targetArch === "x64") { - const envKey = `CFLAGS_${bareTriple.replace(/-/g, "_")}`; - const existing = process.env[envKey] ?? ""; - const sseFlags = "-msse4.1 -msse4.2"; - process.env[envKey] = existing ? `${existing} ${sseFlags}` : sseFlags; + for (const envKey of ["CFLAGS", "CXXFLAGS"]) { + const existing = process.env[envKey] ?? ""; + const sseFlags = "-msse4.1 -msse4.2"; + process.env[envKey] = existing ? `${existing} ${sseFlags}` : sseFlags; + } } // napi 3.7.0 resolves the built artifact from the FULL `--target` directory, // but cargo-zigbuild writes under the bare triple; bridge the two so napi's