Skip to content

Conversation

@mikejoseph23
Copy link

@mikejoseph23 mikejoseph23 commented Oct 22, 2025

Summary

Fixes native module compilation issues on both macOS and Windows by patching native-keymap binding
configuration.

Issues Fixed

macOS (Electron 38)

  • Problem: Native modules failed to compile with Electron 38 due to missing C++20 standard configuration
  • Error: error: 'value' is unavailable: introduced in macOS 11.0
  • Solution: Added C++20 xcode_settings with macOS 11.0 deployment target

Windows

  • Problem: Native modules required Spectre-mitigated libraries not installed by default
  • Error: MSB8040: Spectre-mitigated libraries are required for this project
  • Solution: Disabled SpectreMitigation requirement in msvs_configuration_attributes

Changes

Added Dependencies

  • Added patch-package as devDependency to apply native module patches during installation

Patch File

Created patches/native-keymap+3.3.5.patch with:

  1. Line 10: Set 'SpectreMitigation': 'false' (Windows fix)
  2. Lines 18-22: Added xcode_settings for C++20 compilation (macOS fix):
    'CLANG_CXX_LANGUAGE_STANDARD': 'c++20'
    'CLANG_CXX_LIBRARY': 'libc++'
    'MACOSX_DEPLOYMENT_TARGET': '11.0'

Package.json

  • Added "postinstall": "patch-package" script to automatically apply patches after npm install

Build Requirements

⚠️ Node.js ≥20.19.0 required

  • Newer electron-vite v4.0.1 requires Node.js ^20.19.0 or >=22.12.0
  • Earlier versions (v20.18.0) will encounter ESM/CommonJS compatibility errors

Installation Instructions

Standard Installation (Recommended)

npm install
The patch will be applied automatically via the postinstall script.

Manual Installation (If needed)

npm install --ignore-scripts
npx patch-package
npm rebuild

Testing

macOS ✅

- Native modules compile successfully with Electron 38
- Dev and production builds work

Windows ✅

- Native modules compile without MSB8040 Spectre errors
- Full Windows installer built successfully: marktext-win-x64-0.18.5-setup.exe
- Dev and production builds work
- Tested on Windows with Node.js v20.19.5

Affected Modules

All native modules now compile successfully:
- [email protected]
- ced
- keytar

Fixes Issue #8

Resolves native-keymap build failures on macOS caused by missing C++20
compiler flags. The native-keymap dependency requires C++20 features
(constexpr, concept, requires) for Electron 38 compatibility, but the
macOS build configuration was missing the necessary xcode_settings.

Changes:
- Added patch-package to apply C++20 fix to native-keymap binding.gyp
- Created patches/native-keymap+3.3.5.patch with xcode_settings for macOS
- Enabled npmRebuild in electron-builder.yml to properly rebuild native
  modules for both x64 and arm64 architectures
- Added postinstall script to automatically apply patches

The patch adds CLANG_CXX_LANGUAGE_STANDARD: 'c++20' to the macOS build
configuration in native-keymap, allowing it to compile successfully
against Electron 38 headers.

Tested on:
- macOS Ventura 13.7 (Intel iMac 2017) - x64 build
- macOS Sequoia 15.x (M4 MacBook Air 2025) - arm64 build

Fixes Tkaixiang#8
The postinstall script requires patch-package to be installed
as a devDependency. Without it, npm install fails with
'patch-package: command not found'.

This commit completes the native module compilation fix by
ensuring patch-package is available to apply the native-keymap
patches during installation.
Extends the existing native-keymap patch to disable Spectre mitigation
requirements on Windows. This allows the native module to compile without
requiring Spectre-mitigated libraries from Visual Studio.

Changes:
- Set 'SpectreMitigation': 'false' in binding.gyp msvs_configuration_attributes
- Retains existing macOS C++20 fix

This is a test commit to verify the fix works on Windows before merging
into the main PR branch.
- Updated package-lock.json for Node.js 20.19.5 compatibility
- Added test results showing successful Windows build
- Confirmed Spectre mitigation bypass patch works correctly
- Windows installer created: marktext-win-x64-0.18.5-setup.exe (123.5 MB)

All native modules (native-keymap, ced, keytar) compiled successfully
without MSB8040 Spectre errors.
@mikejoseph23 mikejoseph23 changed the title Fix macOS native module compilation for Electron 38 Fix native module compilation for macOS (Electron 38) and Windows (Spectre mitigation) Oct 24, 2025
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.

1 participant