fix(build): build vendored opus so arm64 links on hosts with an Intel Homebrew - #5041
Open
yonatangross wants to merge 1 commit into
Open
fix(build): build vendored opus so arm64 links on hosts with an Intel Homebrew#5041yonatangross wants to merge 1 commit into
yonatangross wants to merge 1 commit into
Conversation
`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 <yonatan2gross@gmail.com> Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
just desktop-release-buildfails at link time on an Apple Silicon Mac that also has an Intel Homebrew installed:audiopus_sys'sbuild.rsprobespkg-configfirst and returns early on a hit, so the vendored opus that the existingCMAKE_POLICY_VERSION_MINIMUM = "3.5"entry exists to compile never gets built.pkg-config's default search path includes/usr/local/lib/pkgconfig— the Intel Homebrew prefix — so an x86_64libopus.ais statically linked into an arm64 binary.CI never hits this (no Homebrew opus on the runners), which is why the opus source has to be pinned in-repo rather than left to ambient host state.
Fix
Two env vars in
.cargo/config.toml, deliberately both:LIBOPUS_NO_PKGaudiopus_sys's own documented bypass. States the intent — but itsbuild.rsnever emitscargo: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_sysdoes not reliably evict the build-script output dir either.)OPUS_NO_PKG_CONFIGrerun-if-env-changed, so it actually invalidates the cached build script and forces the vendored cmake path to run.Setting only the first one looks correct and changes nothing, which is why both are here with the reasoning inline.
Verification
Before — build script resolved to the Intel prefix:
After:
just desktop-release-build aarch64-apple-darwinthen produces a bundle whoseContents/MacOS/*are 7/7 arm64, and opus is statically linked (no dynamic reference).Anyone can reproduce the original failure with
brew install opusunder an Intel Homebrew on an Apple Silicon host.Scope
One file, config only. No behaviour change on any host that does not have a system libopus — the vendored path is what CI already takes.