Skip to content

Delete node-gyp debris and strip addons when bottling - #23645

Merged
MikeMcQuaid merged 1 commit into
stale-elf-stringsfrom
node-gyp-debris
Aug 26, 2026
Merged

Delete node-gyp debris and strip addons when bottling#23645
MikeMcQuaid merged 1 commit into
stale-elf-stringsfrom
node-gyp-debris

Conversation

@MikeMcQuaid

@MikeMcQuaid MikeMcQuaid commented Aug 24, 2026

Copy link
Copy Markdown
Member
  • node-gyp compiles native addons inside the keg at install time and
    leaves obj.target trees, *.o objects, *.d dependency files and
    intermediate *.a archives behind under node_modules; they embed
    build paths that pin about 33 npm formulae's bottles and are never
    needed at run time (addons load the linked .node files, not the
    objects they were linked from).
  • brew bottle now deletes them alongside *.pyc files, scoped to
    node_modules trees (*.a further to node-gyp build trees) so
    legitimate shipped objects and archives are untouched.
  • The linked .node addons themselves embed keg build paths in their
    N_OSO/N_SO stab strings, so brew bottle also runs
    strip -S -o on them, replacing each addon only when strip
    succeeds. Verified on hsd's published leveldown.node: 76 keg
    paths before, 0 after, with the signature still valid because Apple
    strip re-signs ad hoc, so no separate codesign step is needed.

This change is part of plans/relocatable-bottles.md


  • Have you followed our Contributing guidelines?
  • Have you checked for other open Pull Requests for the same change?
  • Have you explained what your changes do? Performance claims (e.g. "this is faster") must include brew benchmark results.
  • Have you explained why you'd like these changes included, not just what they do?
  • For bug fixes, have you given step-by-step brew commands to reproduce the bug?
  • Have you written new tests (excluding integration tests)? Here's an example.
  • Have you successfully run brew lgtm (style, typechecking and tests) locally?

  • I did not use AI/LLM to create this PR, or I disclosed the tool/model below and reviewed its output; I did not attribute commits to AI and will answer maintainer questions and review comments myself without AI/LLM.

Claude Fable 5 with local review and testing.


@github-actions

Copy link
Copy Markdown
Contributor

Thanks for your pull request. This has been closed because it appears to be missing the pull request template, perhaps because this was written by an AI not a human. We require humans to read and fill in these templates.

Please edit this pull request to fill in the current pull request template. This workflow will reopen this pull request automatically once the template is complete. Do not open a new pull request for this.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This pull request improves bottle relocatability for npm-installed formulae by removing node-gyp intermediate build artifacts from bottled kegs and stripping debug information from compiled .node addons so embedded build paths don鈥檛 pin bottles.

Changes:

  • Add Keg#delete_node_gyp_debris! to remove node-gyp intermediate obj.target trees and related .o, .d, and build-tree .a files under node_modules.
  • Add Keg#strip_node_gyp_addons! to run strip -S on .node addons under node_modules, replacing the addon only when stripping succeeds.
  • Invoke both new cleanup steps during brew bottle, and add RSpec coverage for the new Keg behavior.

Reviewed changes

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

File Description
Library/Homebrew/keg.rb Implements node-gyp debris deletion and .node addon stripping helpers on Keg.
Library/Homebrew/dev-cmd/bottle.rb Runs the new keg cleanup steps as part of the bottling flow.
Library/Homebrew/test/keg_spec.rb Adds tests validating debris cleanup and conditional addon replacement on strip success/failure.
Library/Homebrew/plans/relocatable-bottles.md Removes the plan item now implemented by this PR.

馃挕 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

@MikeMcQuaid
MikeMcQuaid force-pushed the node-gyp-debris branch 2 times, most recently from 9f5e46e to 48524ba Compare August 25, 2026 11:17
@MikeMcQuaid
MikeMcQuaid force-pushed the node-gyp-debris branch 2 times, most recently from 050e7b3 to e67986e Compare August 25, 2026 14:55
- node-gyp compiles native addons inside the keg at install time and
  leaves `obj.target` trees, `*.o` objects, `*.d` dependency files and
  intermediate `*.a` archives behind under `node_modules`; they embed
  build paths that pin about 33 npm formulae's bottles and are never
  needed at run time (addons load the linked `.node` files, not the
  objects they were linked from).
- `brew bottle` now deletes them alongside `*.pyc` files, scoped to
  `node_modules` trees (`*.a` further to node-gyp `build` trees) so
  legitimate shipped objects and archives are untouched.
- The linked `.node` addons themselves embed keg build paths in their
  `N_OSO`/`N_SO` stab strings, so `brew bottle` also runs
  `strip -S -o` on them, replacing each addon only when `strip`
  succeeds. Verified on `hsd`'s published `leveldown.node`: 76 keg
  paths before, 0 after, with the signature still valid because Apple
  `strip` re-signs ad hoc, so no separate codesign step is needed.

This change is part of [`plans/relocatable-bottles.md`](https://github.com/Homebrew/brew/blob/HEAD/Library/Homebrew/plans/relocatable-bottles.md)
@MikeMcQuaid
MikeMcQuaid added this pull request to the merge queue Aug 26, 2026
Merged via the queue into main with commit aec6979 Aug 26, 2026
65 of 77 checks passed
@MikeMcQuaid
MikeMcQuaid deleted the node-gyp-debris branch August 26, 2026 18:23
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.

4 participants