[tools] Make sure to finish the P/Invoke generator output before running the static registrar. Fixes #15190. (#15214)
Otherwise the P/Invoke generator leaves partial results in the static registrar class, essentially saying things like "we've processed CoreMidi, no need to add an #include for this framework", and then we'd generate the static registrar code and that code would lack the #include for CoreMidi. Finishing the P/Invoke generator output will clear out any state stored in the static registrar. Also fix a few other issues to make the generated P/Invoke wrapper code work, and add a test. Fixes https://github.com/xamarin/xamarin-macios/issues/15190.
This commit is contained in:
Родитель
c68372d6f4
Коммит
77b8b61639
|
@ -21,10 +21,13 @@ using System.ComponentModel;
|
|||
using System.Numerics;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using ObjCRuntime;
|
||||
|
||||
// This type does not come from the CoreGraphics framework
|
||||
#if NET
|
||||
namespace CoreGraphics
|
||||
{
|
||||
[NativeName ("GLKMatrix3")]
|
||||
[StructLayout (LayoutKind.Sequential)]
|
||||
public struct RMatrix3 : IEquatable<RMatrix3>
|
||||
{
|
||||
|
|
|
@ -917,5 +917,26 @@ namespace Xamarin.Tests {
|
|||
Assert.AreEqual (1, errors.Length, "Error count");
|
||||
Assert.AreEqual ($"The UIDeviceFamily value '6' requires macOS 11.0. Please set the 'SupportedOSPlatformVersion' in the project file to at least 14.0 (the Mac Catalyst version equivalent of macOS 11.0). The current value is {minOS} (equivalent to macOS 10.15.2).", errors [0].Message, "Error message");
|
||||
}
|
||||
|
||||
[Test]
|
||||
[TestCase (ApplePlatform.iOS, "iossimulator-x64")]
|
||||
// [TestCase (ApplePlatform.TVOS, "tvos-arm64")] // Currently doesn't work because we overwrite the required MtouchExtraArgs in tests/nunit.frameworks.target in this test.
|
||||
// [TestCase (ApplePlatform.TVOS, "tvossimulator-x64")] // Currently doesn't work because we emit signatures with structs from the MetalPerformanceShaders framework, which isn't available in the tvOS simulator.
|
||||
[TestCase (ApplePlatform.MacOSX, "osx-arm64")]
|
||||
[TestCase (ApplePlatform.MacCatalyst, "maccatalyst-x64")]
|
||||
public void PInvokeWrapperGenerator (ApplePlatform platform, string runtimeIdentifiers)
|
||||
{
|
||||
var project = "MySimpleApp";
|
||||
Configuration.IgnoreIfIgnoredPlatform (platform);
|
||||
|
||||
var project_path = GetProjectPath (project, runtimeIdentifiers: runtimeIdentifiers, platform: platform, out var appPath);
|
||||
Clean (project_path);
|
||||
var properties = GetDefaultProperties (runtimeIdentifiers);
|
||||
var extraArgs = "--require-pinvoke-wrappers:true --registrar:static"; // enable the static registrar too, see https://github.com/xamarin/xamarin-macios/issues/15190.
|
||||
properties ["MonoBundlingExtraArgs"] = extraArgs;
|
||||
properties ["MtouchExtraArgs"] = extraArgs;
|
||||
|
||||
DotNet.AssertBuild (project_path, properties);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2329,6 +2329,7 @@ namespace Registrar {
|
|||
n = "struct trampoline_struct_" + name.ToString ();
|
||||
if (!structures.Contains (n)) {
|
||||
structures.Add (n);
|
||||
declarations.WriteLine ($"// {structure.FullName} (+other structs with same layout)");
|
||||
declarations.WriteLine ("{0} {{\n{1}}};", n, body.ToString ());
|
||||
}
|
||||
|
||||
|
@ -2386,7 +2387,7 @@ namespace Registrar {
|
|||
case "System.UIntPtr":
|
||||
name.Append ('p');
|
||||
body.AppendLine ("void *v{0};", size);
|
||||
size += 4; // for now at least...
|
||||
size += Is64Bits ? 8 : 4;
|
||||
break;
|
||||
default:
|
||||
bool found = false;
|
||||
|
@ -2506,6 +2507,7 @@ namespace Registrar {
|
|||
case "System.Drawing.PointF": return App.Platform == ApplePlatform.MacOSX ? "NSPoint" : "CGPoint";
|
||||
case "System.Drawing.SizeF": return App.Platform == ApplePlatform.MacOSX ? "NSSize" : "CGSize";
|
||||
case "System.String": return "NSString *";
|
||||
case "System.UIntPtr":
|
||||
case "System.IntPtr": return "void *";
|
||||
case "System.SByte": return "signed char";
|
||||
case "System.Byte": return "unsigned char";
|
||||
|
@ -2530,6 +2532,7 @@ namespace Registrar {
|
|||
throw ErrorHelper.CreateError (4102, Errors.MT4102, "System.DateTime", "Foundation.NSDate", descriptiveMethodName);
|
||||
case "ObjCRuntime.Selector": return "SEL";
|
||||
case "ObjCRuntime.Class": return "Class";
|
||||
case "ObjCRuntime.NativeHandle": return "void *";
|
||||
default:
|
||||
if (type.FullName == NFloatTypeName) {
|
||||
CheckNamespace ("CoreGraphics", exceptions);
|
||||
|
@ -4982,7 +4985,7 @@ namespace Registrar {
|
|||
sb.WriteLine ("{");
|
||||
if (is_stret) {
|
||||
sb.StringBuilder.AppendLine ("#if defined (__arm64__)");
|
||||
sb.WriteLine ("xamarin_process_managed_exception (xamarin_create_system_entry_point_not_found_exception (\"{0}\"));", pinfo.EntryPoint);
|
||||
sb.WriteLine ("xamarin_process_managed_exception ((MonoObject *) xamarin_create_system_entry_point_not_found_exception (\"{0}\"));", pinfo.EntryPoint);
|
||||
sb.StringBuilder.AppendLine ("#else");
|
||||
}
|
||||
sb.WriteLine ("@try {");
|
||||
|
|
|
@ -58,11 +58,6 @@ namespace Xamarin {
|
|||
|
||||
if (app.RequiresPInvokeWrappers) {
|
||||
var state = Configuration.PInvokeWrapperGenerationState;
|
||||
if (state.Started) {
|
||||
// The generator is 'started' by the linker, which means it may not
|
||||
// be started if the linker was not executed due to re-using cached results.
|
||||
state.End ();
|
||||
}
|
||||
item = new MSBuildItem {
|
||||
Include = state.SourcePath,
|
||||
Metadata = {
|
||||
|
|
|
@ -39,6 +39,18 @@ namespace Xamarin.Linker.Steps
|
|||
}
|
||||
}
|
||||
|
||||
#if NET
|
||||
protected override void EndProcess ()
|
||||
{
|
||||
if (state?.Started == true) {
|
||||
// The generator is 'started' by the linker, which means it may not
|
||||
// be started if the linker was not executed due to re-using cached results.
|
||||
state.End ();
|
||||
}
|
||||
base.EndProcess ();
|
||||
}
|
||||
#endif
|
||||
|
||||
#if NET
|
||||
public LinkerConfiguration Configuration {
|
||||
get {
|
||||
|
|
|
@ -785,6 +785,11 @@ namespace Xamarin.Bundler {
|
|||
|
||||
CheckSystemMonoVersion ();
|
||||
|
||||
if (App.RequiresPInvokeWrappers) {
|
||||
var state = BuildTarget.LinkerOptions.MarshalNativeExceptionsState;
|
||||
state.End ();
|
||||
}
|
||||
|
||||
if (App.Registrar == RegistrarMode.Static) {
|
||||
registrarPath = Path.Combine (App.Cache.Location, "registrar.m");
|
||||
var registrarH = Path.Combine (App.Cache.Location, "registrar.h");
|
||||
|
@ -1002,7 +1007,6 @@ namespace Xamarin.Bundler {
|
|||
|
||||
if (App.RequiresPInvokeWrappers) {
|
||||
var state = BuildTarget.LinkerOptions.MarshalNativeExceptionsState;
|
||||
state.End ();
|
||||
args.Add (state.SourcePath);
|
||||
}
|
||||
|
||||
|
|
|
@ -516,6 +516,13 @@ namespace Xamarin.Bundler
|
|||
|
||||
MonoTouch.Tuner.Linker.Process (LinkerOptions, out LinkContext, out assemblies);
|
||||
|
||||
var state = MarshalNativeExceptionsState;
|
||||
if (state?.Started == true) {
|
||||
// The generator is 'started' by the linker, which means it may not
|
||||
// be started if the linker was not executed due to re-using cached results.
|
||||
state.End ();
|
||||
}
|
||||
|
||||
ErrorHelper.Show (LinkContext.Exceptions);
|
||||
|
||||
Driver.Watch ("Link Assemblies", 1);
|
||||
|
@ -881,12 +888,6 @@ namespace Xamarin.Bundler
|
|||
|
||||
// Write P/Invokes
|
||||
var state = MarshalNativeExceptionsState;
|
||||
if (state.Started) {
|
||||
// The generator is 'started' by the linker, which means it may not
|
||||
// be started if the linker was not executed due to re-using cached results.
|
||||
state.End ();
|
||||
}
|
||||
|
||||
var ifile = state.SourcePath;
|
||||
var mode = App.LibPInvokesLinkMode;
|
||||
foreach (var abi in GetArchitectures (mode)) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче