Skip to content

Strip unused-arch native prebuilts from packaged installers#3371

Merged
gavande1 merged 7 commits into
trunkfrom
stu-1677-strip-unused-arch-native-prebuilts
May 8, 2026
Merged

Strip unused-arch native prebuilts from packaged installers#3371
gavande1 merged 7 commits into
trunkfrom
stu-1677-strip-unused-arch-native-prebuilts

Conversation

@gavande1
Copy link
Copy Markdown
Contributor

@gavande1 gavande1 commented May 7, 2026

Related issues

How AI was used in this PR

Used Claude to walk through the existing forge.config.ts afterCopy hook, draft the arch-aware filter, and add a defensive guard that refuses to delete prebuilts unless the target arch is present. I reviewed the diff, verified the koffi/fs-ext naming conventions against the actual node_modules layout, and checked that the arch value passed by electron-forge matches the directory/file naming used by both packages (x64, arm64).

Proposed Changes

  • Tighten the koffi cleanup in apps/studio/forge.config.ts to filter by ${platform}_${arch} instead of just ${platform}_. A Linux x64 DEB no longer ships linux_arm64/armhf/ia32/loong64/riscv64d; same shape for Mac/Windows.
  • Add an arch-aware fs-ext-extra-prebuilt cleanup in the same prePackage hook. The root postinstall script still filters by platform only (intentional — at install time we don't know the target arch); the new hook strips the unused arch once arch is in scope.
  • Both blocks include a "must match the target" guard: if the expected dir/file is missing, log a warning and skip rather than wipe everything. This protects against an upstream package renaming things in a future version.

Estimated savings per installer (from the issue):

Installer koffi waste removed
Linux x64 DEB ~7 MB
Linux arm64 DEB ~7 MB
Mac arm64 DMG ~4 MB
Mac x64 DMG ~4 MB
Win x64 MSIX ~3.7 MB
Win arm64 MSIX ~4.1 MB

fs-ext-extra-prebuilt adds a few hundred KB on top.

Testing Instructions

  1. Build the installer for one platform inside the appropriate environment (Linux VM for DEB to avoid the postinstall side-effect on Mac):
    npm run make
    
  2. Inspect the packaged tree — confirm only the target arch remains:
    # Linux DEB
    dpkg-deb -x apps/studio/out/make/deb/*/studio_*.deb /tmp/studio-deb
    ls /tmp/studio-deb/opt/Studio/resources/cli/node_modules/koffi/build/koffi/
    ls /tmp/studio-deb/opt/Studio/resources/cli/node_modules/fs-ext-extra-prebuilt/binaries/
    
    Expected: koffi has exactly one dir matching ${platform}_${arch}; fs-ext only contains files starting with fs-ext-${platform}-${arch}-.
  3. Smoke-launch the installer — install the DEB/DMG/MSIX, launch the app, create or start a site (exercises koffi + fs-ext at runtime). The app must boot and complete a site operation cleanly.
  4. Compare DEB size vs. trunk to confirm the ~7 MB savings landed.
  5. (Optional) Guard test — temporarily set koffiTarget = 'bogus_arch' in the hook, run packaging, confirm the warning fires and koffi prebuilts are untouched. Revert before merge.

CI should cover the cross-platform builds (Buildkite Linux dev build group + macOS + Windows).

Pre-merge Checklist

  • Have you checked for TypeScript, React or other console errors?
  • Smoke-tested at least one platform's installer end to end (build + install + launch + site operation).
  • Confirmed the packaged tree contains only the target arch's prebuilts.

@gavande1 gavande1 changed the title Strip unused-arch native prebuilts from packaged installers (STU-1677) Strip unused-arch native prebuilts from packaged installers May 7, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adjusts Studio’s Electron Forge prePackage hook to strip unused-architecture native prebuilts from the bundled CLI node_modules, reducing installer size and avoiding cross-platform binary/code-signing issues.

Changes:

  • Make koffi prebuilt cleanup arch-aware by keeping only ${platform}_${arch}.
  • Add arch-aware cleanup for fs-ext-extra-prebuilt binaries by keeping only fs-ext-${platform}-${arch}-*.
  • Add defensive “target must exist” guards that skip cleanup if expected target artifacts are missing.

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

Comment on lines +215 to +222
const koffiDirs = fs.readdirSync( koffiBuildDir );
// Refuse to delete anything if the target arch dir is missing — guards
// against a koffi naming change silently nuking every prebuilt.
if ( ! koffiDirs.includes( koffiTarget ) ) {
console.warn(
`Skipping koffi cleanup: no directory named ${ koffiTarget } in ${ koffiBuildDir }`
);
} else {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch — applied in 909eace. Now stat-checks the target before deleting siblings, mirroring the existing isDirectory() check inside the loop.

Comment thread apps/studio/forge.config.ts Outdated
Comment on lines +253 to +254
fs.unlinkSync( path.join( fsExtBinDir, file ) );
console.log( `Removed fs-ext-extra-prebuilt/binaries/${ file }` );
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Applied in 84cd9b2. Wrapped the unlink in try/catch and downgraded failures to a warning, matching the prior art in scripts/remove-fs-ext-other-platform-binaries.mjs. Cleanup is purely a size optimization — not worth aborting packaging over a stuck file.

@gavande1 gavande1 requested review from a team and ivan-ottinger May 7, 2026 10:39
@gavande1 gavande1 marked this pull request as ready for review May 7, 2026 10:39
Copy link
Copy Markdown
Contributor

@ivan-ottinger ivan-ottinger left a comment

Choose a reason for hiding this comment

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

Thank you for the work on the clean-up, Rahul!

The changes look good and work as expected. 👍🏼 I did not observe any regressions. Heres are several screenshots from tests I run.

Filtering of fs-ext-linux-x64-node on arm64 Linux:

Image

Filtering of fs-ext-darwin-x64-node on arm64 macOS:

Image

Reduction in size of the .deb installer (before / after):

Image Image

I have also run the installed app on all three platforms (all arm64) and did not observe any issues. Also found the installer is slightly smaller (as expected).

@wpmobilebot
Copy link
Copy Markdown
Collaborator

wpmobilebot commented May 8, 2026

📊 Performance Test Results

Comparing 529a9dd vs trunk

app-size

Metric trunk 529a9dd Diff Change
App Size (Mac) 1410.41 MB 1408.66 MB 1.75 MB 🟢 -0.1%

site-editor

Metric trunk 529a9dd Diff Change
load 1514 ms 1500 ms 14 ms ⚪ 0.0%

site-startup

Metric trunk 529a9dd Diff Change
siteCreation 8093 ms 8089 ms 4 ms ⚪ 0.0%
siteStartup 4929 ms 4936 ms +7 ms ⚪ 0.0%

Results are median values from multiple test runs.

Legend: 🟢 Improvement (faster) | 🔴 Regression (slower) | ⚪ No change (<50ms diff)

@gavande1 gavande1 merged commit a96f984 into trunk May 8, 2026
10 checks passed
@gavande1 gavande1 deleted the stu-1677-strip-unused-arch-native-prebuilts branch May 8, 2026 10:50
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