Skip to content

Commit

Permalink
Merge branch 'main' into dev/mandel/just-rsp-apidefinition
Browse files Browse the repository at this point in the history
  • Loading branch information
mandel-macaque authored Jan 25, 2025
2 parents dd600c3 + fba23cf commit 3d68d50
Show file tree
Hide file tree
Showing 26 changed files with 690 additions and 17 deletions.
15 changes: 15 additions & 0 deletions src/ObjCBindings/BindingTypeTag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ public enum Class : Int64 {
/// Use to let the generator know that the default constructor should not be generated.
/// </summary>
DisableDefaultCtor = 1 << 2,

/// <summary>
/// Flags the object as being thread safe.
/// </summary>
IsThreadSafe = 1 << 3,
}

/// <summary>
Expand All @@ -32,6 +37,11 @@ public enum Protocol : Int64 {
/// Use the default values.
/// </summary>
Default = 0,

/// <summary>
/// Flags the object as being thread safe.
/// </summary>
IsThreadSafe = 1 << 2,
}

/// <summary>
Expand All @@ -44,6 +54,11 @@ public enum Category : Int64 {
/// Use the default values.
/// </summary>
Default = 0,

/// <summary>
/// Flags the object as being thread safe.
/// </summary>
IsThreadSafe = 1 << 2,
}

/// <summary>
Expand Down
15 changes: 15 additions & 0 deletions src/ObjCBindings/ExportTag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ public enum Constructor : Int64 {
/// Map to Objective-C/clang use of __attribute__((objc_designated_initializer)).
/// </summary>
DesignatedInitializer = 1 << 2,

/// <summary>
/// Flags the object as being thread safe.
/// </summary>
IsThreadSafe = 1 << 3,
}

/// <summary>
Expand Down Expand Up @@ -59,6 +64,11 @@ public enum Method : Int64 {
/// </summary>
CustomMarshalDirective = 1 << 5,

/// <summary>
/// Flags the object as being thread safe.
/// </summary>
IsThreadSafe = 1 << 6,

}

/// <summary>
Expand Down Expand Up @@ -112,6 +122,11 @@ public enum Property : Int64 {
/// </summary>
DisableZeroCopy = 1 << 6,

/// <summary>
/// Flags the object as being thread safe.
/// </summary>
IsThreadSafe = 1 << 7,

}
}

Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ readonly partial struct Binding {
/// </summary>
public BindingInfo BindingInfo => bindingInfo;

/// <summary>
/// Returns if the binding has been declared to be thread safe.
/// </summary>
public bool IsThreadSafe => bindingInfo.IsThreadSafe;

/// <summary>
/// Returns all the library names and paths that are needed by the native code represented by the code change.
/// </summary>
Expand Down
15 changes: 15 additions & 0 deletions src/rgen/Microsoft.Macios.Generator/DataModel/BindingInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System;
using System.Runtime.InteropServices;
using Microsoft.Macios.Generator.Attributes;
using ObjCBindings;

namespace Microsoft.Macios.Generator.DataModel;

Expand All @@ -20,6 +21,20 @@ namespace Microsoft.Macios.Generator.DataModel;

public BindingType BindingType => bindingType;

/// <summary>
/// Returns if the binding has been declared to be thread safe.
/// </summary>
public bool IsThreadSafe {
get {
return bindingType switch {
BindingType.Category => categoryData.Flags.HasFlag (Category.IsThreadSafe),
BindingType.Class => classData.Flags.HasFlag (Class.IsThreadSafe),
BindingType.Protocol => protocolData.Flags.HasFlag (Protocol.IsThreadSafe),
_ => false
};
}
}

public BindingInfo (BindingType type, BindingTypeData data)
{
bindingType = type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ readonly partial struct Method {
/// </summary>
public ExportData<ObjCBindings.Method> ExportMethodData { get; }

/// <summary>
/// Returns if the method was marked as thread safe.
/// </summary>
public bool IsThreadSafe => ExportMethodData.Flags.HasFlag (ObjCBindings.Method.IsThreadSafe);

/// <summary>
/// True if the method was exported with the MarshalNativeExceptions flag allowing it to support native exceptions.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ public bool IsNotification
[MemberNotNullWhen (true, nameof (ExportPropertyData))]
public bool IsProperty => ExportPropertyData is not null;

/// <summary>
/// Returns if the property was marked as thread safe.
/// </summary>
public bool IsThreadSafe =>
IsProperty && ExportPropertyData.Value.Flags.HasFlag (ObjCBindings.Property.IsThreadSafe);

/// <summary>
/// True if the method was exported with the MarshalNativeExceptions flag allowing it to support native exceptions.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ symbol is IArrayTypeSymbol arrayTypeSymbol
symbol.GetInheritance (
isNSObject: out isNSObject,
isNativeObject: out isINativeObject,
isDictionaryContainer: out isDictionaryContainer,
parents: out parents,
interfaces: out interfaces);

Expand Down
8 changes: 8 additions & 0 deletions src/rgen/Microsoft.Macios.Generator/DataModel/TypeInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,13 @@ public bool IsINativeObject {
init => isINativeObject = value;
}

readonly bool isDictionaryContainer = false;

public bool IsDictionaryContainer {
get => isDictionaryContainer;
init => isDictionaryContainer = value;
}

readonly ImmutableArray<string> parents = [];
public ImmutableArray<string> Parents {
get => parents;
Expand Down Expand Up @@ -284,6 +291,7 @@ public override string ToString ()
sb.Append ($"IsStruct: {IsStruct}, ");
sb.Append ($"IsVoid : {IsVoid}, ");
sb.Append ($"IsNSObject : {IsNSObject}, ");
sb.Append ($"IsDictionaryContainer: {IsDictionaryContainer}, ");
sb.Append ($"IsNativeObject: {IsINativeObject}, ");
sb.Append ($"IsInterface: {IsInterface}, ");
sb.Append ($"IsNativeIntegerType: {IsNativeIntegerType}, ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,18 +402,22 @@ internal static int GetValueTypeSize (this ITypeSymbol type, List<ITypeSymbol> f
/// </summary>
/// <param name="symbol">The symbol whose inheritance we want to retrieve.</param>
/// <param name="isNativeObject">If the type implements the INativeObject interface.</param>
/// <param name="isDictionaryContainer">If the type inherits from Foundation.DictionaryContainer.</param>
/// <param name="parents">An immutable array of the parents in order from closest to furthest.</param>
/// <param name="interfaces">All implemented interfaces by the type and its parents.</param>
/// <param name="isNSObject">If the type inherits from NSObject.</param>
public static void GetInheritance (
this ITypeSymbol symbol, out bool isNSObject, out bool isNativeObject, out ImmutableArray<string> parents,
this ITypeSymbol symbol, out bool isNSObject, out bool isNativeObject, out bool isDictionaryContainer,
out ImmutableArray<string> parents,
out ImmutableArray<string> interfaces)
{
const string nativeObjectInterface = "ObjCRuntime.INativeObject";
const string nsObjectClass = "Foundation.NSObject";
const string dictionaryContainerClass = "Foundation.DictionaryContainer";

isNSObject = false;
isNativeObject = false;
isDictionaryContainer = false;

// parents will be returned directly in a Immutable array via a builder since the order is important
// interfaces will use a hash set because we do not want duplicates.
Expand All @@ -426,6 +430,7 @@ public static void GetInheritance (
// check if we reach the NSObject as a parent
var parentName = currentType.ToDisplayString ().Trim ();
isNSObject |= parentName == nsObjectClass;
isDictionaryContainer |= parentName == dictionaryContainerClass;
parentsBuilder.Add (parentName);

// union with the current interfaces
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public static bool TryParse (AttributeData attributeData,
var count = attributeData.ConstructorArguments.Length;
string selector;
bool @virtual = false;
// custom marshal directive values

switch (count) {
case 1:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System.Diagnostics.CodeAnalysis;
using Microsoft.CodeAnalysis;
using MethodAttributes = Mono.Cecil.MethodAttributes;

namespace Microsoft.Macios.Transformer.Attributes;

readonly struct CoreImageFilterData : IEquatable<CoreImageFilterData> {

public MethodAttributes DefaultCtorVisibility { get; init; }

public MethodAttributes IntPtrCtorVisibility { get; init; }

public MethodAttributes StringCtorVisibility { get; init; }

public CoreImageFilterData ()
{

DefaultCtorVisibility = MethodAttributes.Public;
IntPtrCtorVisibility = MethodAttributes.Private;
StringCtorVisibility = MethodAttributes.Private;
}


public static bool TryParse (AttributeData attributeData,
[NotNullWhen (true)] out CoreImageFilterData? data)
{
var defaultVisibility = MethodAttributes.Public;
var intPtrVisibility = MethodAttributes.Private;
var stringVisibility = MethodAttributes.Private;

// there is not positional constructor for this attribute
foreach (var (argumentName, value) in attributeData.NamedArguments) {
switch (argumentName) {
case "DefaultCtorVisibility":
defaultVisibility = (MethodAttributes) Convert.ToSingle ((int) value.Value!);
break;
case "IntPtrCtorVisibility":
intPtrVisibility = (MethodAttributes) Convert.ToSingle ((int) value.Value!);
break;
case "StringCtorVisibility":
stringVisibility = (MethodAttributes) Convert.ToSingle ((int) value.Value!);
break;
default:
data = null;
return false;
}
}

data = new () {
DefaultCtorVisibility = defaultVisibility,
IntPtrCtorVisibility = intPtrVisibility,
StringCtorVisibility = stringVisibility,
};
return true;
}

public bool Equals (CoreImageFilterData other)
{
if (DefaultCtorVisibility != other.DefaultCtorVisibility)
return false;
if (IntPtrCtorVisibility != other.IntPtrCtorVisibility)
return false;
return StringCtorVisibility == other.StringCtorVisibility;
}

/// <inheritdoc />
public override bool Equals (object? obj)
{
return obj is CoreImageFilterData other && Equals (other);
}

/// <inheritdoc />
public override int GetHashCode ()
=> HashCode.Combine (DefaultCtorVisibility, IntPtrCtorVisibility, StringCtorVisibility);

public static bool operator == (CoreImageFilterData x, CoreImageFilterData y)
{
return x.Equals (y);
}

public static bool operator != (CoreImageFilterData x, CoreImageFilterData y)
{
return !(x == y);
}

/// <inheritdoc />
public override string ToString ()
{
return $"{{ DefaultCtorVisibility: {DefaultCtorVisibility}, IntPtrCtorVisibility: {IntPtrCtorVisibility}, StringCtorVisibility: {StringCtorVisibility} }}";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System.Diagnostics.CodeAnalysis;
using Microsoft.CodeAnalysis;

namespace Microsoft.Macios.Transformer.Attributes;

readonly struct CoreImageFilterPropertyData : IEquatable<CoreImageFilterPropertyData> {

public string Name { get; }

public CoreImageFilterPropertyData (string name)
{
Name = name;
}

public static bool TryParse (AttributeData attributeData,
[NotNullWhen (true)] out CoreImageFilterPropertyData? data)
{
data = null;
var count = attributeData.ConstructorArguments.Length;
string name;

switch (count) {
case 1:
name = (string) attributeData.ConstructorArguments [0].Value!;
break;
default:
// 0 should not be an option..
return false;
}

if (attributeData.NamedArguments.Length == 0) {
data = new (name);
return true;
}

foreach (var (argumentName, value) in attributeData.NamedArguments) {
switch (argumentName) {
case "Name":
name = (string) value.Value!;
break;
default:
data = null;
return false;
}
}

data = new (name);
return true;
}

public bool Equals (CoreImageFilterPropertyData other)
=> Name == other.Name;

/// <inheritdoc />
public override bool Equals (object? obj)
{
return obj is CoreImageFilterPropertyData other && Equals (other);
}

/// <inheritdoc />
public override int GetHashCode ()
=> HashCode.Combine (Name);


public static bool operator == (CoreImageFilterPropertyData x, CoreImageFilterPropertyData y)
{
return x.Equals (y);
}

public static bool operator != (CoreImageFilterPropertyData x, CoreImageFilterPropertyData y)
{
return !(x == y);
}

/// <inheritdoc />
public override string ToString ()
{
return $"{{ Name: '{Name}' }}";
}
}
1 change: 1 addition & 0 deletions src/rgen/Microsoft.Macios.Transformer/AttributesNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ static class AttributesNames {
[BindingFlag]
public const string CheckDisposedAttribute = "CheckDisposedAttribute";
public const string CoreImageFilterAttribute = "CoreImageFilterAttribute";
public const string CoreImageFilterPropertyAttribute = "CoreImageFilterPropertyAttribute";
public const string DefaultCtorVisibilityAttribute = "DefaultCtorVisibilityAttribute";

[BindingFlag (AttributeTargets.Field)] public const string DefaultEnumValueAttribute = "DefaultEnumValueAttribute";
Expand Down
Loading

1 comment on commit 3d68d50

@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.

🔥 [CI Build] Test results 🔥

Test results

❌ Tests failed on VSTS: test results

1 tests crashed, 2 tests failed, 104 tests passed.

Failures

❌ generator tests

1 tests failed, 4 tests passed.
  • Roslyn Transformer tests: Failed (Execution failed with exit code 1)

Html Report (VSDrops) Download

❌ monotouch tests (iOS)

🔥 Failed catastrophically on VSTS: test results - monotouch_ios (no summary found).

Html Report (VSDrops) Download

❌ monotouch tests (MacCatalyst)

1 tests failed, 10 tests passed.
  • monotouch-test/Mac Catalyst/Debug (interpreter): Failed (Test run failed.
    Tests run: 3153 Passed: 2981 Inconclusive: 10 Failed: 1 Ignored: 171)

Html Report (VSDrops) Download

Successes

✅ cecil: All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (iOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (MacCatalyst): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (macOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (Multiple platforms): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (tvOS): All 1 tests passed. Html Report (VSDrops) Download
✅ framework: All 2 tests passed. Html Report (VSDrops) Download
✅ fsharp: All 4 tests passed. Html Report (VSDrops) Download
✅ interdependent-binding-projects: All 4 tests passed. Html Report (VSDrops) Download
✅ introspection: All 6 tests passed. Html Report (VSDrops) Download
✅ linker: All 44 tests passed. Html Report (VSDrops) Download
✅ monotouch (macOS): All 9 tests passed. Html Report (VSDrops) Download
✅ monotouch (tvOS): All 8 tests passed. Html Report (VSDrops) Download
✅ msbuild: All 2 tests passed. Html Report (VSDrops) Download
✅ xcframework: All 4 tests passed. Html Report (VSDrops) Download
✅ xtro: All 1 tests passed. Html Report (VSDrops) Download

Pipeline on Agent
Hash: 3d68d507e9640255629a6036a4475a47d11fceb2 [CI build]

Please sign in to comment.