Homebrew Formulae(公式)
Homebrew Formulae
是一种Homebrew所使用的在线package browser,也就是软件包管理器。实际上每个Formulae(公式)就是指导Homebrew如何安装软件包的一个 Ruby 代码文件
有时候,如果官方Formulae存在问题没有及时更新,可以通过单独下载Formulae文件进行修订,离线安装。本文是一些实践案例
Homebrew 安装 openssl
在 Homebrew初始化 中安装 Colima ,对于早期旧版本 macOS 11,存在一个问题是,当安装 QEMU 需要编译安装 openssl 3.5.0。但是旧操作系统环境,在编译安装 openssl 3.5.0 的test阶段会出现部分失败。这就导致自动安装过程中断,提示报错:
==> Installing qemu dependency: openssl@3
==> perl ./Configure --prefix=/usr/local/Cellar/openssl@3/3.5.0 --openssldir=/usr/local/etc/openssl@3 --libdir=lib no-s
==> make
==> make install MANDIR=/usr/local/Cellar/openssl@3/3.5.0/share/man MANSUFFIX=ssl
==> make HARNESS_JOBS=8 test TESTS=-test_afalg
Last 15 lines from /Users/admin/Library/Logs/Homebrew/openssl@3/04.make:
Failed 5/6 subtests
Test Summary Report
-------------------
82-test_ocsp_cert_chain.t (Wstat: 256 Tests: 3 Failed: 1)
Failed test: 3
Non-zero exit status: 1
80-test_cmp_http.t (Wstat: 1280 Tests: 6 Failed: 5)
Failed tests: 1-5
Non-zero exit status: 5
Files=341, Tests=4408, 224 wallclock secs (19.00 usr 3.24 sys + 848.58 cusr 321.16 csys = 1191.98 CPU)
Result: FAIL
make[2]: *** [run_tests] Error 1
make[1]: *** [_tests] Error 2
make: *** [tests] Error 2
解决方法是手工安装 OpenSSL ,需要先下载 Homebrew的 formula,然后修订这个formula文件,移除 system "make", "test"
行,在编译安装
curl https://raw.githubusercontent.com/Homebrew/homebrew-core/0d032c8a611ab2585585fa3aa919a604ad978286/Formula/o/openssl%403.rb -o openssl@3.rb
# vi [email protected]
# 注释掉 system "make", "HARNESS_JOBS=#{ENV.make_jobs}", "test", "TESTS=-test_afalg"
brew install --build-from-source /path/to/openssl@3.rb
Hoebrew 安装 snappy
snappy是Google开发的一个压缩和解压库,不追求最大压缩率,但是专注于高速和明确的压缩。2025年5月,我在 MacBook Pro 15" Late 2013 上使用 macOS Big Sur version 11.7.10,这个比较陈旧的macOS系统安装 Colima 遇到一个依赖安装问题:
brew install qemu
报告 cmake
版本过低问题:
==> Installing qemu dependency: snappy
==> Patching
==> cmake -S . -B build/static -DSNAPPY_BUILD_TESTS=OFF -DSNAPPY_BUILD_BENCHMARKS=OFF
Last 15 lines from /Users/admin/Library/Logs/Homebrew/snappy/01.cmake:
-Wno-dev
-DBUILD_TESTING=OFF
-DCMAKE_OSX_SYSROOT=/Library/Developer/CommandLineTools/SDKs/MacOSX11.sdk
CMake Error at CMakeLists.txt:29 (cmake_minimum_required):
Compatibility with CMake < 3.5 has been removed from CMake.
Update the VERSION argument <min> value. Or, use the <min>...<max> syntax
to tell CMake that the project requires at least <min> but has been updated
to work with policies introduced by <max> or earlier.
Or, add -DCMAKE_POLICY_VERSION_MINIMUM=3.5 to try configuring anyway.
-- Configuring incomplete, errors occurred!
但是,我检查 homebrew 实际上已经安装了 /usr/loca/bin/cmake
版本是 4.0.1
这个问题有点类似 VDT Configuration Errors (Mac OS 15.4) ,似乎有多个项目兼容cmake 4.0有问题。果然,在snappy的github项目上,已经有人提出了issue: Require Update to CMakeLists.txt for source build due to new CMake 4.0(+) requirements #204 ,这个修复是在 snappy 1.2.2 ,但是目前 homebrew-core/snappy 1.2.2 #216761 还阻塞没有合并,所以当前安装的是 snappy 1.2.1 存在这个报错
可以参考 Homebrew Formulae: snappy 当前确实是 1.2.1 版本( snappy 官方 1.2.2 是3月26日发布,我当前在5月2日安装可以看到homebrew还停留在1.2.1)
curl https://github.com/Homebrew/homebrew-core/raw/1863e0823cd79776240c6637df06678a2523e12f/Formula/s/snappy.rb -o snappy.rb
# vi snappy.rb
# 将 url 行下载的 1.2.1.tar.gz 修改为 1.2.2.tar.gz 并修订对应的sha256值:
# url "https://github.com/google/snappy/archive/refs/tags/1.2.2.tar.gz"
# sha256 "90f74bc1fbf78a6c56b3c4a082a05103b3a56bb17bca1a27e052ea11723292dc"
# 注释掉patch行(因为最新版本1.2.2不需要针对1.2.1的patch)
brew install --build-from-source snappy.rb
Homebrew 安装qemu
在旧版本macOS Big Sur上安装 qemu
除了遇到上述openssl和snappy的formulae的异常之外,还有一个对编译器版本要求的报错:
==> Downloading https://download.qemu.org/qemu-10.0.0.tar.xz
...
==> ./configure --cc=clang --host-cc=clang --disable-bsd-user --disable-download --disable-guest-agent --enable-slirp -
...
../meson.build:357:4: ERROR: Problem encountered: You either need GCC v7.4 or Clang v10.0 (or XCode Clang v15.0) to compile QEMU
A full log can be found at /private/tmp/qemu-20250503-34203-2xk44i/qemu-10.0.0/build/meson-logs/meson-log.txt
ERROR: meson setup failed
由于笔记本 MacBook Pro 15" Late 2013 硬件限制,只能安装Big Sur,也就导致Xcode clang版本停留在 13.0。我尝试通过 Homebrew 安装高版本gcc:
brew install gcc
sudo ln -s /usr/local/bin/gcc-14 /usr/local/bin/gcc
但是发现报错依旧,难道在macOS平台默认只能使用Clang来编译(即使我安装了符合要求的gcc版本)?可以看到configure时候制定了 --cc=clang --host-cc=clang
仔细检查 qemu.rb
可以看到传递给 configure
的配置使用了 #{ENV.cc}
,正是这个参数导致默认用了clang,我需要将这个参数改成使用自己安装的高版本gcc
我尝试修订 qemu.rb
,将:
qemu.rb
args = %W[
--prefix=#{prefix}
--cc=#{ENV.cc}
--host-cc=#{ENV.cc}
...
修改成
qemu.rb
args = %W[
--prefix=#{prefix}
--cc=gcc
--host-cc=gcc
...
这样果然能够看到 ./configure --cc=gcc --host-cc=gcc --disable-bsd-user ...
,但是报错依旧,似乎 meson.build
没有使用这个传递参数。
MacPort: qemu @9.2.0_0: ERROR: Problem encountered: You either need GCC v7.4 or Clang v10.0 (or XCode Clang v15.0) to compile QEMU 提到了 qemu 需要 macOS 12 or later
检查了 qemu 的issue error: implicit declaration of function 'IOMainPort' is invalid in C99 官方只支持两个主要macOS版本:
Sonoma (14)
Sequoia (15)
[PATCH] meson.build: Refuse XCode versions < v15.0 已经移除了旧版本macOS的支持