From 8f85b3bdecf450980bdce15477cf68d02c21ba14 Mon Sep 17 00:00:00 2001 From: Ray Zane Date: Thu, 1 Oct 2026 17:09:03 -0400 Subject: [PATCH] fix: build bundled Linux dependencies with -O2 On Linux, dependency_build_env set CFLAGS to just -fPIC (plus -mno-outline-atomics on arm64). Setting CFLAGS replaces each project's default optimization level, so libyaml, libffi, libxcrypt, zlib, OpenSSL, ncurses, and libedit were all compiled at -O0. zlib compression, bcrypt, and the C parts of OpenSSL ran several times slower than with distro builds of the same libraries. Put -O2 ahead of any inherited CFLAGS, so dependencies are optimized even when CFLAGS is set, while an -O level in CFLAGS still takes precedence. -fPIC stays last so it always applies. -O2 matches what Ubuntu builds these libraries with, except zlib, which Ubuntu and upstream build at -O3. Co-Authored-By: Claude Opus 5.5 --- libexec/package.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libexec/package.rb b/libexec/package.rb index 0508a57..1e7e072 100755 --- a/libexec/package.rb +++ b/libexec/package.rb @@ -844,8 +844,8 @@ def dependency_build_env(extra = {}) if linux? compile_flags = ["-fPIC"] compile_flags << "-mno-outline-atomics" if linux_arm64? - flags["CFLAGS"] = [ENV["CFLAGS"], *compile_flags].compact.join(" ") - flags["CXXFLAGS"] = [ENV["CXXFLAGS"], *compile_flags].compact.join(" ") + flags["CFLAGS"] = ["-O2", ENV["CFLAGS"], *compile_flags].compact.join(" ") + flags["CXXFLAGS"] = ["-O2", ENV["CXXFLAGS"], *compile_flags].compact.join(" ") end build_env(flags.merge(extra)) end