fix(desktop): stage ffi-rs native bindings so the packaged app launches a window#3129
fix(desktop): stage ffi-rs native bindings so the packaged app launches a window#3129akj wants to merge 1 commit into
Conversation
The packaged backend crash-loops on startup with "Cannot find module '@yuuang/ffi-rs-win32-x64-msvc'". ffi-rs (used by @ff-labs/fff-node) loads its prebuilt native addon from a platform-specific @yuuang/ffi-rs-* package, which was never staged into the desktop build. Because the desktop window is gated on backend HTTP readiness, the backend never becomes ready and no window ever opens. Mirror the existing @ff-labs/fff-bin-* staging: promote the target-triple @yuuang/ffi-rs-* binding to a direct staged dependency (version resolved from pnpm-lock.yaml, where ffi-rs is pinned) and add it to asarUnpack so the .node loads outside the asar archive. Refs pingdotgg#3125
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
ApprovabilityVerdict: Approved Build script fix that ensures ffi-rs native bindings are properly staged for the packaged desktop app. The new functions mirror existing patterns exactly, are purely build-time changes, and include comprehensive unit tests. You can customize Macroscope's approvability policy. Learn more. |
Problem
The packaged desktop app launches a main process but never opens a window. The bundled backend server crash-loops on startup with:
Because the desktop window is gated on backend HTTP readiness (
DesktopBackendManagerpolls/.well-known/t3/environment, thenDesktopWindow.handleBackendReadycreates the window), a backend that never becomes ready means the window is never created — while the main process stays alive restarting the backend forever. First observed on nightly0.0.28-nightly.20260616.571(win32-x64).Root cause
@ff-labs/fff-node(thefffworkspace-search integration, #3099) loads its native binary through theffi-rsFFI runtime.ffi-rs@1.3.2loads its prebuilt addon from a platform-specific package — on Windows x64,@yuuang/ffi-rs-win32-x64-msvc(anoptionalDependencyofffi-rs).#3109 staged the
fffbinary packages (@ff-labs/fff-bin-*) and added them toasarUnpack, but did not stageffi-rs's own native binding. electron-builder reliably keeps direct production deps but prunes platform-gated transitive optional deps in pnpm layouts, so@yuuang/ffi-rs-*was dropped from the package entirely. The staging logic omitted it for all platforms, so mac/linux builds are affected too.Fix
Mirror the
@ff-labs/fff-bin-*treatment for the FFI binding inscripts/build-desktop-artifact.ts:resolveFfiRsNativeDependencies(platform, arch, version)— promote the target-triple@yuuang/ffi-rs-*binding to a direct staged dependency so electron-builder keeps it (covers macdarwin-{arm64,x64}, winwin32-{x64,arm64}-msvc, linuxlinux-{x64,arm64}-{gnu,musl}, anduniversal).node_modules/@yuuang/ffi-rs-*/**/*toDESKTOP_ASAR_UNPACKso the.nodeloads outside the asar.pnpm-lock.yaml(ffi-rsis transitive, so it has no package.json entry; bindings ship in lockstep withffi-rs). The build fails loudly ifffi-rscan't be resolved, so this can't silently regress.Validation
scriptstypecheck clean; new unit tests forresolveFfiRsNativeDependenciesandparseFfiRsLockfileVersion; fullscriptssuite green.resources/app.asar.unpacked/node_modules/@yuuang/ffi-rs-win32-x64-msvc/ffi-rs.win32-x64-msvc.nodeis now present (the broken nightly had no@yuuangdir at all).Follow-up (not in this PR)
The build now enumerates two native package families by hand (
@ff-labs/fff-bin-*,@yuuang/ffi-rs-*). A deeper fix would auto-discover.node-bearing packages in the staged tree and unpack them, so a future native transitive dep can't reintroduce this bug class. A win32-x64 smoke test that boots the backend would also have caught this.Fixes #3125
Note
Medium Risk
Changes the desktop staging/install path that determines which native modules ship in production artifacts; mistakes could break all platform builds, but the change mirrors an existing pattern and adds explicit lockfile validation and tests.
Overview
Fixes packaged desktop builds where the bundled backend crash-looped on missing
@yuuang/ffi-rs-*native modules (used by@ff-labs/fff-nodeviaffi-rs), so the window never opened.The desktop artifact script now promotes platform-specific
@yuuang/ffi-rs-*packages into staged production dependencies (same approach as@ff-labs/fff-bin-*), unpacks them from the asar viaDESKTOP_ASAR_UNPACK, and pins binding versions by parsing the resolvedffi-rsversion frompnpm-lock.yaml(with a hard failure if it's missing or ambiguous). Unit tests cover dependency resolution, lockfile parsing, and unpack globs.Reviewed by Cursor Bugbot for commit 7ca71ab. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Stage ffi-rs native bindings so the packaged Electron app launches a window
@yuuang/ffi-rs-*packages toDESKTOP_ASAR_UNPACKso Electron unpacks and can load the native addons at runtime.resolveFfiRsNativeDependenciesto compute the platform/arch-specific@yuuang/ffi-rs-*packages to stage, including both gnu and musl variants on Linux.parseFfiRsLockfileVersionto extract the single resolved ffi-rs version frompnpm-lock.yaml, throwing if the version is absent or inconsistent.buildDesktopArtifacthandler now readspnpm-lock.yamlto determine the ffi-rs version and merges the resulting native packages into the staged install.BuildScriptErrorifpnpm-lock.yamlis unreadable or ffi-rs is missing or resolved to multiple versions.Macroscope summarized 7ca71ab.