Skip to content

Commit

Permalink
[xcode16] Merge main into xcode16. (#21164)
Browse files Browse the repository at this point in the history
  • Loading branch information
rolfbjarne authored Sep 6, 2024
2 parents ea8310c + ae99651 commit 02fe91b
Show file tree
Hide file tree
Showing 17 changed files with 344 additions and 73 deletions.
2 changes: 1 addition & 1 deletion Make.config
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ INCLUDE_TVOS=1
INCLUDE_MACCATALYST=1
INCLUDE_DEVICE=1
INCLUDE_DOTNET_WATCHOS=
INCLUDE_XAMARIN_LEGACY=1
INCLUDE_XAMARIN_LEGACY=
INCLUDE_HOTRESTART=1

ENABLE_DOTNET=1
Expand Down
23 changes: 0 additions & 23 deletions NuGet.config
Original file line number Diff line number Diff line change
Expand Up @@ -32,36 +32,13 @@
<add key="dotnet-public" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-public/nuget/v3/index.json" protocolVersion="3" />
<add key="Dotnet arcade" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-eng/nuget/v3/index.json" />
<add key="dotnet-tools" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json" />
<!-- We've dropped support for .NET 6, but let's keep the feed in for a little while longer to make sure it's dropped throughout our entire stack and the lack of this feed doesn't break our build. -->
<add key="dotnet6" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet6/nuget/v3/index.json" />
<add key="dotnet7" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet7/nuget/v3/index.json" />
<add key="dotnet8" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet8/nuget/v3/index.json" />
<!-- dotnet8-transport is required for Microsoft.DotNet.Cecil -->
<add key="dotnet8-transport" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet8-transport/nuget/v3/index.json" />
<add key="macios-dependencies" value="https://pkgs.dev.azure.com/xamarin/public/_packaging/macios-dependencies/nuget/v3/index.json" />
<add key="xamarin-impl" value="https://pkgs.dev.azure.com/azure-public/vside/_packaging/xamarin-impl/nuget/v3/index.json" />
<add key="local-tests-feed" value="tests/.nuget/packages" />
<!-- These feeds are from main (6.0.4xx runtime branch) to get 6.0.9 versions of numerous .NET 6 packages. It should be possible to remove this after a while. -->
<add key="darc-pub-dotnet-emsdk-3f6c45a" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/darc-pub-dotnet-emsdk-3f6c45a2/nuget/v3/index.json" />
<add key="darc-pub-dotnet-runtime-531f715" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/darc-pub-dotnet-runtime-531f715f/nuget/v3/index.json" />
<!-- Need 6.0.10 feeds too -->
<add key="darc-pub-dotnet-runtime-8c6bcad" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/darc-pub-dotnet-runtime-8c6bcad1/nuget/v3/index.json" />
<!-- And a 6.0.11 feed -->
<add key="darc-pub-dotnet-runtime-f2980ae" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/darc-pub-dotnet-runtime-f2980ae1/nuget/v3/index.json" />
<!-- And a 6.0.12 feed -->
<add key="darc-pub-dotnet-runtime-15d285f" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/darc-pub-dotnet-runtime-15d285f3/nuget/v3/index.json" />
<!-- Add a 6.0.13 feed -->
<add key="darc-pub-dotnet-runtime-de84cf9" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/darc-pub-dotnet-runtime-d5edd29b-1/nuget/v3/index.json" />
<!-- Add a 6.0.14 feed -->
<add key="darc-pub-dotnet-runtime-2e45bc7" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/darc-pub-dotnet-runtime-2e45bc7a/nuget/v3/index.json" />
<!-- Add a 7.0.11 feed -->
<add key="darc-pub-dotnet-runtime-0ece505" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/darc-pub-dotnet-runtime-0ece5051/nuget/v3/index.json" />
<!-- Add a 7.0.17 feed -->
<add key="darc-pub-dotnet-runtime-21f293d" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/darc-pub-dotnet-runtime-21f293d8/nuget/v3/index.json" />
<!-- Add a 7.0.18 feed -->
<add key="darc-pub-dotnet-runtime-b6e8c6a" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/darc-pub-dotnet-runtime-b6e8c6a6/nuget/v3/index.json" />
<!-- Add a 7.0.19 feed -->
<add key="darc-pub-dotnet-runtime-397f9ea" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/darc-pub-dotnet-runtime-397f9eac/nuget/v3/index.json" />
<!-- Add a 7.0.20 feed -->
<add key="darc-pub-dotnet-runtime-fd36db5" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/darc-pub-dotnet-runtime-fd36db5f/nuget/v3/index.json" />
</packageSources>
Expand Down
13 changes: 13 additions & 0 deletions src/Network/NWConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#nullable enable

using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using ObjCRuntime;
using Foundation;
Expand Down Expand Up @@ -157,8 +158,20 @@ static void TrampolineBooleanChangeHandler (IntPtr block, byte value)
[DllImport (Constants.NetworkLibrary)]
static extern unsafe void nw_connection_set_viability_changed_handler (IntPtr handle, void* callback);

#if !XAMCORE_5_0
[Obsolete ("Use 'SetViabilityChangeHandler' instead.")]
[EditorBrowsable (EditorBrowsableState.Never)]
[BindingImpl (BindingImplOptions.Optimizable)]
public unsafe void SetBooleanChangeHandler (Action<bool> callback)
{
SetViabilityChangeHandler (callback);
}
#endif // !XAMCORE_5_0

/// <summary>Set a handler that is called when data can be sent or received.</summary>
/// <param name="callback">The callback to call when data can be sent or received.</param>
[BindingImpl (BindingImplOptions.Optimizable)]
public unsafe void SetViabilityChangeHandler (Action<bool> callback)
{
if (callback is null) {
nw_connection_set_viability_changed_handler (GetCheckedHandle (), null);
Expand Down
19 changes: 15 additions & 4 deletions src/bgen/Generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,14 @@ public TrampolineInfo MakeTrampoline (Type t)
}
}

if (pi.ParameterType.IsPointer && pi.ParameterType.GetElementType ().IsValueType) {
// Technically we should only allow blittable types here, but the C# compiler shows an error later on if any non-blittable types
// are used, because this ends up in the signature of a UnmanagedCallersOnly method.
pars.Add (new TrampolineParameterInfo (TypeManager.FormatType (null, pi.ParameterType), safe_name));
invoke.Append (safe_name);
continue;
}

if (pi.ParameterType.IsSubclassOf (TypeCache.System_Delegate)) {
if (!delegate_types.ContainsKey (pi.ParameterType.Name)) {
delegate_types [pi.ParameterType.FullName] = pi.ParameterType.GetMethod ("Invoke");
Expand Down Expand Up @@ -4556,8 +4564,8 @@ void GenerateMethod (MemberInformation minfo)
argCount++;
}
if (minfo.Method.GetParameters ().Length != argCount) {
ErrorHelper.Warning (1105,
minfo.selector, argCount, minfo.Method, minfo.Method.GetParameters ().Length);
exceptions.Add (ErrorHelper.CreateWarning (1105,
minfo.selector, argCount, minfo.Method, minfo.Method.GetParameters ().Length));
}
}

Expand Down Expand Up @@ -4732,11 +4740,13 @@ group fullname by ns into g
print ("[MonoNativeFunctionWrapper]\n");

var accessibility = mi.DeclaringType.IsInternal (this) ? "internal" : "public";
print ("{3} delegate {0} {1} ({2});",
var isUnsafe = mi.GetParameters ().Any ((v => v.ParameterType.IsPointer)) || mi.ReturnType.IsPointer;
print ("{3}{4} delegate {0} {1} ({2});",
TypeManager.RenderType (mi.ReturnType, mi.ReturnTypeCustomAttributes),
shortName,
RenderParameterDecl (mi.GetParameters ()),
accessibility);
accessibility,
isUnsafe ? " unsafe" : string.Empty);
}

if (group.Namespace is not null) {
Expand Down Expand Up @@ -5075,6 +5085,7 @@ void GenerateProtocolTypes (Type type, string class_visibility, string TypeName,
foreach (var docId in docIds) {
print ($"[DynamicDependencyAttribute (\"{docId}\")]");
}
print ("[BindingImpl (BindingImplOptions.GeneratedCode | BindingImplOptions.Optimizable)]");
print ($"static I{TypeName} ()");
print ("{");
print ("\tGC.KeepAlive (null);"); // need to do _something_ (doesn't seem to matter what), otherwise the static cctor (and the DynamicDependency attributes) are trimmed away.
Expand Down
1 change: 0 additions & 1 deletion tests/cecil-tests/Documentation.KnownFailures.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43619,7 +43619,6 @@ M:Network.NWConnection.Send(System.Byte[],System.Int32,System.Int32,Network.NWCo
M:Network.NWConnection.SendIdempotent(CoreFoundation.DispatchData,Network.NWContentContext,System.Boolean)
M:Network.NWConnection.SendIdempotent(System.Byte[],Network.NWContentContext,System.Boolean)
M:Network.NWConnection.SetBetterPathAvailableHandler(System.Action{System.Boolean})
M:Network.NWConnection.SetBooleanChangeHandler(System.Action{System.Boolean})
M:Network.NWConnection.SetPathChangedHandler(System.Action{Network.NWPath})
M:Network.NWConnection.SetQueue(CoreFoundation.DispatchQueue)
M:Network.NWConnection.SetStateChangeHandler(System.Action{Network.NWConnectionState,Network.NWError})
Expand Down
34 changes: 20 additions & 14 deletions tests/common/shared-dotnet.mk
Original file line number Diff line number Diff line change
Expand Up @@ -72,44 +72,50 @@ ifeq ($(PLATFORM),)
PLATFORM=$(shell basename "$(CURDIR)")
endif

ifeq ($(RUNTIMEIDENTIFIERS),)
ifneq ($(RUNTIMEIDENTIFIERS)$(RUNTIMEIDENTIFIER),)
$(error "Don't set RUNTIMEIDENTIFIER or RUNTIMEIDENTIFIERS, set RID instead")
endif

ifeq ($(RID),)
ifeq ($(PLATFORM),iOS)
RUNTIMEIDENTIFIERS=ios-arm64
RID=ios-arm64
else ifeq ($(PLATFORM),tvOS)
RUNTIMEIDENTIFIERS=tvos-arm64
RID=tvos-arm64
else ifeq ($(PLATFORM),MacCatalyst)
ifeq ($(CONFIG),Release)
RUNTIMEIDENTIFIERS=maccatalyst-x64;maccatalyst-arm64
RID=maccatalyst-x64;maccatalyst-arm64
else ifneq ($(UNIVERSAL),)
RUNTIMEIDENTIFIERS=maccatalyst-x64;maccatalyst-arm64
RID=maccatalyst-x64;maccatalyst-arm64
else ifeq ($(shell arch),arm64)
RUNTIMEIDENTIFIERS=maccatalyst-arm64
RID=maccatalyst-arm64
else
RUNTIMEIDENTIFIERS=maccatalyst-x64
RID=maccatalyst-x64
endif
else ifeq ($(PLATFORM),macOS)
ifeq ($(CONFIG),Release)
RUNTIMEIDENTIFIERS=osx-x64;osx-arm64
RID=osx-x64;osx-arm64
else ifneq ($(UNIVERSAL),)
RUNTIMEIDENTIFIERS=osx-x64;osx-arm64
RID=osx-x64;osx-arm64
else ifeq ($(shell arch),arm64)
RUNTIMEIDENTIFIERS=osx-arm64
RID=osx-arm64
else
RUNTIMEIDENTIFIERS=osx-x64
RID=osx-x64
endif
else
RUNTIMEIDENTIFIERS=unknown-platform-$(PLATFORM)
RID=unknown-platform-$(PLATFORM)
endif
endif

ifneq ($(UNIVERSAL),)
UNIVERSAL_ARGUMENT=/p:UniversalBuild=true
endif

ifeq ($(findstring ;,$(RUNTIMEIDENTIFIERS)),;)
ifeq ($(findstring ;,$(RID)),;)
PATH_RID=
export RUNTIMEIDENTIFIERS=$(RID)
else
PATH_RID=$(RUNTIMEIDENTIFIERS)/
PATH_RID=$(RID)/
export RUNTIMEIDENTIFIER=$(RID)
endif


Expand Down
15 changes: 15 additions & 0 deletions tests/generator/BGenTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1719,5 +1719,20 @@ public void DelegatesWithNullableReturnType (Profile profile)
var delegateCallback = bgen.ApiAssembly.MainModule.GetType ("NS", "MyCallback").Methods.First ((v) => v.Name == "EndInvoke");
Assert.That (delegateCallback.MethodReturnType.CustomAttributes.Any (v => v.AttributeType.Name == "NullableAttribute"), "Nullable return type");
}

[Test]
[TestCase (Profile.iOS)]
public void DelegatesWithPointerTypes (Profile profile)
{
Configuration.IgnoreIfIgnoredPlatform (profile.AsPlatform ());
var bgen = BuildFile (profile, "tests/delegate-types.cs");
bgen.AssertNoWarnings ();

var delegateCallback = bgen.ApiAssembly.MainModule.GetType ("NS", "MyCallback").Methods.First ((v) => v.Name == "EndInvoke");
Assert.IsTrue (delegateCallback.MethodReturnType.ReturnType.IsPointer, "Pointer return type");
foreach (var p in delegateCallback.Parameters.Where (v => v.Name != "result")) {
Assert.IsTrue (p.ParameterType.IsPointer, $"Pointer parameter type: {p.Name}");
}
}
}
}
15 changes: 15 additions & 0 deletions tests/generator/tests/delegate-types.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;

using Foundation;
using ObjCRuntime;

namespace NS {
unsafe delegate byte* MyCallback (sbyte* a, short* b, ushort* c, int* d, uint* e, long* f, ulong* g, float* h, double* i);

[BaseType (typeof (NSObject))]
interface Widget {
[Export ("foo")]
[NullAllowed]
MyCallback Foo { get; set; }
}
}
32 changes: 32 additions & 0 deletions tests/monotouch-test/ObjCRuntime/RegistrarTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Diagnostics.CodeAnalysis;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Threading;
Expand Down Expand Up @@ -5536,6 +5537,37 @@ public void RefEnumValues ()
Assert.AreEqual (EnumUL.b, ul, "out: UL");
}
}

#if NET && HAS_UIKIT
[Test]
public void ProtocolsTrimmedAway ()
{
PreserveIUIApplicationDelegate (null);

// A little indirection to try to make the trimmer not be helpful and preserve all the methods on IUIApplicationDelegate.
AssertMemberCount (typeof (IUIApplicationDelegate));
}

void AssertMemberCount (Type type)
{
var members = type.GetMembers (BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance);
#if OPTIMIZEALL || NATIVEAOT
var expectNoMembers = true;
#else
var expectNoMembers = false;
#endif
if (expectNoMembers) {
Assert.AreEqual (0, members.Length, $"All members should be trimmed away in {type.FullName}:\n\t{string.Join ("\n\t", members.Select (v => v.ToString ()))}");
} else {
Assert.AreNotEqual (0, members.Length, $"All members should not be trimmed away in {type.FullName}");
}
}

void PreserveIUIApplicationDelegate (IUIApplicationDelegate obj)
{
GC.KeepAlive (obj);
}
#endif // NET && HAS_UIKIT
}

#if !__WATCHOS__
Expand Down
1 change: 0 additions & 1 deletion tests/xharness/Harness.cs
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,6 @@ void AutoConfigureIOS ()
IOSTestProjects.Add (new iOSTestProject (TestLabel.Binding, Path.GetFullPath (Path.Combine (RootDirectory, "bindings-test", "iOS", "bindings-test.csproj")), false) { Name = "bindings-test" });

IOSTestProjects.Add (new iOSTestProject (TestLabel.InterdependentBindingProjects, Path.GetFullPath (Path.Combine (RootDirectory, "interdependent-binding-projects", "interdependent-binding-projects.csproj"))) { Name = "interdependent-binding-projects" });
IOSTestProjects.Add (new iOSTestProject (TestLabel.Introspection, Path.GetFullPath (Path.Combine (RootDirectory, "introspection", "iOS", "introspection-ios.csproj"))) { Name = "introspection" });
IOSTestProjects.Add (new iOSTestProject (TestLabel.Linker, Path.GetFullPath (Path.Combine (RootDirectory, "linker", "ios", "dont link", "dont link.csproj"))) {
Configurations = new string [] { "Debug", "Release" },
});
Expand Down
Loading

6 comments on commit 02fe91b

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

Please sign in to comment.