Path: blob/main/lang/bun/files/patch-scripts_build_deps_libwebp.ts
49052 views
-- Exclude AVX2 DSP sources from libwebp for baseline (v1/SSE2) builds.1-- libwebp compiles lossless_avx2.c and lossless_enc_avx2.c with -mavx2 so the2-- compiler emits AVX2 instructions. Although libwebp uses runtime CPU dispatch3-- so these paths are only executed when AVX2 is detected, the instructions are4-- present in the ELF binary and cause the cpu-microarchitecture classifier to5-- require AVX2. Exclude the _avx2.c files entirely for baseline builds; the6-- SSE2 code paths remain available and are selected at runtime.78--- scripts/build/deps/libwebp.ts.orig 2026-05-23 02:36:10 UTC9+++ scripts/build/deps/libwebp.ts10@@ -98,14 +98,20 @@ const SHARPYUV = [11// (on arm64 these compile to the stub body and the x86 -m flags are invalid).12// Runtime CPU dispatch in dsp/cpu.c picks the best available, so a baseline13// binary still runs on pre-AVX2 hardware.14-function simd(path: string, x64: boolean) {15+function simd(path: string, x64: boolean, baseline: boolean = false) {16if (x64) {17for (const [suf, flag] of [18["_avx2.c", "-mavx2"],19["_sse41.c", "-msse4.1"],20["_sse2.c", "-msse2"],21] as const) {22- if (path.endsWith(suf)) return { path, cflags: [flag] };23+ if (path.endsWith(suf)) {24+ // Exclude AVX2 files for baseline (v1/SSE2) builds: even though25+ // libwebp uses runtime CPU dispatch, the AVX2 instructions must not26+ // be present in the ELF binary at all for baseline compliance.27+ if (baseline && suf === "_avx2.c") return null;28+ return { path, cflags: [flag] };29+ }30}31}32return path;33@@ -126,11 +132,11 @@ export const libwebp: Dependency = {34sources: [35...DEC.map(f => `src/dec/${f}.c`),36...ENC.map(f => `src/enc/${f}.c`),37- ...DSP.map(f => simd(`src/dsp/${f}.c`, cfg.x64)),38+ ...DSP.map(f => simd(`src/dsp/${f}.c`, cfg.x64, cfg.baseline)).filter(Boolean),39...UTILS.map(f => `src/utils/${f}.c`),40...DEMUX.map(f => `src/demux/${f}.c`),41...MUX.map(f => `src/mux/${f}.c`),42- ...SHARPYUV.map(f => simd(`sharpyuv/${f}.c`, cfg.x64)),43+ ...SHARPYUV.map(f => simd(`sharpyuv/${f}.c`, cfg.x64, cfg.baseline)).filter(Boolean),44],45// src/webp/*.h is the public API; internal headers use "src/..."46// includes from the repo root, sharpyuv uses "sharpyuv/...".474849