#521

fix(main): isolate macOS-only native FFI symbols

OpenNook001wants to merge intofrom

What changed

  • Move six macOS-only native wrapper bindings out of the common dlopen symbol table.
  • Load them through a separate optional handle only on macOS.
  • Guard alpha blending, WGPU input handlers, and native text calls when those optional exports are unavailable.
  • Add a source-contract regression test so platform-only exports cannot accidentally return to the common binding table.

Why

Bun resolves the full symbol table passed to dlopen eagerly. The Windows native wrapper does not export these six macOS capabilities, so one missing symbol prevented the entire native wrapper from loading and made otherwise valid core APIs unavailable.

This keeps the common binding table aligned with cross-platform exports while preserving the existing macOS functionality through feature detection.

Closes #520.

Validation

  • bun test package/src/shared/native-platform-ffi.test.ts: 2 passed, 0 failed, 20 assertions.
  • Targeted FFI and related Windows/DPI tests: 16 passed, 0 failed, 92 assertions.
  • End-to-end with electrobun@1.18.4-beta.25 on Windows at 150% scaling: window starts successfully, Per-Monitor V2 is active, window DPI is 144, and WebView device scale factor is 1.5.
  • git diff --check: passed.

Broader baseline checks were also run. The shared suite had 161 passing tests and 4 failures unrelated to this patch (including an unavailable cl.exe environment check and existing source-contract drift). hutch typecheck retained 9 existing main-branch errors involving missing generated/template modules and test typings; this change introduced no platform-FFI type errors.

Activity

4
copilot-pull-request-reviewer[bot]reviewed2mo ago
copilot-pull-request-reviewer[bot]2mo ago

Pull request overview

This PR fixes cross-platform Bun main-process startup by isolating macOS-only native wrapper FFI symbols into a separate optional dlopen handle on macOS, preventing missing platform exports (e.g., on Windows) from breaking the entire native wrapper load.

Changes:

  • Split six macOS-only native wrapper bindings into a separate macOSNative handle that is only loaded on darwin.
  • Guard alpha blending, WGPU input handler registration, and native text calls behind optional-export feature detection.
  • Add a source-contract regression test to prevent macOS-only exports from re-entering the common binding table.

Reviewed changes

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

FileDescription
package/src/shared/native-platform-ffi.test.tsAdds a regression test that asserts macOS-only exports are not present in the common FFI binding table and that call sites are guarded.
package/src/sdks/main/proc/native.tsMoves macOS-only exports to an optional macOS-only dlopen handle and updates call sites to feature-detect optional symbols.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

copilot-pull-request-reviewer[bot]reviewed2mo ago
copilot-pull-request-reviewer[bot]2mo ago

Pull request overview

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

Suppressed comments (1)

package/src/shared/native-platform-ffi.test.ts:56

  • This assertion is overly brittle because it depends on an exact newline + tab indentation sequence in native.ts (\n\t\t\t). Small formatting changes (or CRLF line endings) will break the test even though behavior is unchanged. Prefer a whitespace-tolerant regex (or split assertions) to make the regression test stable.
		expect(nativeSource).toContain(
			'!hasFFI ||\n\t\t\ttypeof rasterizeText !== "function"',
		);