Skip to content

Commit aca52ac

Browse files
authored
fix(🍏): compile and shut down WebGPU on macOS (#629)
1 parent 3c54979 commit aca52ac

4 files changed

Lines changed: 35 additions & 4 deletions

File tree

β€Žpackages/webgpu/apple/RNWGUIKit.hβ€Ž

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
#ifndef PACKAGES_WEBGPU_APPLE_RNWGUIKIT_H_
22
#define PACKAGES_WEBGPU_APPLE_RNWGUIKIT_H_
33

4+
// Select UIKit or AppKit before importing either framework.
5+
#import <TargetConditionals.h>
6+
47
#if !TARGET_OS_OSX
58
#import <UIKit/UIKit.h>
69
#else
7-
#import <Appkit/Appkit.h>
10+
#import <AppKit/AppKit.h>
811
#endif
912

1013
#if !TARGET_OS_OSX

β€Žpackages/webgpu/apple/WebGPUModule.mmβ€Ž

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,38 @@ @implementation WebGPUModule
4646
return webgpuManager;
4747
}
4848

49-
#pragma Setup and invalidation
49+
#pragma mark - Setup and invalidation
5050

5151
+ (BOOL)requiresMainQueueSetup {
5252
return YES;
5353
}
5454

55+
#if TARGET_OS_OSX
56+
- (instancetype)init {
57+
if (self = [super init]) {
58+
[[NSNotificationCenter defaultCenter]
59+
addObserver:self
60+
selector:@selector(applicationWillTerminate:)
61+
name:NSApplicationWillTerminateNotification
62+
object:nil];
63+
}
64+
return self;
65+
}
66+
67+
- (void)applicationWillTerminate:(NSNotification *)notification {
68+
// AppKit exits without necessarily invalidating the React instance. Release
69+
// the manager before static teardown destroys SurfaceRegistry and its mutex.
70+
[self invalidate];
71+
}
72+
#endif
73+
5574
- (void)invalidate {
75+
#if TARGET_OS_OSX
76+
[[NSNotificationCenter defaultCenter]
77+
removeObserver:self
78+
name:NSApplicationWillTerminateNotification
79+
object:nil];
80+
#endif
5681
webgpuManager = nil;
5782
}
5883

β€Žpackages/webgpu/apple/WebGPUView.hβ€Ž

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#pragma once
22

33
#import "MetalView.h"
4+
// RNWGUIKit selects AppKit for native macOS and UIKit for other Apple targets.
5+
#import "RNWGUIKit.h"
46
#import <React/RCTViewComponentView.h>
5-
#import <UIKit/UIKit.h>
67

78
NS_ASSUME_NONNULL_BEGIN
89

β€Žpackages/webgpu/scripts/check-apple-sdks.shβ€Ž

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ fi
1818

1919
# The other files under apple/ need React and codegen headers, which only
2020
# exist after a pod install.
21-
FILES=(apple/MetalLayerColorSpace.mm apple/AppleVideoPlayer.mm)
21+
# Also compile the platform header on its own: TargetConditionals must be
22+
# available before it decides whether UIKit or AppKit is required.
23+
FILES=(apple/RNWGUIKit.h apple/MetalLayerColorSpace.mm apple/AppleVideoPlayer.mm)
2224

2325
# sdk:target pairs, using the podspec's minimum versions.
2426
TARGETS=(

0 commit comments

Comments
Β (0)