Skip to content

build: bundle the OCR binary into macOS wheels#10

Merged
sid732 merged 6 commits into
mainfrom
build/bundle-ocr-binary
Jun 23, 2026
Merged

build: bundle the OCR binary into macOS wheels#10
sid732 merged 6 commits into
mainfrom
build/bundle-ocr-binary

Conversation

@sid732

@sid732 sid732 commented Jun 23, 2026

Copy link
Copy Markdown
Owner

Makes pip install localcontextrouter ship working OCR — no manual Swift build, no LCR_OCR_BIN.

What

  • Build hook (hatch_build.py): compiles a universal (arm64 + x86_64) lcr-ocr, bundles it under the package, and tags the wheel py3-none-macosx_11_0_universal2. Skips cleanly when Swift is unavailable (so the sdist still builds), producing a pure wheel in that case.
  • Resolution (ocr.py): LCR_OCR_BIN → bundled copy → PATH → in-repo dev build, restoring the executable bit if installation dropped it.
  • Release CI: builds on macOS so the hook runs, and asserts the wheel is universal2 and contains localcontextrouter/_bin/lcr-ocr.
  • The compiled binary is git-ignored; it is produced at build time, not committed.

Verified locally

  • python -m buildlocalcontextrouter-0.1.0-py3-none-macosx_11_0_universal2.whl containing the binary; twine check passes.
  • Clean venv install of the wheel, no LCR_OCR_BIN and lcr-ocr not on PATH, OCRs an image successfully — zero-setup OCR.
  • lipo confirms the bundled binary is a fat x86_64 arm64 build.

Tests

ruff, ruff format, mypy (strict), pytest (56), including a bundled-binary resolution test.

Notes

  • macOS only. The sdist excludes the binary; a non-macOS install from sdist would lack OCR (the package is macOS-only by design).

sid732 added 6 commits June 22, 2026 20:55
Add a hatch build hook that compiles a universal (arm64 + x86_64) lcr-ocr,
bundles it under the package, and tags the wheel macosx_11_0_universal2. The
hook skips when Swift is unavailable (e.g. the sdist), and the built binary is
git-ignored since it is produced at build time.
Resolve the binary as LCR_OCR_BIN, then the copy bundled in the wheel, then
PATH, then the in-repo dev build, restoring the executable bit if installation
dropped it.
Assert the bundled copy is used when no override is set.
Move the release build to macOS so the Swift hook runs, and assert the wheel
is universal2 and contains the OCR binary.
The macOS wheel ships the OCR binary, so OCR works without building it or
setting LCR_OCR_BIN.
Editable installs invoke the build hook with version 'editable'; some hosts
(e.g. CI without Xcode) have a non-functional swift shim that the which-guard
does not catch. Editable installs never need the bundled binary, so return
early for them.
@sid732 sid732 merged commit ce1d72e into main Jun 23, 2026
6 checks passed
@sid732 sid732 deleted the build/bundle-ocr-binary branch June 23, 2026 03:12
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.

1 participant