Skip to content

Commit

Permalink
[generator][dotnet] Add support for `[Uns|S]upportedOSPlatformAttribu…
Browse files Browse the repository at this point in the history
…te` (#10580)

This moves our current/legacy attributes to the ones added in dotnet 5 [1].

Short Forms (only in bindings)

| Old                                   | New                                 |
|---------------------------------------|-------------------------------------|
| [iOS (7,0)]                           | [SupportedOSPlatform ("ios7.0")]    |
| [NoIOS]                               | [UnsupportedOSPlatform ("ios")]     |

Long Forms

| Old                                   | New                                 |
|---------------------------------------|-------------------------------------|
| [Introduced (PlatformName.iOS, 7,0)]  | [SupportedOSPlatform ("ios7.0")]    |
| [Obsoleted (PlatformName.iOS, 12,1)]  | [Obsolete (...)]                    |
| [Deprecated (PlatformName.iOS, 14,3)] | [UnsupportedOSPlatform ("ios14.3")] |
| [Unavailable (PlatformName.iOS)]      | [UnsupportedOSPlatform ("ios")]     |

Other changes

* `[SupportedOSPlatform]` and `[UnsupportedOSPlatform]` are not allowed on `interface` [2] which means they cannot be used for protocols. This is currently handled by inlining the existing attributes on all members.
* `[ObsoletedInOSPlatform]` was removed in net5 RC. This PR is now mapping the existing attributes to `[Obsolote]`, however multiple ones cannot be added so they need to be platform specific.

Remaining work (manual bindings update) tracked in #11055

References

* [1] #10170
* [2] dotnet/runtime#47599
* [3] dotnet/runtime#47601
  • Loading branch information
spouliot authored Apr 10, 2021
1 parent 75e913e commit 4e48aa2
Show file tree
Hide file tree
Showing 72 changed files with 849 additions and 51 deletions.
2 changes: 2 additions & 0 deletions src/CoreAnimation/CALayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ public virtual CAAutoresizingMask AutoresizinMask {
}
}
#endif
#if !NET
[Watch (3,0)][TV (10,0)][Mac (10,12)][iOS (10,0)]
#endif
public CAContentsFormat ContentsFormat {
get { return CAContentsFormatExtensions.GetValue (_ContentsFormat); }
set { _ContentsFormat = value.GetConstant ()!; }
Expand Down
32 changes: 32 additions & 0 deletions src/CoreFoundation/Dispatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,20 +152,24 @@ public void SetTargetQueue (DispatchQueue queue)
[DllImport (Constants.libcLibrary)]
internal extern static void dispatch_suspend (IntPtr o);

#if !NET
[Mac (10,12)]
[iOS (10,0)]
[TV (10,0)]
[Watch (3,0)]
#endif
public void Activate ()
{
dispatch_activate (GetCheckedHandle ());
}

[DllImport (Constants.libcLibrary)]
#if !NET
[Mac (10,12)]
[iOS (10,0)]
[TV (10,0)]
[Watch (3,0)]
#endif
extern static void dispatch_activate (/* dispatch_object_t */ IntPtr @object);
#endif // !COREBUILD
}
Expand Down Expand Up @@ -204,10 +208,12 @@ public DispatchQueue (string label, bool concurrent)
throw new Exception ("Error creating dispatch queue");
}

#if !NET
[Mac (10,12)]
[iOS (10,0)]
[TV (10,0)]
[Watch (3,0)]
#endif
public DispatchQueue (string label, Attributes attributes, DispatchQueue target = null)
: base (dispatch_queue_create_with_target (label, attributes?.Create () ?? IntPtr.Zero, target.GetHandle ()), true)
{
Expand All @@ -223,7 +229,9 @@ public string Label {
}
}

#if !NET
[iOS (7,0)]
#endif
public static string CurrentQueueLabel {
get {
return Marshal.PtrToStringAnsi (dispatch_queue_get_label (IntPtr.Zero));
Expand Down Expand Up @@ -467,8 +475,10 @@ public object GetSpecific (IntPtr key)
return gchandle.Target;
}

#if !NET
[Mac (10,10)]
[iOS (8,0)]
#endif
public DispatchQualityOfService GetQualityOfService (out int relative_priority)
{
unsafe {
Expand All @@ -477,8 +487,10 @@ public DispatchQualityOfService GetQualityOfService (out int relative_priority)
}
}

#if !NET
[Mac (10,10)]
[iOS (8,0)]
#endif
public DispatchQualityOfService QualityOfService {
get {
unsafe {
Expand All @@ -493,10 +505,12 @@ public DispatchQualityOfService QualityOfService {
[DllImport (Constants.libcLibrary)]
extern static IntPtr dispatch_queue_create (string label, IntPtr attr);

#if !NET
[Mac (10,12)]
[iOS (10,0)]
[TV (10,0)]
[Watch (3,0)]
#endif
[DllImport (Constants.libcLibrary)]
extern static IntPtr dispatch_queue_create_with_target (string label, IntPtr attr, IntPtr target);

Expand Down Expand Up @@ -549,8 +563,10 @@ public DispatchQualityOfService QualityOfService {
[DllImport(Constants.libcLibrary)]
extern static IntPtr dispatch_queue_get_specific (IntPtr queue, /* const void* */ IntPtr key);

#if !NET
[Mac (10,10)]
[iOS (8,0)]
#endif
[DllImport (Constants.libcLibrary)]
unsafe extern static /* dispatch_qos_class_t */ DispatchQualityOfService dispatch_queue_get_qos_class (/* dispatch_queue_t */ IntPtr queue, /* int *_Nullable */ int* relative_priority);

Expand Down Expand Up @@ -599,24 +615,32 @@ public class Attributes
{
public bool Concurrent { get; set; }

#if !NET
[Mac (10,12)]
[iOS (10,0)]
[TV (10,0)]
[Watch (3,0)]
#endif
public bool IsInitiallyInactive { get; set; }

#if !NET
[Mac (10,12)]
[iOS (10,0)]
[TV (10,0)]
[Watch (3,0)]
#endif
public AutoreleaseFrequency? AutoreleaseFrequency { get; set; }

#if !NET
[Mac (10,10)]
[iOS (8,0)]
#endif
public int RelativePriority { get; set; }

#if !NET
[Mac (10,10)]
[iOS (8,0)]
#endif
public DispatchQualityOfService? QualityOfService { get; set; }

internal IntPtr Create ()
Expand All @@ -638,30 +662,38 @@ internal IntPtr Create ()
return rv;
}

#if !NET
[Mac (10,12)]
[iOS (10,0)]
[TV (10,0)]
[Watch (3,0)]
#endif
[DllImport (Constants.libcLibrary)]
static extern /* dispatch_queue_attr_t */ IntPtr dispatch_queue_attr_make_initially_inactive (/* dispatch_queue_attr_t _Nullable */ IntPtr attr);

#if !NET
[Mac (10,12)]
[iOS (10,0)]
[TV (10,0)]
[Watch (3,0)]
#endif
[DllImport (Constants.libcLibrary)]
static extern /* dispatch_queue_attr_t */ IntPtr dispatch_queue_attr_make_with_autorelease_frequency (/* dispatch_queue_attr_t _Nullable */ IntPtr attr, /* dispatch_autorelease_frequency_t */ nuint frequency);

#if !NET
[Mac (10,10)]
[iOS (8,0)]
#endif
[DllImport (Constants.libcLibrary)]
static extern /* dispatch_queue_attr_t */ IntPtr dispatch_queue_attr_make_with_qos_class (/* dispatch_queue_attr_t _Nullable */ IntPtr attr, /* dispatch_qos_class_t */ DispatchQualityOfService qos_class, int relative_priority);
}

#if !NET
[Mac (10,12)]
[iOS (10,0)]
[TV (10,0)]
[Watch (3,0)]
#endif
[Native]
public enum AutoreleaseFrequency : ulong /* unsigned long */
{
Expand Down
3 changes: 3 additions & 0 deletions src/CoreFoundation/OSLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@
using System.Collections.Generic;

namespace CoreFoundation {

#if !NET
[Mac (10,12), iOS (10,0), Watch (3,0), TV (10,0)]
[Introduced (PlatformName.MacCatalyst, 13, 0)]
#endif
public sealed class OSLog : NativeObject {

static OSLog _default;
Expand Down
4 changes: 4 additions & 0 deletions src/CoreGraphics/CGColorConversionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

namespace CoreGraphics {

#if !NET
[iOS (10,0)][TV (10,0)][Watch (3,0)][Mac (10,12)]
#endif
[StructLayout (LayoutKind.Sequential)]
public struct GColorConversionInfoTriple {
public CGColorSpace Space;
Expand All @@ -25,7 +27,9 @@ public struct GColorConversionInfoTriple {
}

// CGColorConverter.h
#if !NET
[iOS (10,0)][TV (10,0)][Watch (3,0)][Mac (10,12)]
#endif
public partial class CGColorConversionInfo : INativeObject, IDisposable {

/* invoked by marshallers */
Expand Down
16 changes: 12 additions & 4 deletions src/CoreGraphics/CGColorConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@

namespace CoreGraphics {

[TV (9,2)][Obsoleted (PlatformName.TvOS, 10,0, message: "Replaced by 'GColorConversionInfoTriple'.")]
[iOS (9,3)][Obsoleted (PlatformName.iOS, 10,0, message: "Replaced by 'GColorConversionInfoTriple'.")]
#if !NET
[TV (9,2)]
[iOS (9,3)]
#endif
[Obsoleted (PlatformName.TvOS, 10,0, message: "Replaced by 'GColorConversionInfoTriple'.")]
[Obsoleted (PlatformName.iOS, 10,0, message: "Replaced by 'GColorConversionInfoTriple'.")]
[StructLayout (LayoutKind.Sequential)]
public struct CGColorConverterTriple {
public CGColorSpace Space;
Expand All @@ -30,8 +34,12 @@ public struct CGColorConverterTriple {
}

// CGColorConverter.h
[TV (9,2)][Obsoleted (PlatformName.TvOS, 10,0, message: "Replaced by 'CGColorConversionInfo'.")]
[iOS (9,3)][Obsoleted (PlatformName.iOS, 10,0, message: "Replaced by 'CGColorConversionInfo'.")]
#if !NET
[TV (9,2)]
[iOS (9,3)]
#endif
[Obsoleted (PlatformName.TvOS, 10,0, message: "Replaced by 'CGColorConversionInfo'.")]
[Obsoleted (PlatformName.iOS, 10,0, message: "Replaced by 'CGColorConversionInfo'.")]
public class CGColorConverter : INativeObject, IDisposable
{
/* invoked by marshallers */
Expand Down
Loading

4 comments on commit 4e48aa2

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ Tests failed on Build ❌

Tests failed on Build.

API diff

✅ API Diff from stable

View API diff

Packages generated

View packages

Test results

1 tests failed, 180 tests passed.

Failed tests

  • introspection/watchOS 32-bits - simulator/Debug (watchOS 5.0): LaunchFailure

Pipeline on Agent XAMBOT-1036'

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥 Tests failed catastrophically on VSTS: device tests tvOS (no summary found). 🔥

Result file $(TEST_SUMMARY_PATH) not found.

Pipeline on Agent

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥 Tests failed catastrophically on VSTS: device tests iOS32b (no summary found). 🔥

Result file $(TEST_SUMMARY_PATH) not found.

Pipeline on Agent

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥 Tests failed catastrophically on VSTS: device tests iOS (no summary found). 🔥

Result file $(TEST_SUMMARY_PATH) not found.

Pipeline on Agent

Please sign in to comment.