Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
### Behavioural Changes and Deprecations

- The `EnableMetrics` option is now marked as `[Obsolete]` and no longer has any effect, following the .NET SDK where metrics are always enabled. Disable the individual `Auto*Metrics` options instead, or filter emitted metrics with `SetBeforeSendMetric`. ([#2828](https://github.com/getsentry/sentry-unity/pull/2828))
- The runtime assembly is now compiled for any platform except CloudRendering, EmbeddedLinux, PS4, tvOS and Xbox One, instead of an explicit allowlist. Platforms without a dedicated integration, like visionOS and the dedicated server targets now run the SDK in managed-only mode. ([#2834](https://github.com/getsentry/sentry-unity/pull/2834))

### Features

- Added Nintendo Switch 2 support. The SDK now correctly recognises the platform, providing native support and automatic debug symbol upload. Switch 2 shares the existing `SwitchNativeSupportEnabled` option. ([#2834](https://github.com/getsentry/sentry-unity/pull/2834))

### Fixes

Expand Down
4 changes: 4 additions & 0 deletions package-dev/Plugins/Switch/sentry_native_stubs.c.meta

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

4 changes: 4 additions & 0 deletions package-dev/Runtime/Sentry.Unity.Native.Switch.dll.meta

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

2 changes: 1 addition & 1 deletion package-dev/Runtime/SentryInitialization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#define SENTRY_NATIVE
#endif

#if UNITY_SWITCH
#if UNITY_SWITCH || UNITY_SWITCH2
#define SENTRY_NATIVE_SWITCH
#endif

Expand Down
22 changes: 7 additions & 15 deletions package-dev/Runtime/io.sentry.unity.dev.runtime.asmdef
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,14 @@
"name": "io.sentry.unity.dev.runtime",
"rootNamespace": "",
"references": [],
"includePlatforms": [
"Android",
"Editor",
"iOS",
"LinuxStandalone64",
"macOSStandalone",
"Switch",
"PS5",
"WSA",
"WebGL",
"WindowsStandalone32",
"WindowsStandalone64",
"GameCoreXboxOne",
"GameCoreScarlett"
"includePlatforms": [],
"excludePlatforms": [
"CloudRendering",
"EmbeddedLinux",
"PS4",
"XboxOne",
"tvOS"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
Expand Down
22 changes: 7 additions & 15 deletions package/Runtime/io.sentry.unity.runtime.asmdef
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,14 @@
"name": "io.sentry.unity.runtime",
"rootNamespace": "",
"references": [],
"includePlatforms": [
"Android",
"Editor",
"GameCoreScarlett",
"GameCoreXboxOne",
"iOS",
"LinuxStandalone64",
"macOSStandalone",
"PS5",
"Switch",
"WSA",
"WebGL",
"WindowsStandalone32",
"WindowsStandalone64"
"includePlatforms": [],
"excludePlatforms": [
"CloudRendering",
"EmbeddedLinux",
"PS4",
"XboxOne",
"tvOS"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ internal static void Display(ScriptableSentryUnityOptions options, SentryCliOpti
options.PlayStationNativeSupportEnabled);

options.SwitchNativeSupportEnabled = EditorGUILayout.Toggle(
new GUIContent("Nintendo Switch", "Whether to enable native scope sync support on Nintendo Switch."),
new GUIContent("Nintendo Switch", "Whether to enable native scope sync support on Nintendo Switch and Switch 2."),
options.SwitchNativeSupportEnabled);
}

Expand Down
64 changes: 43 additions & 21 deletions src/Sentry.Unity.Editor/Native/BuildPostProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ public static class BuildPostProcess
public static void OnPostProcessBuild(BuildTarget target, string executablePath)
{
var targetGroup = BuildPipeline.GetBuildTargetGroup(target);
if (targetGroup is not BuildTargetGroup.Standalone
and not BuildTargetGroup.GameCoreXboxSeries
and not BuildTargetGroup.PS5
and not BuildTargetGroup.Switch)
var isSupportedGroup = targetGroup is BuildTargetGroup.Standalone
or BuildTargetGroup.GameCoreXboxSeries
or BuildTargetGroup.PS5
or BuildTargetGroup.Switch
|| targetGroup.IsSwitch2();
if (!isSupportedGroup)
{
return;
}
Expand Down Expand Up @@ -58,6 +60,7 @@ and not BuildTargetGroup.PS5
BuildTargetGroup.GameCoreXboxSeries => executablePath,
BuildTargetGroup.PS5 => executablePath,
BuildTargetGroup.Switch => Path.GetDirectoryName(executablePath),
_ when targetGroup.IsSwitch2() => Path.GetDirectoryName(executablePath),
_ => string.Empty
};

Expand Down Expand Up @@ -131,6 +134,8 @@ and not BuildTargetGroup.PS5
BuildTarget.GameCoreXboxSeries or BuildTarget.GameCoreXboxOne => options.XboxNativeSupportEnabled,
BuildTarget.PS5 => options.PlayStationNativeSupportEnabled,
BuildTarget.Switch => options.SwitchNativeSupportEnabled,
// Switch 2 reuses the Switch native support.
_ when target.IsSwitch2() => options.SwitchNativeSupportEnabled,
_ => false,
};

Expand Down Expand Up @@ -238,6 +243,11 @@ private static IEnumerable<NativePluginArtifact> GetNativePluginArtifact(
// No standalone crash handler for Switch - uses Nintendo's crash reporter
break;
default:
if (target.IsSwitch2())
{
// No standalone crash handler for Switch - uses Nintendo's crash reporter
break;
}
throw new ArgumentException($"Unsupported build target: {target}");
}
}
Expand Down Expand Up @@ -526,31 +536,43 @@ private static void UploadDebugSymbols(IDiagnosticLogger logger, BuildTarget tar
break;

case BuildTarget.Switch:
// IL2CPP output, Managed DLLs/PDBs, and Symbols
foreach (var dir in Directory.GetDirectories(buildOutputDir, "*_BackUpThisFolder_*"))
{
AddPath(paths, dir, logger);
}
AddSwitchPaths();
break;

// Burst
foreach (var dir in Directory.GetDirectories(buildOutputDir, "*_BurstDebugInformation_*"))
default:
if (target.IsSwitch2())
{
AddPath(paths, dir, logger);
AddSwitchPaths();
break;
}

// When exporting as an NSP the assemblies are bundled inside the package. So we're also checking the build cache.
var beePath = Path.Combine(projectDir, "Library", "Bee", "artifacts", "SwitchPlayerBuildProgram");
AddPath(paths, beePath, logger);

// User-provided Sentry plugin
AddPath(paths, Path.GetFullPath("Assets/Plugins/Sentry/"), logger);
break;

default:
logger.LogError("Symbol upload for '{0}' is currently not supported.", target);
return;
}

void AddSwitchPaths()
{
// IL2CPP output, Managed DLLs/PDBs, and Symbols
foreach (var dir in Directory.GetDirectories(buildOutputDir, "*_BackUpThisFolder_*"))
{
AddPath(paths, dir, logger);
}

// Burst
foreach (var dir in Directory.GetDirectories(buildOutputDir, "*_BurstDebugInformation_*"))
{
AddPath(paths, dir, logger);
}

// When exporting as an NSP the assemblies are bundled inside the package. So we're also checking the
// build cache. The build program is named after the build target, i.e. `SwitchPlayerBuildProgram`.
var beePath = Path.Combine(projectDir, "Library", "Bee", "artifacts", $"{target}PlayerBuildProgram");
AddPath(paths, beePath, logger);

// User-provided Sentry plugin
AddPath(paths, Path.GetFullPath("Assets/Plugins/Sentry/"), logger);
}

// Possible duplicate but check for the .pdb files that Unity stores for script assemblies in `./Temp/ManagedSymbols/`.
var managedSymbolsDirectory = Path.Combine(projectDir, "Temp", "ManagedSymbols");
AddPath(paths, managedSymbolsDirectory, logger);
Expand Down
22 changes: 22 additions & 0 deletions src/Sentry.Unity.Editor/Native/SwitchBuildTargets.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using UnityEditor;

namespace Sentry.Unity.Editor.Native;

/// <summary>
/// <c>BuildTarget.Switch2</c> and <c>BuildTargetGroup.Switch2</c> only exist in Unity 6000.3
/// and newer, so matching by name instead.
/// </summary>
internal static class SwitchBuildTargets
{
private const string Switch2Name = "Switch2";

internal static bool IsSwitch2(this BuildTarget target) =>
string.Equals(target.ToString(), Switch2Name, StringComparison.Ordinal);

internal static bool IsSwitch2(this BuildTargetGroup group) =>
string.Equals(group.ToString(), Switch2Name, StringComparison.Ordinal);

internal static bool IsSwitchFamily(this BuildTarget target) =>
target is BuildTarget.Switch || target.IsSwitch2();
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,43 @@ namespace Sentry.Unity.Editor.Native;
/// </remarks>
internal class SwitchNativePluginBuildPreProcess : IPreprocessBuildWithReport
{
private static readonly string[] RequiredFiles =
/// <summary>
/// Both platforms share one stub, so the required libraries are what differ between them. The build target's
/// name doubles as the directory name, i.e. `Switch` and `Switch2`.
/// </summary>
internal static string[] RequiredFilesFor(BuildTarget target)
{
"Assets/Plugins/Sentry/Switch/libsentry.a",
"Assets/Plugins/Sentry/Switch/libzstd.a",
};
return
[
$"Assets/Plugins/Sentry/{target}/libsentry.a",
$"Assets/Plugins/Sentry/{target}/libzstd.a"
];
}

public int callbackOrder => -100;

public void OnPreprocessBuild(BuildReport report)
{
if (report.summary.platform != BuildTarget.Switch)
if (!report.summary.platform.IsSwitchFamily())
{
return;
}

var options = SentryScriptableObject.LoadOptions(isBuilding: true);
var logger = options?.DiagnosticLogger ?? new UnityLogger(new SentryUnityOptions());

ConfigureStub(logger, options?.SwitchNativeSupportEnabled ?? false);
ConfigureStub(logger, options?.SwitchNativeSupportEnabled ?? false, report.summary.platform);
}

internal static void ConfigureStub(IDiagnosticLogger logger, bool nativeSupportEnabled)
internal static void ConfigureStub(IDiagnosticLogger logger, bool nativeSupportEnabled, BuildTarget target)
{
logger.LogDebug("Switch native support: checking for required files:\n{0}",
string.Join("\n", RequiredFiles.Select(f => $" - {f}")));
var requiredFiles = RequiredFilesFor(target);

logger.LogDebug("{0} native support: checking for required files:\n{1}",
target, string.Join("\n", requiredFiles.Select(f => $" - {f}")));

// One stub serves both platforms; the importer tracks compatibility per build target, so
// enabling it for one does not affect the other.
var stubPath = Path.Combine("Packages", SentryPackageInfo.GetName(), "Plugins", "Switch", "sentry_native_stubs.c");

var importer = AssetImporter.GetAtPath(stubPath) as PluginImporter;
Expand All @@ -56,45 +67,45 @@ internal static void ConfigureStub(IDiagnosticLogger logger, bool nativeSupportE
return;
}

var existingFiles = RequiredFiles.Where(File.Exists).ToList();
var missingFiles = RequiredFiles.Except(existingFiles).ToList();
var existingFiles = requiredFiles.Where(File.Exists).ToList();
var missingFiles = requiredFiles.Except(existingFiles).ToList();

var someFilesPresent = existingFiles.Count > 0 && missingFiles.Count > 0;
if (someFilesPresent)
{
logger.LogError(
"Switch native support is partially configured. Missing files:\n{0}\n" +
logger.LogWarning(
"{0} native support is partially configured. Missing files:\n{1}\n" +
"Please add all required files to enable native support, or remove all files to fall back on no-op stubs.\n" +
"Build sentry-switch and copy the libraries to the expected locations. " +
"See: https://github.com/getsentry/sentry-switch",
string.Join("\n", missingFiles.Select(f => $" - {f}"))
target, string.Join("\n", missingFiles.Select(f => $" - {f}"))
);
return;
}

var allFilesPresent = missingFiles.Count == 0;
if (allFilesPresent)
{
logger.LogInfo("Switch native libraries found:\n{0}",
string.Join("\n", existingFiles.Select(f => $" - {f}")));
importer.SetCompatibleWithPlatform(BuildTarget.Switch, false);
logger.LogInfo("{0} native libraries found:\n{1}",
target, string.Join("\n", existingFiles.Select(f => $" - {f}")));
importer.SetCompatibleWithPlatform(target, false);
}
else
{
if (nativeSupportEnabled)
{
logger.LogWarning(
"Switch native support is enabled but required files are missing:\n{0}\n" +
"{0} native support is enabled but required files are missing:\n{1}\n" +
"Build sentry-switch and copy the libraries to the expected locations. " +
"See: https://github.com/getsentry/sentry-switch",
string.Join("\n", missingFiles.Select(f => $" - {f}"))
target, string.Join("\n", missingFiles.Select(f => $" - {f}"))
);
}
else
{
logger.LogDebug("Switch native support is disabled. Enabling stubs (native calls will be no-op).");
logger.LogDebug("{0} native support is disabled. Enabling stubs (native calls will be no-op).", target);
}
importer.SetCompatibleWithPlatform(BuildTarget.Switch, true);
importer.SetCompatibleWithPlatform(target, true);
}

importer.SaveAndReimport();
Expand Down
3 changes: 2 additions & 1 deletion src/Sentry.Unity.Native/SentryNativeBridge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public static bool Init(SentryUnityOptions options)
UseLibC = Application.platform
is RuntimePlatform.LinuxPlayer or RuntimePlatform.LinuxServer
or RuntimePlatform.PS5
or RuntimePlatform.Switch;
or RuntimePlatform.Switch
|| Application.platform.IsSwitch2();
if ((Application.platform
is RuntimePlatform.OSXPlayer or RuntimePlatform.OSXServer)
&& RuntimeInformation.ProcessArchitecture == Architecture.X64)
Expand Down
4 changes: 3 additions & 1 deletion src/Sentry.Unity/SentryUnityOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,7 @@ or RuntimePlatform.PS5
// Special casing Xbox: `Application.persistentDataPath` returns an empty string on packaged builds.
if (IsKnownPlatform(application.Platform)
&& application.Platform is not RuntimePlatform.Switch
&& !application.Platform.IsSwitch2()
&& application.Platform is not RuntimePlatform.GameCoreXboxSeries
&& application.Platform is not RuntimePlatform.GameCoreXboxOne)
{
Expand All @@ -664,7 +665,8 @@ or RuntimePlatform.WebGLPlayer
or RuntimePlatform.GameCoreXboxSeries
or RuntimePlatform.GameCoreXboxOne
or RuntimePlatform.PS5
or RuntimePlatform.Switch;
or RuntimePlatform.Switch
|| platform.Value.IsSwitch2();
}

public override string ToString()
Expand Down
Loading
Loading