Skip to content

Commit

Permalink
Include IL2CPP workarounds in nuget package build targets older than …
Browse files Browse the repository at this point in the history
…netstandard2.1.
  • Loading branch information
timcassell committed Sep 25, 2022
1 parent 39bfba2 commit 68ffd11
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
7 changes: 7 additions & 0 deletions ProtoPromise/ProtoPromise.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@
<DefineConstants>$(DefineConstants);NET_LEGACY</DefineConstants>
</PropertyGroup>

<!--Unity's IL2CPP runtime had a lot of issues that we had to work around, most of which were fixed when they added .Net Standard 2.1 support.
If someone chooses to use the Nuget package instead of the Unity package, and builds with IL2CPP in an older Unity version, we must make sure everything still works with those workarounds.
To keep things simple, we just define ENABLE_IL2CPP in all build targets older than netstandard2.1, so all build targets that older Unity versions can possibly consume will have the workarounds baked in.-->
<PropertyGroup Condition="'$(TargetFramework)'=='net35' OR '$(TargetFramework)'=='net40' OR '$(TargetFramework)'=='net47' OR '$(TargetFramework)'=='netstandard2.0'">
<DefineConstants>$(DefineConstants);ENABLE_IL2CPP</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release_NoProgress|AnyCPU'">
<DefineConstants>$(DefineConstants);RELEASE;PROTO_PROMISE_PROGRESS_DISABLE</DefineConstants>
<DebugSymbols>false</DebugSymbols>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ internal interface IPromiseAwaiter

#if !NETCOREAPP
// Override AwaitOnCompleted implementation to prevent boxing in Unity.
#if UNITY_2021_2_OR_NEWER || !UNITY_5_5_OR_NEWER // C# 9 added in 2021.2. We can also use this in non-Unity library since CIL has supported function pointers forever.
#if UNITY_2021_2_OR_NEWER || NETSTANDARD2_1_OR_GREATER // Even though CIL has always had function pointers, Unity did not properly support the CIL instructions until C# 9/ .Net Standard 2.1 support was added.
internal unsafe abstract class AwaitOverrider<T> where T : INotifyCompletion
{
#pragma warning disable IDE0044 // Add readonly modifier
Expand Down Expand Up @@ -193,7 +193,7 @@ private static void AwaitOnCompletedVirt(ref TAwaiter awaiter, PromiseRefBase as
}
}
}
#else // UNITY_2021_2_OR_NEWER || !UNITY_5_5_OR_NEWER
#else // UNITY_2021_2_OR_NEWER || NETSTANDARD2_1_OR_GREATER
internal abstract class AwaitOverrider<T> where T : INotifyCompletion
{
private static AwaitOverrider<T> s_awaitOverrider;
Expand Down Expand Up @@ -238,7 +238,7 @@ protected override void AwaitOnCompletedVirt(ref TAwaiter awaiter, PromiseRefBas
}
}
}
#endif // UNITY_2021_2_OR_NEWER || !UNITY_5_5_OR_NEWER
#endif // UNITY_2021_2_OR_NEWER || NETSTANDARD2_1_OR_GREATER
#endif // !NETCOREAPP

internal static void ValidateId(short promiseId, PromiseRefBase _ref, int skipFrames)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,9 +407,9 @@ public static Promise<T> First<TEnumerator>(TEnumerator promises) where TEnumera
}
}

#if UNITY_2021_2_OR_NEWER || !UNITY_5_5_OR_NEWER
// Old IL2CPP runtime immediately crashes if these methods exist, even if they are not used. So we only include them if we're not in Unity, or in a newer Unity version with the fixed compiler.
// (Even though it would work with the Mono runtime, the API surface must be kept consistent.)
#if UNITY_2021_2_OR_NEWER || NETSTANDARD2_1_OR_GREATER || NETCOREAPP
// Old IL2CPP runtime immediately crashes if these methods exist, even if they are not used. So we only include them in newer build targets that old Unity versions cannot consume.
// (Even though it works with Mono and other runtimes, the API surface must be kept consistent.)
// See https://github.com/timcassell/ProtoPromise/pull/106 for details.

/// <summary>
Expand Down Expand Up @@ -519,8 +519,7 @@ public static Promise<ValueTuple<int, T>> FirstWithIndex<TEnumerator>(TEnumerato
{
return Promise.FirstWithIndex<T, TEnumerator>(promises);
}
#endif // UNITY_2021_2_OR_NEWER || !UNITY_5_5_OR_NEWER

#endif // UNITY_2021_2_OR_NEWER || NETSTANDARD2_1_OR_GREATER || NETCOREAPP
/// <summary>
/// Returns a <see cref="Promise"/> that will resolve with a list of the promises' values in the same order when they have all resolved.
/// If any promise is rejected or canceled, the returned <see cref="Promise"/> will immediately be rejected or canceled with the same reason.
Expand Down

0 comments on commit 68ffd11

Please sign in to comment.