From 2ce1032012c7545d65c3c65ca428639bcdfb14d7 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Tue, 29 Sep 2026 17:35:08 -0700 Subject: [PATCH] Enable libwebp's SSE2 paths on wasm32-unknown-emscripten with simd128 Emscripten lowers the SSE2 and SSE4.1 intrinsics to wasm simd128, and cpu.h derives WEBP_HAVE_SSE2/SSE41 from the compiler's __SSE2__ and __SSE4_1__, so passing -msimd128 -msse2 (and -msse4.1 with the sse41 feature) when the Rust target has the simd128 feature is all that is needed. The vendored libwebp still selects its wasm CPU-info path on the legacy EMSCRIPTEN macro that emcc no longer defines; libwebp moved to __EMSCRIPTEN__ in v1.6.0-167 (53394835). Until the submodule is past that, -DEMSCRIPTEN in CFLAGS is additionally needed for the SSE2 paths to be selected at runtime. --- build.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/build.rs b/build.rs index 7f65200..e483d77 100644 --- a/build.rs +++ b/build.rs @@ -103,6 +103,7 @@ fn setup_build(build: &mut cc::Build, include_dir: &PathBuf) { } let target_arch = env::var("CARGO_CFG_TARGET_ARCH").expect("CARGO_CFG_TARGET_ARCH"); + let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap_or_default(); let target_features = env::var("CARGO_CFG_TARGET_FEATURE").unwrap_or_default(); let has_feature = |f: &str| target_features.split(',').any(|feature| feature == f); @@ -152,6 +153,14 @@ fn setup_build(build: &mut cc::Build, include_dir: &PathBuf) { build.debug(false); } } + // Emscripten lowers the SSE intrinsics to wasm simd128; cpu.h derives + // WEBP_HAVE_SSE2/SSE41 from the compiler's __SSE2__/__SSE4_1__. + "wasm32" if target_os == "emscripten" && has_feature("simd128") => { + build.flag("-msimd128").flag("-msse2"); + if cfg!(feature = "sse41") { + build.flag("-msse4.1"); + } + } _ => {} }; }