Fix desktop native optional dependency packaging #3816
main fromrefs/pull/3816/head·merged by juliusmarminge View on GitHubSummary#
Fixes desktop packaging regressions where nightly Linux and Windows builds could ship ffi-rs without the platform-native optional @yuuang/ffi-rs-* binding required at runtime.
Covered issues:
Problem#
Recent nightly desktop builds started failing during backend startup because the packaged app included ffi-rs, but did not include the native optional dependency that ffi-rs loads for the current platform.
On Linux AppImage builds, the backend crashed with:
Cannot find module '@yuuang/ffi-rs-linux-x64-gnu'
On Windows builds, affected users saw the app never render a window. The server child process was crash-looping with:
Cannot find module '@yuuang/ffi-rs-win32-x64-msvc'
Both failures happen before the desktop backend can become ready, so the UI either shows a generic Electron process error or never opens.
Root Cause#
There were two related packaging gaps.
Linux AppImage#
The staged production pnpm-workspace.yaml declared the target os and cpu, but did not declare libc.
Packages such as @yuuang/ffi-rs-linux-x64-gnu are optional dependencies with:
{
"os": ["linux"],
"cpu": ["x64"],
"libc": ["glibc"]
}
Without libc: ["glibc"], pnpm could skip that optional native package during the staged production install, leaving ffi-rs present but unable to resolve its Linux binding.
Windows#
The Windows stage already requested the right target architectures, including Windows and Linux/glibc for WSL. However, Electron Builder was detecting the staged app as an npm project when collecting node_modules.
Because the staged install uses pnpm, npm-style collection can miss optional dependency subtrees from the pnpm layout. That caused the Windows artifact to omit packages like:
@yuuang/ffi-rs-win32-x64-msvc
The fix explicitly passes a pnpm user agent to Electron Builder so it uses the pnpm collector for the staged app.
Changes#
- Add
libc: ["glibc"]to Linux desktop staging architecture metadata. - Keep Windows staging behavior for host Windows plus Linux/glibc WSL backend.
- Add
resolvePackageManagerUserAgent()to convertpackageManagersyntax:
pnpm@11.10.0
into npm user-agent syntax:
pnpm/11.10.0
- Set
buildEnv.npm_config_user_agentbefore invoking Electron Builder. - Add tests for Linux staging architecture metadata and packageManager-to-user-agent conversion.
Validation#
Commands run:
vp test run scripts/build-desktop-artifact.test.ts
vp check
vp run typecheck
Local artifacts generated for verification:
node scripts/build-desktop-artifact.ts --platform linux --target AppImage --arch x64 --build-version 0.0.29-nightly.20260708.999 --output-dir release-test
node scripts/build-desktop-artifact.ts --platform win --target nsis --arch x64 --build-version 0.0.29-nightly.20260708.999 --output-dir release-test --skip-build
Artifact inspection confirmed:
- Linux AppImage includes:
resources/app.asar.unpacked/node_modules/@yuuang/ffi-rs-linux-x64-gnu/ffi-rs.linux-x64-gnu.node
- Windows installer includes:
resources/app.asar.unpacked/node_modules/@yuuang/ffi-rs-win32-x64-msvc/ffi-rs.win32-x64-msvc.node
Note: the local Windows installer was generated without T3CODE_DESKTOP_WSL_PREBUILD, so it validates the primary Windows backend packaging path and the missing ffi-rs binding, but not the WSL backend binary path.
Note
Fix desktop native optional dependency packaging for Linux and package manager user agent#
- Adds
libc: ["glibc"]tosupportedArchitecturesincreateStageWorkspaceConfigfor Linux builds in build-desktop-artifact.ts, ensuring native optional dependencies targeting glibc are included during staged production installs. - Introduces
resolvePackageManagerUserAgent, which converts apackage.jsonpackageManagerfield (e.g.pnpm@11.10.0) to a user-agent string (pnpm/11.10.0) for use by electron-builder. - Sets
npm_config_user_agentin the electron-builder environment using the derived user agent before the env-scrubbing step.
Note
Medium Risk Changes only desktop packaging scripts but affect runtime-critical native modules; mis-staging would still break backend startup on Linux/Windows without obvious compile-time failures.
Overview
Fixes desktop builds shipping ffi-rs without the platform-specific @yuuang/ffi-rs-* optional bindings, which caused Linux AppImage and Windows backend crash-loops (Cannot find module '@yuuang/ffi-rs-…').
Linux staging: createStageWorkspaceConfig now sets libc: ["glibc"] for Linux targets (not only Windows), so staged pnpm install --prod resolves glibc-scoped optional natives like @yuuang/ffi-rs-linux-x64-gnu.
Electron Builder / Windows: Adds resolvePackageManagerUserAgent() to map root packageManager (pnpm@11.10.0) to npm_config_user_agent form (pnpm/11.10.0), and sets that on the electron-builder env so collection uses the pnpm layout and optional Windows bindings (e.g. @yuuang/ffi-rs-win32-x64-msvc) are not dropped.
Tests cover Linux workspace supportedArchitectures (including libc in full yaml fixtures) and user-agent conversion.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
Approvability#
Verdict: Approved
Build script bug fix that adds missing
You can customize Macroscope's approvability policy. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).libc: ["glibc"]configuration for Linux desktop builds and a utility function for electron-builder package manager detection. Changes are limited to packaging scripts with good test coverage.Also seeing this on MacOS chipsets (SEE: Discord Thread):
ARM:
Error: Cannot find module '@yuuang/ffi-rs-darwin-arm64'Intel:Error: Cannot find module '@yuuang/ffi-rs-darwin-x64'Can confirm the npm_config_user_agent change fixes the macOS arm64 case too (#3804). Traced it independently before finding this PR.
Electron-builder detects pnpm fine at first (staged package.json packageManager field), but then resolves the workspace root via pnpm --workspace-root exec pwd and uses the raw stdout as a path. In the freshly staged app pnpm 11 prepends install/verify output, so the "root" comes back as:
? Verifying lockfile against supply-chain policies (372 entries)... Lockfile is up to date, resolution step is skipped ... Done in 2.2s using pnpm v11.10.0 /private/var/folders/.../t3code-desktop-mac-stage-xxx/appRe-detection at that "path" finds nothing -> falls back to npm_config_user_agent -> unset under vp exec -> npm. The npm collector walks the pnpm tree and silently drops optional dep subtrees. @yuuang/ffi-rs-darwin-arm64, @anthropic-ai/claude-agent-sdk-darwin-arm64, @clerk/electron-passkeys-darwin-arm64, @msgpackr-extract/msgpackr-extract-darwin-arm64, msgpackr-extract, detect-libc, node-gyp-build-optional-packages. (mac arm64)
A/B tested master vs master + the env var (only change): master collects 176 modules via the npm collector; with the var set the pnpm collector runs, 183 modules, all 7 back in the asar, app launches. So this fixes #3804 as well.
juliusmarminge approved these changes
juliusmarminge merged this18a4138
juliusmarminge closed this
Sign in to join this conversation.
Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID:
d74879ae-9eee-41bb-bcf3-aeaf77736fcaYou can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.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.
❤️ Share