Skip to content

Commit

Permalink
feat: build macOS SDK as a dylib from sentry-cocoa
Browse files Browse the repository at this point in the history
  • Loading branch information
vaind committed Apr 27, 2022
1 parent bddcfdf commit 6b20018
Show file tree
Hide file tree
Showing 7 changed files with 378 additions and 4 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ jobs:
target: iOS
runsOn: macos-latest

macos-sdk:
uses: ./.github/workflows/sdk.yml
with:
target: macOS
runsOn: macos-latest

windows-sdk:
uses: ./.github/workflows/sdk.yml
with:
Expand Down Expand Up @@ -90,6 +96,12 @@ jobs:
path: package-dev/Plugins/iOS
wait-timeout: 3600

- uses: vaind/download-artifact@989a39a417730897d098ab11c34e49ac4e13ed70
with:
name: macOS-sdk
path: package-dev/Plugins/macOS
wait-timeout: 3600

- uses: vaind/download-artifact@989a39a417730897d098ab11c34e49ac4e13ed70
with:
name: Windows-sdk
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/sdk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
run: |
if [[ "${{ inputs.target }}" == "Android" ]]; then
submodules="modules/sentry-java"
elif [[ "${{ inputs.target }}" == "iOS" ]]; then
elif [[ "${{ inputs.target }}" == "iOS" || "${{ inputs.target }}" == "macOS" ]]; then
submodules="modules/sentry-cocoa"
else
submodules="modules/sentry-native"
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ package-dev/**/*.meta
package-dev/**/*.framework
package-dev/**/*.pdb
package-dev/**/*.xml
package-dev/**/*.dylib
package-dev/**/*.dSYM
package-dev/**/TestSentryOptions.json
package-dev/Tests/Editor/TestFiles/
package-dev/Plugins/*/Sentry/crashpad_handler*
Expand Down
26 changes: 23 additions & 3 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
<UnityTestPlayModeResultFilePath>../../artifacts/test/playmode/results.xml</UnityTestPlayModeResultFilePath>
<UnityTestEditModeResultFilePath>../../artifacts/test/editmode/results.xml</UnityTestEditModeResultFilePath>
<SentryArtifactsDestination>$(RepoRoot)package-dev/Plugins/</SentryArtifactsDestination>
<!-- Cocoa -->
<!-- iOS -->
<SentryCocoaRoot>$(RepoRoot)modules/sentry-cocoa/</SentryCocoaRoot>
<SentryiOSDeviceArtifactsDestination>$(SentryArtifactsDestination)/iOS/Device/Sentry.framework/</SentryiOSDeviceArtifactsDestination>
<SentryiOSSimulatorArtifactsDestination>$(SentryArtifactsDestination)/iOS/Simulator/Sentry.framework/</SentryiOSSimulatorArtifactsDestination>
<SentrymacOSArtifactsDestination>$(SentryArtifactsDestination)/macOS/Sentry/</SentrymacOSArtifactsDestination>
<!-- Android -->
<SentryAndroidRoot>$(RepoRoot)modules/sentry-java/</SentryAndroidRoot>
<SentryAndroidArtifactsDestination>$(SentryArtifactsDestination)/Android/Sentry/</SentryAndroidArtifactsDestination>
Expand Down Expand Up @@ -107,6 +108,7 @@ Expected to exist:
</Target>

<Target Name="CleaniOSSDK" AfterTargets="Clean" Condition="'$(MSBuildProjectName)' == 'Sentry.Unity'">
<RemoveDir Directories="$(SentryCocoaRoot)Carthage" ContinueOnError="true" />
<RemoveDir Directories="$(SentryiOSDeviceArtifactsDestination)" ContinueOnError="true" />
<RemoveDir Directories="$(SentryiOSSimulatorArtifactsDestination)" ContinueOnError="true" />
</Target>
Expand All @@ -117,6 +119,12 @@ Expected to exist:
<RemoveDir Directories="$(SentryAndroidArtifactsDestination)" ContinueOnError="true" />
</Target>

<Target Name="CleanmacOSSDK" AfterTargets="Clean" Condition="'$(MSBuildProjectName)' == 'Sentry.Unity'">
<RemoveDir Directories="$(SentryCocoaRoot)Carthage/Build/Mac" ContinueOnError="true" />
<Delete Files="$(SentrymacOSArtifactsDestination)/Sentry.dylib" ContinueOnError="true" />
<Delete Files="$(SentrymacOSArtifactsDestination)/Sentry.dylib.dSYM" ContinueOnError="true" />
</Target>

<Target Name="CleanWindowsSDK" AfterTargets="Clean" Condition="'$(MSBuildProjectName)' == 'Sentry.Unity'">
<RemoveDir Directories="$(SentryNativeRoot)build/" ContinueOnError="true" />
<RemoveDir Directories="$(SentryWindowsArtifactsDestination)" ContinueOnError="true" />
Expand All @@ -143,8 +151,20 @@ Expected to exist:
<Copy SourceFiles="@(iOSSimulatorBuildPath)" DestinationFiles="@(iOSSimulatorBuildPath->'$(SentryiOSSimulatorArtifactsDestination)%(RecursiveDir)%(Filename)%(Extension)')">
</Copy>

<Error Condition="(!Exists('$(SentryiOSDeviceArtifactsDestination)') OR !Exists('$(SentryiOSSimulatorArtifactsDestination)'))" Text="Failed to build the Cocoa SDK.">
</Error>
<Error Condition="(!Exists('$(SentryiOSDeviceArtifactsDestination)') OR !Exists('$(SentryiOSSimulatorArtifactsDestination)'))" Text="Failed to build the iOS SDK." />
</Target>

<!-- Build the macOS SDK: dotnet msbuild /t:BuildmacOSSDK src/Sentry.Unity -->
<Target Name="BuildmacOSSDK" BeforeTargets="BeforeBuild" Condition="$([MSBuild]::IsOSPlatform('OSX'))
And '$(MSBuildProjectName)' == 'Sentry.Unity'
And (!Exists('$(SentrymacOSArtifactsDestination)/Sentry.dylib') Or !Exists('$(SentrymacOSArtifactsDestination)/Sentry.dylib.dSYM'))">
<Error Condition="!Exists('$(SentryCocoaRoot)')" Text="Couldn't find the Cocoa root at $(SentryCocoaRoot)."></Error>
<Message Importance="High" Text="Building Sentry macOS SDK."></Message>

<Exec WorkingDirectory="$(SentryCocoaRoot)" Command="carthage build --no-skip-current --platform macOS"></Exec>

<Copy SourceFiles="$(SentryCocoaRoot)Carthage/Build/Mac/Sentry.framework/Sentry" DestinationFiles="$(SentrymacOSArtifactsDestination)/Sentry.dylib" />
<Copy SourceFiles="$(SentryCocoaRoot)Carthage/Build/Mac/Sentry.framework.dSYM/Contents/Resources/DWARF/Sentry" DestinationFiles="$(SentrymacOSArtifactsDestination)/Sentry.dylib.dSYM" />
</Target>

<!-- Build the Android SDK: dotnet msbuild /t:BuildAndroidSDK src/Sentry.Unity -->
Expand Down
81 changes: 81 additions & 0 deletions package-dev/Plugins/macOS/Sentry/Sentry.dylib.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

173 changes: 173 additions & 0 deletions package-dev/Plugins/macOS/SentryNativeBridge.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
#import <Foundation/Foundation.h>
#include <dlfcn.h>

@class SentryOptions;
@class SentrySDK;

static int loadStatus = 0; // 0 = unitialized; 1 = dylib loaded successfully; -1 = dylib load error
static void *dylib;
static Class sdkClass;
static Class optionsClass;

int
LoadSentryDylib()
{
if (!loadStatus) {
loadStatus = -1; // init to "error"
do {
dylib = dlopen("@executable_path/../PlugIns/Sentry.dylib", RTLD_LAZY);
if (!dylib) {
NSLog(@"Couldn't load Sentry.dylib - dlopen() failed");
break;
}

sdkClass = dlsym(dylib, "OBJC_CLASS_$_SentrySDK");
if (!sdkClass) {
NSLog(@"Couldn't load SentrySDK class from the dynamic library");
break;
}

optionsClass = dlsym(dylib, "OBJC_CLASS_$_SentryOptions");
if (!optionsClass) {
NSLog(@"Couldn't load SentryOptions class from the dynamic library");
break;
}

// everything above passed succesfully - mark as loaded
loadStatus = 1;
} while (false);
}
return loadStatus;
}

// TODO expose options setup & init
// SentryOptions *options = [[optionsClass alloc] init];
// [options
// setValue:
// @"https://[email protected]/5439417"
// forKey:@"dsn"];
// [options setValue:[NSNumber numberWithBool:YES] forKey:@"debug"];

// [sdkClass startWithOptionsObject:options];

// int CrashedLastRun() {
// return [SentrySDK crashedLastRun] ? 1 : 0;
// }

// void Close() {
// [SentrySDK close];
// }

// void SentryNativeBridgeAddBreadcrumb(const char* timestamp, const char* message, const char*
// type, const char* category, int level) {
// if (timestamp == NULL && message == NULL && type == NULL && category == NULL) {
// return;
// }

// [SentrySDK configureScope:^(SentryScope * scope) {
// SentryBreadcrumb *breadcrumb = [[SentryBreadcrumb alloc] init];

// if (timestamp != NULL) {
// NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
// [dateFormatter setDateFormat:NSCalendarIdentifierISO8601];
// breadcrumb.timestamp = [dateFormatter dateFromString:[NSString
// stringWithCString:timestamp encoding:NSUTF8StringEncoding]];
// }

// if (message != NULL) {
// breadcrumb.message = [NSString stringWithCString:message
// encoding:NSUTF8StringEncoding];
// }

// if (type != NULL) {
// breadcrumb.type = [NSString stringWithCString:type
// encoding:NSUTF8StringEncoding];
// }

// if (category != NULL) {
// breadcrumb.category = [NSString stringWithCString:category
// encoding:NSUTF8StringEncoding];
// }

// breadcrumb.level = level;

// [scope addBreadcrumb:breadcrumb];
// }];
// }

// void SentryNativeBridgeSetExtra(const char* key, const char* value) {
// if (key == NULL) {
// return;
// }

// [SentrySDK configureScope:^(SentryScope * scope) {
// if (value != NULL) {
// [scope setExtraValue:[NSString stringWithUTF8String:value] forKey:[NSString
// stringWithUTF8String:key]];
// } else {
// [scope removeExtraForKey:[NSString stringWithUTF8String:key]];
// }
// }];
// }

// void SentryNativeBridgeSetTag(const char* key, const char* value) {
// if (key == NULL) {
// return;
// }

// [SentrySDK configureScope:^(SentryScope * scope) {
// if (value != NULL) {
// [scope setTagValue:[NSString stringWithUTF8String:value] forKey:[NSString
// stringWithUTF8String:key]];
// } else {
// [scope removeTagForKey:[NSString stringWithUTF8String:key]];
// }
// }];
// }

// void SentryNativeBridgeUnsetTag(const char* key) {
// if (key == NULL) {
// return;
// }

// [SentrySDK configureScope:^(SentryScope * scope) {
// [scope removeTagForKey:[NSString stringWithUTF8String:key]];
// }];
// }

// void SentryNativeBridgeSetUser(const char* email, const char* userId, const char* ipAddress,
// const char* username) {
// if (email == NULL && userId == NULL && ipAddress == NULL && username == NULL) {
// return;
// }

// [SentrySDK configureScope:^(SentryScope * scope) {
// SentryUser *user = [[SentryUser alloc] init];

// if (email != NULL) {
// user.email = [NSString stringWithCString:email encoding:NSUTF8StringEncoding];
// }

// if (userId != NULL) {
// user.userId = [NSString stringWithCString:userId encoding:NSUTF8StringEncoding];
// }

// if (ipAddress != NULL) {
// user.ipAddress = [NSString stringWithCString:ipAddress
// encoding:NSUTF8StringEncoding];
// }

// if (username != NULL) {
// user.username = [NSString stringWithCString:username
// encoding:NSUTF8StringEncoding];
// }

// [scope setUser:user];
// }];
// }

// void SentryNativeBridgeUnsetUser() {
// [SentrySDK configureScope:^(SentryScope * scope) {
// [scope setUser:nil];
// }];
// }
Loading

0 comments on commit 6b20018

Please sign in to comment.