Skip to content
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

fix: Build visionOS project with static Sentry SDK #4462

Merged
merged 10 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Sources/Sentry/SentryLogC.m
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#import "SentryLogC.h"
#import "SentryAsyncSafeLog.h"
#import "SentryFileManager.h"
#import "SentryInternalCDefines.h"
Expand All @@ -6,8 +7,8 @@

NS_ASSUME_NONNULL_BEGIN

void
sentry_initializeAsyncLogFile(void)
@implementation SentryAsyncLogWrapper
+ (void)initializeAsyncLogFile
{
const char *asyncLogPath =
[[sentryStaticCachesPath() stringByAppendingPathComponent:@"async.log"] UTF8String];
Expand All @@ -25,5 +26,6 @@
@"Could not open a handle to specified path for async logging %s", asyncLogPath);
};
}
@end

NS_ASSUME_NONNULL_END
1 change: 0 additions & 1 deletion Sources/Sentry/SentrySDK.m
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ + (void)startWithOptions:(SentryOptions *)options
{
startOption = options;
[SentryLog configure:options.debug diagnosticLevel:options.diagnosticLevel];
sentry_initializeAsyncLogFile();

// We accept the tradeoff that the SDK might not be fully initialized directly after
// initializing it on a background thread because scheduling the init synchronously on the main
Expand Down
7 changes: 6 additions & 1 deletion Sources/Sentry/include/SentryLogC.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#ifndef SentryLogC_h
#define SentryLogC_h
void sentry_initializeAsyncLogFile(void);
#import <Foundation/Foundation.h>

@interface SentryAsyncLogWrapper : NSObject
+ (void)initializeAsyncLogFile;
@end

#endif
1 change: 1 addition & 0 deletions Sources/Swift/Tools/SentryLog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class SentryLog: NSObject {
self.isDebug = isDebug
self.diagnosticLevel = diagnosticLevel
}
SentryAsyncLogWrapper.initializeAsyncLogFile()
brustolin marked this conversation as resolved.
Show resolved Hide resolved
}

@objc
Expand Down
10 changes: 10 additions & 0 deletions develop-docs/DECISIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,13 @@ please refer to this [PR](https://github.com/getsentry/sentry-cocoa/pull/3623).
When coding with Swift be aware of two things:
1. If you want to use swift code in an Objc file: `#import "SentrySwift.h"`
2. If you want to use Objc code from Swift, first add the desired header file to `SentryInternal.h`, then, in your Swift file, `@_implementationOnly import _SentryPrivate` (the underscore makes auto-complete ignore it since we dont want users importing this module).

## Enabling C++/Objective-c++ interoperability for visionOS
brustolin marked this conversation as resolved.
Show resolved Hide resolved

Date: October 23, 2024
Contributors: @brustolin, @philipphofmann

To enable visionOS support with the Sentry static framework, you need to set the `SWIFT_OBJC_INTEROP_MODE` build setting to `objcxx`. This setting will only be applied for visionOS, but because much of the codebase is shared across platforms, this change introduces a limitation: we won’t be able to call C functions directly from Swift code.

However, C functions can still be accessed from code that is conditionally compiled using directives, such as `#if os(iOS)`.