diff --git a/Sentry.Unity.sln b/Sentry.Unity.sln index 04ddc5a14..804fc073d 100644 --- a/Sentry.Unity.sln +++ b/Sentry.Unity.sln @@ -45,6 +45,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.Unity.Android.Tests" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.Unity.Native", "src\Sentry.Unity.Native\Sentry.Unity.Native.csproj", "{F291F324-D17C-4732-9E54-099D326B0929}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.Unity.MacOS", "src\Sentry.Unity.MacOS\Sentry.Unity.MacOS.csproj", "{B0C3BCDC-44F8-4DD0-B57A-6517F195C06F}" +EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.Analyzers", "src\sentry-dotnet\src\Sentry.Analyzers\Sentry.Analyzers.csproj", "{C1798B72-5382-4C13-96F0-EAFDA28428F0}" EndProject Global @@ -201,6 +203,18 @@ Global {F291F324-D17C-4732-9E54-099D326B0929}.Release|x64.Build.0 = Release|Any CPU {F291F324-D17C-4732-9E54-099D326B0929}.Release|x86.ActiveCfg = Release|Any CPU {F291F324-D17C-4732-9E54-099D326B0929}.Release|x86.Build.0 = Release|Any CPU + {B0C3BCDC-44F8-4DD0-B57A-6517F195C06F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B0C3BCDC-44F8-4DD0-B57A-6517F195C06F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B0C3BCDC-44F8-4DD0-B57A-6517F195C06F}.Debug|x64.ActiveCfg = Debug|Any CPU + {B0C3BCDC-44F8-4DD0-B57A-6517F195C06F}.Debug|x64.Build.0 = Debug|Any CPU + {B0C3BCDC-44F8-4DD0-B57A-6517F195C06F}.Debug|x86.ActiveCfg = Debug|Any CPU + {B0C3BCDC-44F8-4DD0-B57A-6517F195C06F}.Debug|x86.Build.0 = Debug|Any CPU + {B0C3BCDC-44F8-4DD0-B57A-6517F195C06F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B0C3BCDC-44F8-4DD0-B57A-6517F195C06F}.Release|Any CPU.Build.0 = Release|Any CPU + {B0C3BCDC-44F8-4DD0-B57A-6517F195C06F}.Release|x64.ActiveCfg = Release|Any CPU + {B0C3BCDC-44F8-4DD0-B57A-6517F195C06F}.Release|x64.Build.0 = Release|Any CPU + {B0C3BCDC-44F8-4DD0-B57A-6517F195C06F}.Release|x86.ActiveCfg = Release|Any CPU + {B0C3BCDC-44F8-4DD0-B57A-6517F195C06F}.Release|x86.Build.0 = Release|Any CPU {C1798B72-5382-4C13-96F0-EAFDA28428F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {C1798B72-5382-4C13-96F0-EAFDA28428F0}.Debug|Any CPU.Build.0 = Debug|Any CPU {C1798B72-5382-4C13-96F0-EAFDA28428F0}.Debug|x64.ActiveCfg = Debug|Any CPU @@ -233,6 +247,7 @@ Global {35A9BDB0-253E-4753-9D47-99CE6AAA4F07} = {36979A3D-4741-4D8A-82BF-4010474388E1} {DC954ED7-3DFA-4197-B511-202CB70AA816} = {6A85CE0A-6FE4-4190-ABEE-7E8BCFF9AF4D} {F291F324-D17C-4732-9E54-099D326B0929} = {36979A3D-4741-4D8A-82BF-4010474388E1} + {B0C3BCDC-44F8-4DD0-B57A-6517F195C06F} = {36979A3D-4741-4D8A-82BF-4010474388E1} {C1798B72-5382-4C13-96F0-EAFDA28428F0} = {36979A3D-4741-4D8A-82BF-4010474388E1} EndGlobalSection EndGlobal diff --git a/package-dev/Runtime/Sentry.Unity.MacOS.dll.meta b/package-dev/Runtime/Sentry.Unity.MacOS.dll.meta new file mode 100644 index 000000000..ee66c562d --- /dev/null +++ b/package-dev/Runtime/Sentry.Unity.MacOS.dll.meta @@ -0,0 +1,87 @@ +fileFormatVersion: 2 +guid: 9e48b8cf39b1464f8ac84f4a35e220e2 +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 0 + isOverridable: 1 + isExplicitlyReferenced: 0 + validateReferences: 1 + platformData: + - first: + : Any + second: + enabled: 0 + settings: + Exclude Android: 1 + Exclude Editor: 1 + Exclude Linux64: 1 + Exclude OSXUniversal: 0 + Exclude WebGL: 1 + Exclude Win: 1 + Exclude Win64: 1 + Exclude iOS: 1 + - first: + Android: Android + second: + enabled: 0 + settings: + CPU: ARMv7 + - first: + Any: + second: + enabled: 0 + settings: {} + - first: + Editor: Editor + second: + enabled: 0 + settings: + CPU: AnyCPU + DefaultValueInitialized: true + OS: AnyOS + - first: + Standalone: Linux64 + second: + enabled: 0 + settings: + CPU: None + - first: + Standalone: OSXUniversal + second: + enabled: 1 + settings: + CPU: AnyCPU + - first: + Standalone: Win + second: + enabled: 0 + settings: + CPU: None + - first: + Standalone: Win64 + second: + enabled: 0 + settings: + CPU: None + - first: + Windows Store Apps: WindowsStoreApps + second: + enabled: 0 + settings: + CPU: AnyCPU + - first: + iPhone: iOS + second: + enabled: 0 + settings: + AddToEmbeddedBinaries: false + CPU: AnyCPU + CompileFlags: + FrameworkDependencies: + userData: + assetBundleName: + assetBundleVariant: diff --git a/package-dev/Runtime/SentryInitialization.cs b/package-dev/Runtime/SentryInitialization.cs index cf8c8cc2e..ddb20b6a0 100644 --- a/package-dev/Runtime/SentryInitialization.cs +++ b/package-dev/Runtime/SentryInitialization.cs @@ -1,6 +1,6 @@ #if !UNITY_EDITOR -#if UNITY_IOS || (UNITY_STANDALONE_OSX && ENABLE_IL2CPP) +#if UNITY_IOS #define SENTRY_NATIVE_COCOA #endif @@ -8,7 +8,11 @@ #define SENTRY_NATIVE_ANDROID #endif -#if UNITY_STANDALONE_WIN || UNITY_STANDALONE_LINUX || UNITY_STANDALONE_OSX || UNITY_GAMECORE || UNITY_PS5 +#if UNITY_STANDALONE_OSX +#define SENTRY_NATIVE_MACOS +#endif + +#if UNITY_STANDALONE_WIN || UNITY_STANDALONE_LINUX || UNITY_GAMECORE || UNITY_PS5 #define SENTRY_NATIVE #endif @@ -22,7 +26,7 @@ #endif -#if ENABLE_IL2CPP && (SENTRY_NATIVE_COCOA || SENTRY_NATIVE_ANDROID || SENTRY_NATIVE) +#if ENABLE_IL2CPP && (SENTRY_NATIVE_COCOA || SENTRY_NATIVE_ANDROID || SENTRY_NATIVE_MACOS || SENTRY_NATIVE) #define IL2CPP_LINENUMBER_SUPPORT #endif @@ -35,13 +39,8 @@ using UnityEngine; using UnityEngine.Scripting; -#if UNITY_STANDALONE_OSX -#if SENTRY_NATIVE_COCOA -using Sentry.Unity.iOS; -#endif -#if SENTRY_NATIVE -using Sentry.Unity.Native; -#endif +#if SENTRY_NATIVE_MACOS +using Sentry.Unity.MacOS; #elif SENTRY_NATIVE_COCOA using Sentry.Unity.iOS; #elif SENTRY_NATIVE_ANDROID @@ -88,8 +87,8 @@ private static void Init() { // If the SDK is not `enabled` we're closing down the native layer as well. This is especially relevant // in a `built-time-initialization` scenario where the native SDKs self-initialize. -#if UNITY_STANDALONE_OSX - CloseMacosBackend(options); +#if SENTRY_NATIVE_MACOS + SentryNativeMacos.Close(options); #elif SENTRY_NATIVE_COCOA SentryNativeCocoa.Close(options); #elif SENTRY_NATIVE_ANDROID @@ -103,8 +102,8 @@ private static void SetUpPlatformServices() SentryPlatformServices.CollectMainThreadData(); SentryPlatformServices.UnityInfo = new SentryUnityInfo(); -#if UNITY_STANDALONE_OSX - SentryPlatformServices.PlatformConfiguration = ConfigureMacosBackend; +#if SENTRY_NATIVE_MACOS + SentryPlatformServices.PlatformConfiguration = SentryNativeMacos.Configure; #elif SENTRY_NATIVE_COCOA SentryPlatformServices.PlatformConfiguration = SentryNativeCocoa.Configure; #elif SENTRY_NATIVE_ANDROID @@ -118,40 +117,6 @@ private static void SetUpPlatformServices() #endif } -#if UNITY_STANDALONE_OSX - private static void ConfigureMacosBackend(SentryUnityOptions options) - { -#if SENTRY_NATIVE - if (options.Experimental.MacosBackend == MacosBackend.Native) - { - SentryNative.Configure(options); - return; - } -#endif -#if SENTRY_NATIVE_COCOA - SentryNativeCocoa.Configure(options); -#else - options.DiagnosticLogger?.LogWarning( - "MacosBackend is set to Cocoa, but Cocoa requires IL2CPP. " + - "Native crash reporting is disabled. Set MacosBackend to Native or enable IL2CPP."); -#endif - } - - private static void CloseMacosBackend(SentryUnityOptions options) - { - if (options is null) - { - return; - } -#if SENTRY_NATIVE_COCOA - if (options.Experimental.MacosBackend == MacosBackend.Cocoa) - { - SentryNativeCocoa.Close(options); - } -#endif - // Native: nothing to do — SentryNative registers its own close callback at Configure time. - } -#endif } public class SentryUnityInfo : ISentryUnityInfo diff --git a/src/Sentry.Unity.MacOS/Sentry.Unity.MacOS.csproj b/src/Sentry.Unity.MacOS/Sentry.Unity.MacOS.csproj new file mode 100644 index 000000000..1dbf30142 --- /dev/null +++ b/src/Sentry.Unity.MacOS/Sentry.Unity.MacOS.csproj @@ -0,0 +1,12 @@ + + + $(PackageRuntimePath) + + + + + + + + + diff --git a/src/Sentry.Unity.MacOS/SentryNativeMacos.cs b/src/Sentry.Unity.MacOS/SentryNativeMacos.cs new file mode 100644 index 000000000..8e8d3071a --- /dev/null +++ b/src/Sentry.Unity.MacOS/SentryNativeMacos.cs @@ -0,0 +1,42 @@ +using Sentry.Extensibility; +using Sentry.Unity.iOS; +using Sentry.Unity.Native; +using Sentry.Unity.NativeUtils; + +namespace Sentry.Unity.MacOS; + +public static class SentryNativeMacos +{ + public static void Configure(SentryUnityOptions options) + { + if (options.Experimental.MacosBackend == MacosBackend.Native) + { + SentryNative.Configure(options); + return; + } + + if (!SentryPlatformServices.UnityInfo.IL2CPP) + { + options.DiagnosticLogger?.LogWarning( + "Cocoa backend requires IL2CPP on macOS. Native crash reporting is disabled. " + + "Set macOS Backend to Native or enable IL2CPP."); + return; + } + + SentryNativeCocoa.Configure(options); + } + + public static void Close(SentryUnityOptions options) + { + if (options is null) + { + return; + } + + if (options.Experimental.MacosBackend == MacosBackend.Cocoa + && SentryPlatformServices.UnityInfo.IL2CPP) + { + SentryNativeCocoa.Close(options); + } + } +} diff --git a/test/Scripts.Tests/package-release.zip.snapshot b/test/Scripts.Tests/package-release.zip.snapshot index b0902bd3d..3847cf196 100644 --- a/test/Scripts.Tests/package-release.zip.snapshot +++ b/test/Scripts.Tests/package-release.zip.snapshot @@ -315,6 +315,10 @@ Runtime/Sentry.Unity.iOS.dll Runtime/Sentry.Unity.iOS.dll.meta Runtime/Sentry.Unity.iOS.pdb Runtime/Sentry.Unity.iOS.pdb.meta +Runtime/Sentry.Unity.MacOS.dll +Runtime/Sentry.Unity.MacOS.dll.meta +Runtime/Sentry.Unity.MacOS.pdb +Runtime/Sentry.Unity.MacOS.pdb.meta Runtime/Sentry.Unity.Native.dll Runtime/Sentry.Unity.Native.dll.meta Runtime/Sentry.Unity.Native.pdb