Skip to content

Strip foreign-architecture code from the macOS bundle (#10063)#10064

Open
dpage wants to merge 1 commit into
pgadmin-org:masterfrom
dpage:worktree-mac-strip-foreign-arch
Open

Strip foreign-architecture code from the macOS bundle (#10063)#10064
dpage wants to merge 1 commit into
pgadmin-org:masterfrom
dpage:worktree-mac-strip-foreign-arch

Conversation

@dpage

@dpage dpage commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Summary

The macOS app is built for a single architecture (matching the build machine, via ${ARCH}), but relocatable-python pulls the python.org universal2 installer, so the entire Python.framework ships both arm64 and x86_64 slices. PostgreSQL-sourced dylibs (libpq, libssl, ...) may be universal too. The foreign slice is dead weight that bloats the bundle and DMG.

Fixes #10063.

Changes

  • New _strip_architecture() in pkg/mac/build-functions.sh, called from build.sh after _complete_bundle and before code-signing (lipo invalidates signatures, so the existing _codesign_* passes re-sign the thinned binaries — no extra re-sign needed).
  • Removes the universal2 stragglers: the python*-intel64 launcher and the stray config-*-darwin/python.o build object.
  • lipo -thins every fat Mach-O in the bundle to the build arch, preserving file modes (the +x bit the signing pass relies on) and warning rather than failing on any binary that lacks the target slice.
  • Already single-arch inputs (Electron and its helpers, downloaded per-arch) are skipped.
  • Changelog entry under Housekeeping in release_notes_9_16.rst.

Notes

lipo can only keep a slice that already exists — this strips the build machine's foreign slice from an otherwise-correct build; it does not let an arm64 build produce an x86_64 bundle or vice versa.

Summary by CodeRabbit

  • Housekeeping
    • Optimized macOS builds to exclude unused architecture slices from the bundled Python framework, reducing bundle size for single-architecture builds.

)

The macOS app is built for a single architecture (matching the build
machine, via ${ARCH}), but relocatable-python pulls the python.org
universal2 installer, so the entire Python.framework ships both arm64
and x86_64 slices. PostgreSQL-sourced dylibs may be universal too. The
foreign slice is dead weight that bloats the bundle and DMG.

Add a _strip_architecture step, run after _complete_bundle and before
code-signing (lipo invalidates signatures, so the existing sign passes
re-sign the thinned binaries). It removes the universal2 stragglers
(python*-intel64 launcher, config-*-darwin/python.o) and lipo-thins
every fat Mach-O in the bundle to the build arch, preserving file modes
and warning on anything lacking the target slice. Already single-arch
inputs (Electron and its helpers) are skipped.
@coderabbitai

coderabbitai Bot commented Jun 10, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: fa8d56a8-91e7-4095-b45b-30b9017faf5e

📥 Commits

Reviewing files that changed from the base of the PR and between 04fa05c and 45abd1e.

📒 Files selected for processing (3)
  • docs/en_US/release_notes_9_16.rst
  • pkg/mac/build-functions.sh
  • pkg/mac/build.sh

Walkthrough

This PR implements architecture slicing for the macOS bundle. A new _strip_architecture() function detects and thins universal Mach-O binaries in the app bundle to match the build-machine architecture, removing foreign architecture slices and Python framework stragglers. The function is wired into the build pipeline and documented in release notes.

Changes

macOS architecture stripping

Layer / File(s) Summary
Strip architecture function
pkg/mac/build-functions.sh
_strip_architecture() thins universal/fat Mach-O binaries in the bundle to the build-machine target architecture. It removes Python framework universal2 artifacts, iterates through regular files to detect fat binaries via lipo -archs, and replaces them with single-arch versions using lipo -thin while preserving permissions. Non-applicable or failed operations emit warnings and continue.
Build integration and release notes
pkg/mac/build.sh, docs/en_US/release_notes_9_16.rst
_strip_architecture is called after _complete_bundle and before _generate_sbom to establish build step ordering. Release notes document the housekeeping improvement for Issue #10063 stating that foreign-architecture slices are stripped from the macOS bundle so single-arch builds no longer ship unused universal2 Python framework code.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely summarizes the main change: stripping foreign-architecture code from the macOS bundle, with the related issue number.
Linked Issues check ✅ Passed The PR implementation fully addresses all coding requirements from issue #10063: the _strip_architecture() function removes universal2 stragglers, thins all fat Mach-O binaries to the build machine architecture, preserves single-arch artifacts, operates safely when target slices are absent, and performs thinning before signing.
Out of Scope Changes check ✅ Passed All changes are directly scoped to the stated objectives: release notes entry, new _strip_architecture() function, and its invocation in the build script. No extraneous modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Reduces the size of the macOS pgAdmin4 app bundle by stripping unused (foreign) CPU architecture slices from universal/fat Mach-O binaries (notably the universal2 Python.framework pulled in via relocatable-python) before code-signing.

Changes:

  • Adds _strip_architecture() to thin fat Mach-O files in the bundle to the build machine’s target architecture and remove universal2 installer stragglers.
  • Wires the new strip step into the macOS build pipeline before SBOM generation and code-signing.
  • Documents the change in the v9.16 release notes (Housekeeping).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
pkg/mac/build.sh Invokes _strip_architecture after bundle completion and before SBOM/signing.
pkg/mac/build-functions.sh Implements architecture stripping/thinning and removes universal2 Python installer leftovers.
docs/en_US/release_notes_9_16.rst Adds a release note entry for Issue #10063 under Housekeeping.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +419 to +426
perms=$(stat -f '%Lp' "${f}")
if lipo -thin "${LIPO_ARCH}" "${f}" -output "${f}.thin"; then
chmod "${perms}" "${f}.thin"
mv -f "${f}.thin" "${f}"
else
rm -f "${f}.thin"
echo "WARNING: failed to thin ${f}" >&2
fi
rm -f "${f}.thin"
echo "WARNING: failed to thin ${f}" >&2
fi
done < <(find "${BUNDLE_DIR}" -type f)
Comment on lines +411 to +414
# Already single-arch (our arch) — nothing to strip.
if [ "$(echo "${archs}" | wc -w)" -le 1 ]; then
continue
fi
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.

macOS bundle ships both arm64 and x86_64 Python code (universal2), bloating single-arch builds

2 participants