-
Notifications
You must be signed in to change notification settings - Fork 6
Fix native module compilation for macOS (Electron 38) and Windows (Spectre mitigation) #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Fix native module compilation for macOS (Electron 38) and Windows (Spectre mitigation) #24
Conversation
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.
|
Hey @Tkaixiang ... This PR should fix macOS! Let me know if you need me too change anything! I'd be glad to walk you through the other PR's I've submitted as well... |
|
Hi Mike, thank you for your PRs. Unfortuantely I do not have the time to review them at the moment due to irl commitments. I should be more free in a few weeks time :) |
scratchpad/scratchpad.md
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, please remove this file as it is not related to the repository :)
| 'msvs_configuration_attributes': { | ||
| - 'SpectreMitigation': 'Spectre' | ||
| + 'SpectreMitigation': 'false' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a need to remove SpectreMitigation when it can be installed easily via the Visual Studio Installer?
SpectreMitigation is a useful security feature with minimal performance impact.
| "build:unpack": "npm run minify-locales && npm run build && electron-builder --dir", | ||
| "build:win": "npm run minify-locales && npx @electron/rebuild && npm run build && electron-builder --win --publish never", | ||
| "build:mac": "npm run minify-locales && npx @electron/rebuild && npm run build && electron-builder --mac --publish never", | ||
| "build:linux": "npm run minify-locales && npx @electron/rebuild && npm run build && electron-builder --linux --publish never" | ||
| "build:mac": "npm run minify-locales && npm run build && electron-builder --mac --publish never", | ||
| "build:linux": "npm run minify-locales && npx @electron/rebuild && npm run build && electron-builder --linux --publish never", | ||
| "postinstall": "patch-package" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a specific reason why we removed npx @electron/rebuild and instead relied on npmRebuild in electron-builder.yml? The GitHub Mac runners seem to compile the builds just fine?
The scratchpad file has been moved to a separate branch (feature/scratchpad-notes) as it is not related to the native module compilation fixes in this PR.
|
Re: removing The The current approach relies on:
This is cleaner and avoids the redundant |
|
I just removed those extraneous files. Sorry about that. I'm new to the git PR workflow since I mostly just work by myself most of the time. Apologies for the confusion. |
Summary
Fixes native module compilation issues on both macOS and Windows by patching
native-keymapbindingconfiguration.
Issues Fixed
macOS (Electron 38)
error: 'value' is unavailable: introduced in macOS 11.0Windows
MSB8040: Spectre-mitigated libraries are required for this projectChanges
Added Dependencies
patch-packageas devDependency to apply native module patches during installationPatch File
Created
patches/native-keymap+3.3.5.patchwith:'SpectreMitigation': 'false'(Windows fix)'CLANG_CXX_LANGUAGE_STANDARD': 'c++20'
'CLANG_CXX_LIBRARY': 'libc++'
'MACOSX_DEPLOYMENT_TARGET': '11.0'
Package.json
"postinstall": "patch-package"script to automatically apply patches after npm installBuild Requirements
Installation Instructions
Standard Installation (Recommended)
Fixes Issue #8