Skip to content

Commit 02c740a

Browse files
authored
Exclude plugin sources that use sentry-native if build platform isn't supported (#937)
* Exclude plugin sources that use sentry-native if build platform isn't supported * Update plugin-dev/Source/Sentry/Sentry.Build.cs * Update docs link * Fix macro redefinition warning if plugin extension is installed * Add platform include macro * Update package snapshot * Exclude macro clang format
1 parent efd668c commit 02c740a

File tree

7 files changed

+79
-2
lines changed

7 files changed

+79
-2
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright (c) 2025 Sentry. All Rights Reserved.
2+
3+
#pragma once
4+
5+
// clang-format off
6+
7+
#ifdef SENTRY_PLATFORM_NULL
8+
#define SENTRY_COMPILED_PLATFORM_HEADER(Suffix) \
9+
PREPROCESSOR_TO_STRING(PREPROCESSOR_JOIN(Null/Null, Suffix))
10+
#else
11+
#define SENTRY_COMPILED_PLATFORM_HEADER(Suffix) \
12+
COMPILED_PLATFORM_HEADER(Suffix)
13+
#endif
14+
15+
// clang-format on

plugin-dev/Source/Sentry/Private/HAL/PlatformSentrySubsystem.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22

33
#pragma once
44

5-
#include COMPILED_PLATFORM_HEADER(SentrySubsystem.h)
5+
#include "PlatformSentryDefines.h"
6+
7+
#include SENTRY_COMPILED_PLATFORM_HEADER(SentrySubsystem.h)

plugin-dev/Source/Sentry/Private/HAL/PlatformSentryUser.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22

33
#pragma once
44

5-
#include COMPILED_PLATFORM_HEADER(SentryUser.h)
5+
#include "PlatformSentryDefines.h"
6+
7+
#include SENTRY_COMPILED_PLATFORM_HEADER(SentryUser.h)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright (c) 2025 Sentry. All Rights Reserved.
2+
3+
#pragma once
4+
5+
#include "Interface/SentrySubsystemInterface.h"
6+
7+
class FNullSentrySubsystem : public ISentrySubsystem
8+
{
9+
public:
10+
virtual ~FNullSentrySubsystem() override = default;
11+
12+
virtual void InitWithSettings(const USentrySettings* settings, USentryBeforeSendHandler* beforeSendHandler, USentryBeforeBreadcrumbHandler* beforeBreadcrumbHandler, USentryTraceSampler* traceSampler) override {}
13+
virtual void Close() override {}
14+
virtual bool IsEnabled() override { return false; }
15+
virtual ESentryCrashedLastRun IsCrashedLastRun() override { return ESentryCrashedLastRun::NotEvaluated; }
16+
virtual void AddBreadcrumb(TSharedPtr<ISentryBreadcrumb> breadcrumb) override {}
17+
virtual void AddBreadcrumbWithParams(const FString& Message, const FString& Category, const FString& Type, const TMap<FString, FString>& Data, ESentryLevel Level) override {}
18+
virtual void ClearBreadcrumbs() override {}
19+
virtual TSharedPtr<ISentryId> CaptureMessage(const FString& message, ESentryLevel level) override { return nullptr; }
20+
virtual TSharedPtr<ISentryId> CaptureMessageWithScope(const FString& message, ESentryLevel level, const FSentryScopeDelegate& onConfigureScope) override { return nullptr; }
21+
virtual TSharedPtr<ISentryId> CaptureEvent(TSharedPtr<ISentryEvent> event) override { return nullptr; }
22+
virtual TSharedPtr<ISentryId> CaptureEventWithScope(TSharedPtr<ISentryEvent> event, const FSentryScopeDelegate& onScopeConfigure) override { return nullptr; }
23+
virtual TSharedPtr<ISentryId> CaptureEnsure(const FString& type, const FString& message) override { return nullptr; }
24+
virtual void CaptureUserFeedback(TSharedPtr<ISentryUserFeedback> userFeedback) override {}
25+
virtual void SetUser(TSharedPtr<ISentryUser> user) override {}
26+
virtual void RemoveUser() override {}
27+
virtual void ConfigureScope(const FSentryScopeDelegate& onConfigureScope) override {}
28+
virtual void SetContext(const FString& key, const TMap<FString, FString>& values) override {}
29+
virtual void SetTag(const FString& key, const FString& value) override {}
30+
virtual void RemoveTag(const FString& key) override {}
31+
virtual void SetLevel(ESentryLevel level) override {}
32+
virtual void StartSession() override {}
33+
virtual void EndSession() override {}
34+
virtual TSharedPtr<ISentryTransaction> StartTransaction(const FString& name, const FString& operation) override { return nullptr; }
35+
virtual TSharedPtr<ISentryTransaction> StartTransactionWithContext(TSharedPtr<ISentryTransactionContext> context) override { return nullptr; }
36+
virtual TSharedPtr<ISentryTransaction> StartTransactionWithContextAndTimestamp(TSharedPtr<ISentryTransactionContext> context, int64 timestamp) override { return nullptr; }
37+
virtual TSharedPtr<ISentryTransaction> StartTransactionWithContextAndOptions(TSharedPtr<ISentryTransactionContext> context, const TMap<FString, FString>& options) override { return nullptr; }
38+
virtual TSharedPtr<ISentryTransactionContext> ContinueTrace(const FString& sentryTrace, const TArray<FString>& baggageHeaders) override { return nullptr; }
39+
};
40+
41+
typedef FNullSentrySubsystem FPlatformSentrySubsystem;

plugin-dev/Source/Sentry/Sentry.Build.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,5 +161,18 @@ public Sentry(ReadOnlyTargetRules Target) : base(Target)
161161

162162
AddEngineThirdPartyPrivateStaticDependencies(Target, "libcurl");
163163
}
164+
else
165+
{
166+
if (GetType() == typeof(Sentry))
167+
{
168+
PublicDefinitions.Add("SENTRY_PLATFORM_NULL");
169+
170+
// Exclude sources in `Private/GenericPlatform` that use sentry-native API from the build if target platform isn't supported
171+
// Plugin extensions that add support for more platforms (e.g. consoles) can override this define if needed
172+
PublicDefinitions.Add("USE_SENTRY_NATIVE=0");
173+
174+
Console.WriteLine("To use Sentry SDK on game consoles follow the instructions at https://docs.sentry.io/platforms/unreal/game-consoles/");
175+
}
176+
}
164177
}
165178
}

scripts/packaging/package-github.snapshot

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ Source/Sentry/Private/GenericPlatform/Infrastructure/GenericPlatformSentryConver
104104
Source/Sentry/Private/GenericPlatform/Infrastructure/GenericPlatformSentryConverters.h
105105
Source/Sentry/Private/HAL/PlatformSentryAttachment.h
106106
Source/Sentry/Private/HAL/PlatformSentryBreadcrumb.h
107+
Source/Sentry/Private/HAL/PlatformSentryDefines.h
107108
Source/Sentry/Private/HAL/PlatformSentryEvent.h
108109
Source/Sentry/Private/HAL/PlatformSentryHint.h
109110
Source/Sentry/Private/HAL/PlatformSentryId.h
@@ -147,6 +148,7 @@ Source/Sentry/Private/Null/NullSentryId.h
147148
Source/Sentry/Private/Null/NullSentrySamplingContext.h
148149
Source/Sentry/Private/Null/NullSentryScope.h
149150
Source/Sentry/Private/Null/NullSentrySpan.h
151+
Source/Sentry/Private/Null/NullSentrySubsystem.h
150152
Source/Sentry/Private/Null/NullSentryTransaction.h
151153
Source/Sentry/Private/Null/NullSentryTransactionContext.h
152154
Source/Sentry/Private/Null/NullSentryUser.h

scripts/packaging/package-marketplace.snapshot

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ Source/Sentry/Private/GenericPlatform/Infrastructure/GenericPlatformSentryConver
103103
Source/Sentry/Private/GenericPlatform/Infrastructure/GenericPlatformSentryConverters.h
104104
Source/Sentry/Private/HAL/PlatformSentryAttachment.h
105105
Source/Sentry/Private/HAL/PlatformSentryBreadcrumb.h
106+
Source/Sentry/Private/HAL/PlatformSentryDefines.h
106107
Source/Sentry/Private/HAL/PlatformSentryEvent.h
107108
Source/Sentry/Private/HAL/PlatformSentryHint.h
108109
Source/Sentry/Private/HAL/PlatformSentryId.h
@@ -146,6 +147,7 @@ Source/Sentry/Private/Null/NullSentryId.h
146147
Source/Sentry/Private/Null/NullSentrySamplingContext.h
147148
Source/Sentry/Private/Null/NullSentryScope.h
148149
Source/Sentry/Private/Null/NullSentrySpan.h
150+
Source/Sentry/Private/Null/NullSentrySubsystem.h
149151
Source/Sentry/Private/Null/NullSentryTransaction.h
150152
Source/Sentry/Private/Null/NullSentryTransactionContext.h
151153
Source/Sentry/Private/Null/NullSentryUser.h

0 commit comments

Comments
 (0)