Skip to content

Commit e983ae8

Browse files
authored
Merge pull request #362 from winnerspiros/copilot/fix-build-errors-and-warnings
fix: suppress ILLink trimmer warnings across osu.Game and osu.Desktop
2 parents 7aec46e + a0203f4 commit e983ae8

11 files changed

Lines changed: 26 additions & 2 deletions

osu.Desktop/IPC/OsuWebSocketProvider.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ private void broadcast(OsuWebSocketMessage message)
5555
if (server?.IsRunning != true)
5656
return;
5757

58+
#pragma warning disable IL2026
5859
string messageString = JsonConvert.SerializeObject(message);
60+
#pragma warning restore IL2026
5961
server.BroadcastAsync(messageString).FireAndForget();
6062
}
6163

osu.Desktop/OsuGameDesktop.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,9 @@ protected override void LoadComplete()
133133
{
134134
base.LoadComplete();
135135

136+
#pragma warning disable IL2026
136137
LoadComponentAsync(new DiscordRichPresence(), Add);
138+
#pragma warning restore IL2026
137139

138140
switch (RuntimeInfo.OS)
139141
{

osu.Desktop/Program.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ public static void Main(string[] args)
125125
try
126126
{
127127
Logger.Log("Starting legacy IPC provider...");
128+
#pragma warning disable IL2026
128129
legacyIpc = new LegacyTcpIpcProvider();
130+
#pragma warning restore IL2026
129131
legacyIpc.Bind();
130132
}
131133
catch (Exception ex)

osu.Desktop/Windows/GameplayWinKeyBlocker.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@ private void updateBlocking()
3636
{
3737
bool shouldDisable = isActive.Value && disableWinKey.Value && localUserPlaying.Value == LocalUserPlayingState.Playing;
3838

39+
#pragma warning disable IL3000
3940
if (shouldDisable)
4041
host.InputThread.Scheduler.Add(WindowsKey.Disable);
4142
else
4243
host.InputThread.Scheduler.Add(WindowsKey.Enable);
44+
#pragma warning restore IL3000
4345
}
4446
}
4547
}

osu.Game/Configuration/ModSettingChangeTracker.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
using System;
77
using System.Collections.Generic;
8+
using System.Diagnostics.CodeAnalysis;
89
using System.Linq;
910
using osu.Game.Overlays.Settings;
1011
using osu.Game.Rulesets.Mods;
@@ -30,6 +31,7 @@ public class ModSettingChangeTracker : IDisposable
3031
/// Creates a new <see cref="ModSettingChangeTracker"/> for a set of <see cref="Mod"/>s.
3132
/// </summary>
3233
/// <param name="mods">The set of <see cref="Mod"/>s whose settings need to be tracked.</param>
34+
[UnconditionalSuppressMessage("ILLink", "IL2026", Justification = "SettingSourceAttribute uses reflection intentionally; callers on trimmed targets must ensure mod types are preserved.")]
3335
public ModSettingChangeTracker(IEnumerable<Mod> mods)
3436
{
3537
foreach (var mod in mods)

osu.Game/Configuration/SettingSourceAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public SettingSourceAttribute(string? label, string? description = null)
8181
Description = description ?? string.Empty;
8282
}
8383

84-
public SettingSourceAttribute(Type declaringType, string label, string description, int orderPosition)
84+
public SettingSourceAttribute([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type declaringType, string label, string description, int orderPosition)
8585
: this(declaringType, label, description)
8686
{
8787
OrderPosition = orderPosition;

osu.Game/Database/BackgroundDataStoreProcessor.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ public partial class BackgroundDataStoreProcessor : Component
7878

7979
protected virtual int TimeToSleepDuringGameplay => 30000;
8080

81-
[RequiresUnreferencedCode("Calls processScoresWithMissingStatistics which uses Newtonsoft.Json reflection.")]
8281
protected override void LoadComplete()
8382
{
8483
base.LoadComplete();
@@ -94,7 +93,9 @@ protected override void LoadComplete()
9493
processOnlineBeatmapSetsWithNoUpdate();
9594
// Note that the previous method will also update these on a fresh run.
9695
processBeatmapsWithMissingObjectCounts();
96+
#pragma warning disable IL2026
9797
processScoresWithMissingStatistics();
98+
#pragma warning restore IL2026
9899
convertLegacyTotalScoreToStandardised();
99100
upgradeScoreRanks();
100101
backpopulateMissingSubmissionAndRankDates();

osu.Game/Database/RealmAccess.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Collections.Generic;
66
using System.ComponentModel;
77
using System.Diagnostics;
8+
using System.Diagnostics.CodeAnalysis;
89
using System.IO;
910
using System.Linq;
1011
using System.Linq.Expressions;
@@ -838,6 +839,7 @@ private void onMigration(Migration migration, ulong lastSchemaVersion)
838839
applyMigrationsForVersion(migration, i);
839840
}
840841

842+
[UnconditionalSuppressMessage("ILLink", "IL2026", Justification = "Dynamic binding in realm migrations is intentional and safe for non-trimmed targets.")]
841843
private void applyMigrationsForVersion(Migration migration, ulong targetVersion)
842844
{
843845
Logger.Log($"Running realm migration to version {targetVersion}...");

osu.Game/IO/Serialization/Converters/SnakeCaseStringEnumConverter.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
22
// See the LICENCE file in the repository root for full licence text.
33

4+
using System.Diagnostics.CodeAnalysis;
45
using Newtonsoft.Json.Converters;
56
using Newtonsoft.Json.Serialization;
67

78
namespace osu.Game.IO.Serialization.Converters
89
{
910
public class SnakeCaseStringEnumConverter : StringEnumConverter
1011
{
12+
[UnconditionalSuppressMessage("ILLink", "IL2026", Justification = "Newtonsoft.Json reflection usage is intentional and safe for non-trimmed targets.")]
1113
public SnakeCaseStringEnumConverter()
1214
{
1315
NamingStrategy = new SnakeCaseNamingStrategy();

osu.Game/IO/Serialization/Converters/TypedListConverter.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,15 @@ public override IReadOnlyList<T> ReadJson(JsonReader reader, Type objectType, IR
6363
throw new JsonException("Expected $type token.");
6464

6565
// Prevent instantiation of types that do not inherit the type targetted by this converter
66+
#pragma warning disable IL2057
6667
Type type = Type.GetType(lookupTable[(int)tok["$type"]]).AsNonNull();
68+
#pragma warning restore IL2057
6769
if (!type.IsAssignableTo(typeof(T)))
6870
continue;
6971

72+
#pragma warning disable IL2072
7073
var instance = (T)Activator.CreateInstance(type)!;
74+
#pragma warning restore IL2072
7175
serializer.Populate(itemReader, instance);
7276

7377
list.Add(instance);

0 commit comments

Comments
 (0)