From 5c410d38a623c839a68ad17d35bbc519eae8b44c Mon Sep 17 00:00:00 2001 From: Nathan Walker Date: Fri, 30 Oct 2026 23:25:18 -0700 Subject: [PATCH 1/2] fix(metagen): target the macOS SDK version, as iOS does macOS metadata was generated for macos11.0, and the generator leaves out declarations introduced after the target, so everything newer than macOS 11 was missing from the embedded metadata: ScreenCaptureKit's SCStream (12.3), SCScreenshotManager (14.0), NSGlassEffectView (26.0) and the rest. iOS already targets the SDK version. --- scripts/metagen.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/metagen.js b/scripts/metagen.js index ea9ad899..14befe79 100755 --- a/scripts/metagen.js +++ b/scripts/metagen.js @@ -276,9 +276,11 @@ const sdks = { macos: { path: getSDKPath("macosx"), frameworks: [...COMMON_FRAMEWORKS, ...MACOS_FRAMEWORKS], + // The generator leaves out declarations introduced after the target OS, so + // the target is the SDK itself; classes missing at runtime resolve to undefined. targets: { - x86_64: "x86_64-apple-macos11.0", - arm64: "arm64-apple-macos11.0", + x86_64: `x86_64-apple-macos${getSDKVersion("macosx")}`, + arm64: `arm64-apple-macos${getSDKVersion("macosx")}`, }, }, ios: { From 64dc06c9ccca59090d2bee48a7bcd40544fb95c3 Mon Sep 17 00:00:00 2001 From: Nathan Walker Date: Sun, 1 Nov 2026 15:06:49 -0800 Subject: [PATCH 2/2] feat(react-native): build and run on react-native-macos The TurboModule pod now declares macOS 14 alongside iOS 13, so Expo Desktop and other react-native-macos apps can link it. On macOS: - metadata.macos.{arm64,x86_64}.nsmd is bundled and selected at runtime - Libffi.xcframework carries a macOS slice - the Hermes signature dispatch table is chosen per platform at compile time - NativeScriptUIView (UIKit host views) is left out until an AppKit host exists Verified in an Expo Desktop (SDK 55, react-native-macos 0.83) app: init(), runOnUI worklets reading and writing NSApplication/NSWindow on the main thread, and ScreenCaptureKit captures of the app's own window. --- .../NativeScriptNativeApi.podspec | 15 ++++-- .../ios/NativeScriptNativeApiModule.mm | 51 ++++++++++++++++--- scripts/build_react_native_turbomodule.sh | 25 ++++++++- 3 files changed, 79 insertions(+), 12 deletions(-) diff --git a/packages/react-native/NativeScriptNativeApi.podspec b/packages/react-native/NativeScriptNativeApi.podspec index bfb68590..c5d3a0e7 100644 --- a/packages/react-native/NativeScriptNativeApi.podspec +++ b/packages/react-native/NativeScriptNativeApi.podspec @@ -12,7 +12,7 @@ Pod::Spec.new do |s| s.homepage = "https://github.com/NativeScript/runtimes" s.license = "Apache-2.0" s.author = package["author"] - s.platforms = { :ios => "15.1" } + s.platforms = { :ios => "15.1", :osx => "14.0" } s.source = { :git => "https://github.com/NativeScript/runtimes.git", :tag => "react-native-v#{s.version}" } s.requires_arc = false @@ -23,10 +23,17 @@ Pod::Spec.new do |s| "native-api/jsi/**/*.h", "native-api/ffi/objc/hermes/NativeApiJsi.mm" ] - s.exclude_files = "ios/Fabric/**/*" unless fabric_enabled + s.ios.exclude_files = fabric_enabled ? [] : ["ios/Fabric/**/*"] + # Fabric component views host UIKit views; AppKit has no counterpart yet. + s.osx.exclude_files = [ + "ios/Fabric/**/*" + ] s.public_header_files = "ios/**/*.h" - s.resource_bundles = { - "NativeScriptNativeApi" => ["metadata/*.nsmd"] + s.ios.resource_bundles = { + "NativeScriptNativeApi" => ["metadata/metadata.ios*.nsmd"] + } + s.osx.resource_bundles = { + "NativeScriptNativeApi" => ["metadata/metadata.macos*.nsmd"] } s.vendored_frameworks = "ios/vendor/Libffi.xcframework" diff --git a/packages/react-native/ios/NativeScriptNativeApiModule.mm b/packages/react-native/ios/NativeScriptNativeApiModule.mm index 206efbc2..dd81c5ea 100644 --- a/packages/react-native/ios/NativeScriptNativeApiModule.mm +++ b/packages/react-native/ios/NativeScriptNativeApiModule.mm @@ -2,6 +2,11 @@ #import #import +#if TARGET_OS_OSX +#import +#else +#import +#endif #include #include @@ -10,8 +15,10 @@ #include "NativeApiJsiReactNative.h" #include "NativeScriptFabricGateway.h" +#if !TARGET_OS_OSX #include "Fabric/NativeScriptComponentRegistration.h" #include "Fabric/NativeScriptComponentView.h" +#endif #import #import @@ -37,7 +44,13 @@ } std::string bundledMetadataPath() { -#if TARGET_OS_SIMULATOR +#if TARGET_OS_OSX +#if defined(__x86_64__) + NSString* metadataName = @"metadata.macos.x86_64"; +#else + NSString* metadataName = @"metadata.macos.arm64"; +#endif +#elif TARGET_OS_SIMULATOR #if defined(__x86_64__) NSString* metadataName = @"metadata.ios-sim.x86_64"; #else @@ -199,13 +212,26 @@ bool nativeApiInstalled(facebook::jsi::Runtime& runtime) { return imageLoader; } -UIImage* imageWithRenderingMode(UIImage* image, bool isTemplate) { +#if TARGET_OS_OSX +using NativeScriptPlatformImage = NSImage; +#else +using NativeScriptPlatformImage = UIImage; +#endif + +NativeScriptPlatformImage* imageWithRenderingMode(NativeScriptPlatformImage* image, + bool isTemplate) { if (image == nil) { return nil; } +#if TARGET_OS_OSX + NSImage* copy = [[image copy] autorelease]; + [copy setTemplate:isTemplate]; + return copy; +#else return [image imageWithRenderingMode:isTemplate ? UIImageRenderingModeAlwaysTemplate : UIImageRenderingModeAlwaysOriginal]; +#endif } id imageSourceFromJSIValue(facebook::jsi::Runtime& runtime, @@ -225,9 +251,9 @@ id imageSourceFromJSIValue(facebook::jsi::Runtime& runtime, void callImageLoadCallback( std::weak_ptr workletRuntimeWeak, std::shared_ptr callback, - UIImage* image, + NativeScriptPlatformImage* image, NSString* errorMessage) { - UIImage* retainedImage = image != nil ? [image retain] : nil; + NativeScriptPlatformImage* retainedImage = image != nil ? [image retain] : nil; std::string imageHandle = retainedImage != nil ? nativeScriptHandleFromNSObject(retainedImage).UTF8String : ""; std::string errorText = errorMessage.UTF8String != nullptr ? errorMessage.UTF8String : ""; @@ -380,10 +406,12 @@ void callImageLoadCallback( nativescript::InstallNativeApiJSI(workletRuntime, config); } +#if !TARGET_OS_OSX // ctx.emit / ctx.setContentSize / ctx.scheduleOnMainQueue targets // (src/ui/dispatcher.ts); idempotent, safe to call on every // install (including reload re-installs onto a fresh UI VM). NativeScriptInstallComponentHostFunctions(workletRuntime); +#endif std::weak_ptr imageWorkletRuntimeWeak(workletRuntimeRef); auto loadImage = jsi::Function::createFromHostFunction( @@ -420,11 +448,11 @@ void callImageLoadCallback( resizeMode:RCTResizeModeCenter progressBlock:^(int64_t, int64_t) { } - partialLoadBlock:^(UIImage*) { + partialLoadBlock:^(NativeScriptPlatformImage*) { } - completionBlock:^(NSError* error, UIImage* image) { + completionBlock:^(NSError* error, NativeScriptPlatformImage* image) { dispatch_async(dispatch_get_main_queue(), ^{ - UIImage* renderedImage = + NativeScriptPlatformImage* renderedImage = imageWithRenderingMode(image, isTemplate); callImageLoadCallback( imageWorkletRuntimeWeak, callback, renderedImage, @@ -479,6 +507,14 @@ void callImageLoadCallback( bool NativeScriptNativeApiModule::registerComponent(jsi::Runtime& runtime, std::string name, jsi::Object spec, double hookMask, double shouldBeRecycled) { +#if TARGET_OS_OSX + (void)runtime; + (void)name; + (void)spec; + (void)hookMask; + (void)shouldBeRecycled; + return false; +#else if (name.empty()) { return false; } @@ -515,6 +551,7 @@ void callImageLoadCallback( BOOL shouldBeRecycledValue = shouldBeRecycled > 0; NativeScriptRegisterFlavoredComponent(nsName, hookMaskValue, hasShouldBeRecycled, shouldBeRecycledValue); return true; +#endif } } // namespace facebook::react diff --git a/scripts/build_react_native_turbomodule.sh b/scripts/build_react_native_turbomodule.sh index 5e604df8..1712c71f 100755 --- a/scripts/build_react_native_turbomodule.sh +++ b/scripts/build_react_native_turbomodule.sh @@ -9,6 +9,7 @@ VERSION_OVERRIDE=${NPM_PACKAGE_VERSION:-} GENERATED_SIGNATURE_DISPATCH_OVERRIDE=${NS_SIGNATURE_BINDINGS_CPP_PATH:-${TNS_SIGNATURE_BINDINGS_CPP_PATH:-}} GENERATED_SIGNATURE_DISPATCH=${GENERATED_SIGNATURE_DISPATCH_OVERRIDE:-"$REPO_ROOT/dist/intermediates/react-native/GeneratedSignatureDispatch.ios-sim.tmp.inc"} DEVICE_SIGNATURE_DISPATCH="$REPO_ROOT/dist/intermediates/react-native/GeneratedSignatureDispatch.ios-device.tmp.inc" +MACOS_SIGNATURE_DISPATCH="$REPO_ROOT/dist/intermediates/react-native/GeneratedSignatureDispatch.macos.tmp.inc" SKIP_PACK=false function metadata_generator_source_hash { @@ -55,6 +56,12 @@ mkdir -p "$(dirname "$DEVICE_SIGNATURE_DISPATCH")" NS_SIGNATURE_BINDINGS_CPP_PATH="$DEVICE_SIGNATURE_DISPATCH" npm run metagen ios rm -f "$DEVICE_SIGNATURE_DISPATCH" "$DEVICE_SIGNATURE_DISPATCH.stamp" +# Before ios-sim: each metagen run rewrites GeneratedGsdSignatureDispatch.inc, +# and the staged copy has to stay the ios-sim one. +checkpoint "Generating macOS metadata and signature dispatch bindings for the TurboModule..." +mkdir -p "$(dirname "$MACOS_SIGNATURE_DISPATCH")" +NS_SIGNATURE_BINDINGS_CPP_PATH="$MACOS_SIGNATURE_DISPATCH" npm run metagen macos + checkpoint "Generating Hermes signature dispatch bindings for the TurboModule..." mkdir -p "$(dirname "$GENERATED_SIGNATURE_DISPATCH")" NS_SIGNATURE_BINDINGS_CPP_PATH="$GENERATED_SIGNATURE_DISPATCH" npm run metagen ios-sim @@ -106,13 +113,25 @@ cp -R "$REPO_ROOT/NativeScript/ffi/objc/hermes/." "$PACKAGE_DIR/native-api/ffi/o cp -R "$REPO_ROOT/NativeScript/ffi/objc/shared/." "$PACKAGE_DIR/native-api/ffi/objc/shared/" # Build leftovers, not sources. find "$PACKAGE_DIR/native-api/ffi/objc" -name '*.stamp' -delete -cp "$GENERATED_SIGNATURE_DISPATCH" "$PACKAGE_DIR/native-api/ffi/objc/shared/GeneratedSignatureDispatch.inc" +# One pod serves iOS and macOS, so the dispatch table is chosen per platform at +# compile time. A signature missing from the table falls back to libffi. +cp "$GENERATED_SIGNATURE_DISPATCH" "$PACKAGE_DIR/native-api/ffi/objc/shared/GeneratedSignatureDispatch.ios.inc" +cp "$MACOS_SIGNATURE_DISPATCH" "$PACKAGE_DIR/native-api/ffi/objc/shared/GeneratedSignatureDispatch.macos.inc" +cat > "$PACKAGE_DIR/native-api/ffi/objc/shared/GeneratedSignatureDispatch.inc" <<'INC' +#include +#if TARGET_OS_OSX +#include "GeneratedSignatureDispatch.macos.inc" +#else +#include "GeneratedSignatureDispatch.ios.inc" +#endif +INC GENERATED_GSD_SIGNATURE_DISPATCH="$(dirname "$GENERATED_SIGNATURE_DISPATCH")/GeneratedGsdSignatureDispatch.inc" if [ -f "$GENERATED_GSD_SIGNATURE_DISPATCH" ]; then cp "$GENERATED_GSD_SIGNATURE_DISPATCH" "$PACKAGE_DIR/native-api/ffi/objc/shared/GeneratedGsdSignatureDispatch.inc" fi if [ -z "$GENERATED_SIGNATURE_DISPATCH_OVERRIDE" ]; then rm -f "$GENERATED_SIGNATURE_DISPATCH" "$GENERATED_SIGNATURE_DISPATCH.stamp" \ + "$MACOS_SIGNATURE_DISPATCH" "$MACOS_SIGNATURE_DISPATCH.stamp" \ "$GENERATED_GSD_SIGNATURE_DISPATCH" fi cp metadata-generator/include/Metadata.h "$PACKAGE_DIR/native-api/metadata/include/" @@ -123,6 +142,8 @@ cp NativeScript/libffi/iphonesimulator-universal/include/ffitarget.h "$PACKAGE_D cp metadata-generator/metadata/metadata.ios-sim.arm64.nsmd "$PACKAGE_DIR/metadata/" cp metadata-generator/metadata/metadata.ios-sim.x86_64.nsmd "$PACKAGE_DIR/metadata/" cp metadata-generator/metadata/metadata.ios.arm64.nsmd "$PACKAGE_DIR/metadata/" +cp metadata-generator/metadata/metadata.macos.arm64.nsmd "$PACKAGE_DIR/metadata/" +cp metadata-generator/metadata/metadata.macos.x86_64.nsmd "$PACKAGE_DIR/metadata/" checkpoint "Staging iOS SDK TypeScript declarations..." cp packages/objc-node-api/index.d.ts "$PACKAGE_DIR/types/objc-node-api/" @@ -232,6 +253,8 @@ xcodebuild -create-xcframework \ -headers NativeScript/libffi/iphoneos-arm64/include \ -library NativeScript/libffi/iphonesimulator-universal/libffi.a \ -headers NativeScript/libffi/iphonesimulator-universal/include \ + -library NativeScript/libffi/macosx-universal/libffi.a \ + -headers NativeScript/libffi/macosx-universal/include \ -output "$PACKAGE_DIR/ios/vendor/Libffi.xcframework" if [[ -n "$VERSION_OVERRIDE" ]]; then