From 42b5397ce0c11787c5a468943cadda64cbab18cb Mon Sep 17 00:00:00 2001 From: Yonatan Gross Date: Wed, 5 Aug 2026 18:59:43 +0300 Subject: [PATCH] fix(build): build vendored opus so arm64 links on Homebrew hosts `audiopus_sys` probes pkg-config first and returns early on a hit, so the vendored opus that `CMAKE_POLICY_VERSION_MINIMUM` exists to compile never gets built when the host has a system libopus. On an Apple Silicon Mac that also carries an Intel Homebrew at /usr/local, pkg-config's default search path includes /usr/local/lib/pkgconfig, so an x86_64 libopus is linked into an arm64 binary and the desktop build dies at link time with "Undefined symbols for architecture arm64: _opus_encoder_create, ...". CI never hits this (no Homebrew opus), which is why the opus source has to be pinned here rather than left to ambient host state. Sets both bypass vars deliberately: LIBOPUS_NO_PKG is audiopus_sys's own documented switch, but its build.rs never emits `cargo:rerun-if-env-changed=LIBOPUS_NO_PKG`, so on a tree that already resolved to the system libopus cargo reuses the cached build script and the setting reads as inert. OPUS_NO_PKG_CONFIG is declared by pkg-config-rs via rerun-if-env-changed, so it actually invalidates the cached script. Verified the intended path now runs: cargo:info=Bypassed `pkg-config`. cargo:info=Building Opus via CMake. cargo:rustc-link-search=native=.../release/build/audiopus_sys-.../out/lib Signed-off-by: Yonatan Gross Co-Authored-By: Claude --- .cargo/config.toml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/.cargo/config.toml b/.cargo/config.toml index d42c757d31..94b34a4960 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -9,3 +9,33 @@ debug = "line-tables-only" # cmake_minimum_required < 3.5; audiopus_sys's vendored opus declares 3.1. # Same workaround CI uses. A value already set in the environment wins. CMAKE_POLICY_VERSION_MINIMUM = "3.5" +# Always build the vendored opus rather than whatever `pkg-config` happens to +# find on the host. `audiopus_sys`'s build.rs probes pkg-config FIRST and +# returns early on a hit, so a system libopus silently wins over the vendored +# source the line above exists to compile. On an Apple Silicon Mac that also +# carries an Intel Homebrew at /usr/local, pkg-config's default search path +# includes /usr/local/lib/pkgconfig, so an x86_64 libopus gets linked into an +# arm64 binary and the build dies at link time with +# "Undefined symbols for architecture arm64: _opus_encoder_create, ...". +# CI never hits this (no Homebrew opus), which is exactly why it has to be +# pinned here instead of left to ambient host state. +# +# TWO vars, deliberately, because only one of them is cache-correct: +# +# LIBOPUS_NO_PKG audiopus_sys's own documented bypass. States the intent, +# but build.rs never emits +# `cargo:rerun-if-env-changed=LIBOPUS_NO_PKG` — so on a +# tree that already resolved to the system libopus, cargo +# reuses the cached build script and this reads as INERT. +# (`cargo clean -p audiopus_sys` does not reliably evict +# the build-script output dir either.) +# OPUS_NO_PKG_CONFIG pkg-config-rs's per-library opt-out. It IS declared via +# `cargo:rerun-if-env-changed`, so setting it actually +# invalidates the cached build script and forces the +# vendored cmake path to run. +# +# Verify a build really took the intended path: +# grep -r 'cargo:info=Bypassed' \ +# desktop/src-tauri/target/*/release/build/audiopus_sys-*/output +LIBOPUS_NO_PKG = "1" +OPUS_NO_PKG_CONFIG = "1"