From 3a8040e9c1cb6d0fcd1e2f7023dac49592b8d183 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Wed, 2 Sep 2020 09:32:31 +0200 Subject: [PATCH 1/3] [dotnet] Pass the Optimize flags from the extra bundler arguments to the linker configuration. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also call Application.InitializeCommon to initialize the application instance. The important part here is that InitializeCommon calls Optimizations.Initialize to compute the default optimizations. It also calls Set*ExceptionMode and sets the default EnableCoopGC value (so we don't need to call/set those anymore), and it does a few other initialization tasks which we don't need yet, but eventually will. And finally remember to parse the bundler arguments before using them in the dotnet build logic. How did this not cause problems before? 🤦 --- dotnet/targets/Xamarin.Shared.Sdk.targets | 3 ++- tools/dotnet-linker/LinkerConfiguration.cs | 17 ++++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/dotnet/targets/Xamarin.Shared.Sdk.targets b/dotnet/targets/Xamarin.Shared.Sdk.targets index c6dbefd0a00d..56c08f132d4e 100644 --- a/dotnet/targets/Xamarin.Shared.Sdk.targets +++ b/dotnet/targets/Xamarin.Shared.Sdk.targets @@ -139,7 +139,7 @@ <_AdditionalTaskAssemblyDirectory>$(_XamarinSdkRootDirectory)tools/dotnet-linker/ <_AdditionalTaskAssembly>$(_AdditionalTaskAssemblyDirectory)dotnet-linker.dll - + @@ -164,6 +164,7 @@ LinkMode=$(_LinkMode) MarshalManagedExceptionMode=$(_MarshalManagedExceptionMode) MarshalObjectiveCExceptionMode=$(_MarshalObjectiveCExceptionMode) + Optimize=$(_BundlerOptimize) PartialStaticRegistrarLibrary=$(_LibPartialStaticRegistrar) Platform=$(_PlatformName) PlatformAssembly=$(_PlatformAssemblyName).dll diff --git a/tools/dotnet-linker/LinkerConfiguration.cs b/tools/dotnet-linker/LinkerConfiguration.cs index e682d5860656..1e59a0cc38e0 100644 --- a/tools/dotnet-linker/LinkerConfiguration.cs +++ b/tools/dotnet-linker/LinkerConfiguration.cs @@ -45,6 +45,8 @@ public class LinkerConfiguration { // The list of assemblies is populated in CollectAssembliesStep. public List Assemblies = new List (); + + string user_optimize_flags; public static LinkerConfiguration GetInstance (LinkContext context) { @@ -134,6 +136,9 @@ public static LinkerConfiguration GetInstance (LinkContext context) Application.MarshalObjectiveCExceptions = mode; } break; + case "Optimize": + user_optimize_flags = value; + break; case "PartialStaticRegistrarLibrary": PartialStaticRegistrarLibrary = value; break; @@ -191,10 +196,16 @@ public static LinkerConfiguration GetInstance (LinkContext context) ErrorHelper.Platform = Platform; + // Optimizations.Parse can only be called after setting ErrorHelper.Platform + if (!string.IsNullOrEmpty (user_optimize_flags)) { + var messages = new List (); + Application.Optimizations.Parse (Application.Platform, user_optimize_flags, messages); + ErrorHelper.Show (messages); + } + Application.CreateCache (significantLines.ToArray ()); Application.Cache.Location = CacheDirectory; Application.DeploymentTarget = DeploymentTarget; - Application.EnableCoopGC ??= Platform == ApplePlatform.WatchOS; Application.SdkVersion = SdkVersion; switch (Platform) { @@ -211,8 +222,7 @@ public static LinkerConfiguration GetInstance (LinkContext context) if (Driver.TargetFramework.Platform != Platform) throw ErrorHelper.CreateError (99, "Inconsistent platforms. TargetFramework={0}, Platform={1}", Driver.TargetFramework.Platform, Platform); - Application.SetManagedExceptionMode (); - Application.SetObjectiveCExceptionMode (); + Application.InitializeCommon (); } public void Write () @@ -232,6 +242,7 @@ public void Write () Console.WriteLine ($" LinkMode: {LinkMode}"); Console.WriteLine ($" MarshalManagedExceptions: {Application.MarshalManagedExceptions} (IsDefault: {Application.IsDefaultMarshalManagedExceptionMode})"); Console.WriteLine ($" MarshalObjectiveCExceptions: {Application.MarshalObjectiveCExceptions}"); + Console.WriteLine ($" Optimize: {user_optimize_flags} => {Application.Optimizations}"); Console.WriteLine ($" PartialStaticRegistrarLibrary: {PartialStaticRegistrarLibrary}"); Console.WriteLine ($" Platform: {Platform}"); Console.WriteLine ($" PlatformAssembly: {PlatformAssembly}.dll"); From dcc1750d0a571c6621914d5b81854aded1e5432d Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Wed, 9 Sep 2020 09:49:56 +0200 Subject: [PATCH 2/3] [tests] Set the verbosity using the additional args instead of an internal variable. The internal _BundlerVerbosity variable is overwritten now (with the verbosity value from the additional args). --- tests/dotnet/UnitTests/ProjectTest.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/dotnet/UnitTests/ProjectTest.cs b/tests/dotnet/UnitTests/ProjectTest.cs index 7efeda850cfe..34ac0afc6dc8 100644 --- a/tests/dotnet/UnitTests/ProjectTest.cs +++ b/tests/dotnet/UnitTests/ProjectTest.cs @@ -12,7 +12,10 @@ namespace Xamarin.Tests { [TestFixture] public class DotNetProjectTest { - Dictionary verbosity = new Dictionary { { "_BundlerVerbosity", "1" } }; + Dictionary verbosity = new Dictionary { + { "MtouchExtraArgs", "-v" }, + { "MonoBundlingExtraArgs", "-v" }, + }; string GetProjectPath (string project, string subdir = null) { From 8a7833f00974a44d44bda0f57ba947056f753149 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Wed, 9 Sep 2020 12:26:08 +0200 Subject: [PATCH 3/3] [xharness] Disable tvOS generation for the introspection/.NET test, it incorrect and needs fixing. --- tests/xharness/Harness.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/xharness/Harness.cs b/tests/xharness/Harness.cs index 8a00ed0602d2..84df31ff5e02 100644 --- a/tests/xharness/Harness.cs +++ b/tests/xharness/Harness.cs @@ -390,7 +390,7 @@ void AutoConfigureIOS () IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "interdependent-binding-projects", "interdependent-binding-projects.csproj"))) { Name = "interdependent-binding-projects" }); IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "interdependent-binding-projects", "dotnet", "iOS", "interdependent-binding-projects.csproj"))) { Name = "interdependent-binding-projects", IsDotNetProject = true, SkipiOSVariation = false, SkiptvOSVariation = true, SkipwatchOSVariation = true, SkipTodayExtensionVariation = true, SkipDeviceVariations = true, SkipiOS32Variation = true, }); IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "introspection", "iOS", "introspection-ios.csproj"))) { Name = "introspection" }); - IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "introspection", "iOS", "introspection-ios-dotnet.csproj"))) { Name = "introspection", IsDotNetProject = true, SkipiOSVariation = false, SkiptvOSVariation = false, SkipwatchOSVariation = true, SkipTodayExtensionVariation = true, SkipDeviceVariations = true, SkipiOS32Variation = true, }); + IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "introspection", "iOS", "introspection-ios-dotnet.csproj"))) { Name = "introspection", IsDotNetProject = true, SkipiOSVariation = false, SkiptvOSVariation = true, SkipwatchOSVariation = true, SkipTodayExtensionVariation = true, SkipDeviceVariations = true, SkipiOS32Variation = true, }); IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "monotouch-test", "dotnet", "iOS", "monotouch-test.csproj"))) { Name = "monotouch-test", IsDotNetProject = true, SkipiOSVariation = false, SkiptvOSVariation = true, SkipwatchOSVariation = true, SkipTodayExtensionVariation = true, SkipDeviceVariations = true, SkipiOS32Variation = true, }); IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "linker", "ios", "dont link", "dont link.csproj"))) { Configurations = new string [] { "Debug", "Release" } }); IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "linker", "ios", "dont link", "dotnet", "iOS", "dont link.csproj"))) { Configurations = new string [] { "Debug", "Release" }, IsDotNetProject = true, SkipiOSVariation = false, SkiptvOSVariation = true, SkipwatchOSVariation = true, SkipTodayExtensionVariation = true, SkipDeviceVariations = true, SkipiOS32Variation = true });