Skip to content

Make plain cargo build work on macOS arm64 (#92)#100

Merged
RyanCodrai merged 1 commit into
mainfrom
fix-macos-cargo-build
Jun 9, 2026
Merged

Make plain cargo build work on macOS arm64 (#92)#100
RyanCodrai merged 1 commit into
mainfrom
fix-macos-cargo-build

Conversation

@RyanCodrai

Copy link
Copy Markdown
Owner

Closes #92.

Problem

A bare cargo build (or cargo test) on macOS Apple Silicon fails to link the turbovec-python extension module:

ld: symbol(s) not found for architecture arm64
clang: error: linking with `cc` failed: exit status: 1

The cdylib references Python interpreter symbols (Py_True, etc.) that are only present at load time. maturin injects the right linker args (-undefined dynamic_lookup on macOS) so the link succeeds, but a plain cargo build doesn't — so anyone cloning and running cargo build hits a wall. Reproduced locally.

Fix

Add a build.rs for turbovec-python that calls pyo3_build_config::add_extension_module_link_args() (with the matching pyo3-build-config build-dependency). This emits the platform-correct extension-module linker args for a bare cargo build, matching what maturin already does. End-user pip install is unaffected (wheels are built by maturin either way).

Also clears the 3 pre-existing build warnings the reporter asked about:

  • two unused n_groups bindings in the NEON scoring kernels
  • the scalar score_query_into_heap fallback is cfg-gated out of aarch64 builds, where the NEON kernel is always used and it was dead code (still compiled for x86_64, where it's the pre-AVX2 fallback)

Verification (macOS arm64)

  • cargo build ✅ · cargo build --release ✅ — both now link, zero warnings
  • cargo test -p turbovec ✅ — all suites pass

Approach matches the patch suggested by @yihong0618 in the issue; implemented and verified independently.

🤖 Generated with Claude Code

A bare `cargo build` on macOS failed to link the turbovec-python
extension module — 'symbol(s) not found for architecture arm64' — because
nothing emitted the Python-extension linker args that resolve interpreter
symbols (Py_True, etc.) at load time. maturin injects these, but a plain
cargo build did not.

Add a build.rs for turbovec-python calling
pyo3_build_config::add_extension_module_link_args() (with the matching
pyo3-build-config build-dependency), so cargo build/test work directly.

Also clear the 3 pre-existing build warnings the reporter noted: drop two
unused n_groups bindings in the NEON kernels, and cfg-gate the scalar
score_query_into_heap fallback out of aarch64 builds where it is never
reached.

Reported by @yihong0618.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@RyanCodrai RyanCodrai merged commit 15694dd into main Jun 9, 2026
6 checks passed
@RyanCodrai RyanCodrai deleted the fix-macos-cargo-build branch June 9, 2026 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

can not build on mac arm when simple run cargo build

1 participant