feat: Add macOS support to Swift Package Manager build system#2815
Draft
Saadnajmi wants to merge 8 commits intomicrosoft:mainfrom
Draft
feat: Add macOS support to Swift Package Manager build system#2815Saadnajmi wants to merge 8 commits intomicrosoft:mainfrom
Saadnajmi wants to merge 8 commits intomicrosoft:mainfrom
Conversation
[pull] main from microsoft:main
a22ab6e to
30d348a
Compare
|
2 tasks
- RCTLinkingManager.mm: combine iOS and macOS implementations into a single file using #if TARGET_OS_OSX guards, remove macos/ overlay directory, and clean up podspec - RCTCursor.m: replace Foundation + conditional AppKit imports with RCTUIKit umbrella header - RCTViewComponentView.mm: remove duplicate cursor property check introduced during merge Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add .macOS(.v14) platform to Package.swift - Create React-RCTUIKit as its own SPM module with conditional UIKit/AppKit linking - Port findMatchingHermesVersion and hermesCommitAtMergeBase from Ruby to JS - Add macOS platform and destination to prebuild CLI - Link RCTUIKit and macOS view platform headers in setup Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add "macosx" to the create_universal_framework call so the published Hermes xcframework includes a native macOS slice. The macOS framework is already built by build-mac-framework.sh and placed in destroot/Library/Frameworks/macosx/ — it just wasn't included in the xcodebuild -create-xcframework step. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…rball When downloading prebuilt Hermes from Maven, the tarball contains a standalone macOS framework at destroot/Library/Frameworks/macosx/ but the xcframework at destroot/Library/Frameworks/universal/ does not include it. After extraction, rebuild the xcframework using xcodebuild -create-xcframework to include the macOS slice. This is a workaround until the upstream build-ios-framework.sh change (commit 2) is adopted by Meta's CI pipeline. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
5f31f61 to
fa8de90
Compare
Add a new reusable workflow (microsoft-build-spm.yml) that tests SPM builds for ios, macos, and visionos on every PR. Wire it into the PR gate job in microsoft-pr.yml. Also add visionos/visionos-simulator as supported platforms in the ios-prebuild CLI so CI and local builds can target visionOS. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
fa8de90 to
21908c3
Compare
The cleanup commit accidentally removed the core dark mode fix from HostPlatformColor.mm. This re-adds it using performAsCurrentDrawingAppearance instead of manual NSAppearance save/restore for cleaner, exception-safe code. - ColorFromUIColor: resolve dynamic colors against effective appearance - hashFromUIColor: hash both light and dark variants for proper invalidation Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…tion" This reverts commit 0308dac.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Extends the Swift Package Manager (SPM) build system to support macOS, building on the existing iOS/visionOS SPM infrastructure. This enables building React Native as an xcframework with a macOS slice.
Changes
Package.swift
.macOS(.v14)to platformsReact-RCTUIKitas its own SPM module — RCTUIKit needs conditional UIKit (iOS/visionOS) vs AppKit (macOS) linking, which requires it to be a separate target"RCTUIKit"toReact-CoreexcludedPaths to avoid overlapping sources, and added.reactRCTUIKitas a dependencyReact-graphics-AppleandReact-RCTUIKit:reactFabricandreactFabricComponentsso macOS-specific C++ files (HostPlatformViewProps, HostPlatformViewEventEmitter, etc.) get compiledscripts/ios-prebuild/hermes.js
findMatchingHermesVersion()from Ruby (hermes-utils.rb) to JavaScript — maps react-native-macos version to upstream RN version viapeerDependencies['react-native']in package.json, so Hermes artifacts can be downloaded from MavenhermesCommitAtMergeBase()from Ruby — finds the Hermes commit at the merge base with facebook/react-native for main branch builds where no prebuilt artifacts exist (version1000.0.0)allowBuildFromSourceflag tohermesSourceType()so the nightly fallback behavior isn't broken — only allowsBUILD_FROM_HERMES_COMMITwhen on main branch with no explicitHERMES_VERSIONensureMacOSSliceInXCFramework()— after downloading the Hermes tarball from Maven, rebuilds the xcframework to include the macOS slice. The tarball already contains a standalone macOS framework atdestroot/Library/Frameworks/macosx/but it's not included in the xcframework atdestroot/Library/Frameworks/universal/. SPM's BinaryTarget requires an xcframework, so we usexcodebuild -create-xcframeworkto reassemble it with all existing slices plus macOS. This avoids needing any upstream changes to Meta's Hermes publishing pipeline.scripts/ios-prebuild/setup.js
link('React/RCTUIKit', 'React')for RCTUIKit header linking<react/renderer/components/view/MouseEvent.h>which resolves via the non-prefixed search path.scripts/ios-prebuild/cli.js & types.js
'macos'to thePlatformtype and platforms array'macOS'to theDestinationtype andplatformToDestinationmapHow to test locally
Dependencies
Test plan
node scripts/ios-prebuild.js -s -f Debugcompletes successfullynode scripts/ios-prebuild.js -b -f Debug -p macosenters compilation phaseswift package describe --type jsonoutputs valid build graph with macOS targets🤖 Generated with Claude Code