Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dotnet] Pass the Optimize flags from the extra bundler arguments to the linker configuration. #9599

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion dotnet/targets/Xamarin.Shared.Sdk.targets
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
<_AdditionalTaskAssemblyDirectory>$(_XamarinSdkRootDirectory)tools/dotnet-linker/</_AdditionalTaskAssemblyDirectory>
<_AdditionalTaskAssembly>$(_AdditionalTaskAssemblyDirectory)dotnet-linker.dll</_AdditionalTaskAssembly>
</PropertyGroup>
<Target Name="_ComputeLinkerArguments" DependsOnTargets="_ComputeLinkMode;_ComputeFrameworkVariables;_ComputeFrameworkAssemblies;ComputeResolvedFilesToPublishList">
<Target Name="_ComputeLinkerArguments" DependsOnTargets="_ComputeLinkMode;_ComputeFrameworkVariables;_ComputeFrameworkAssemblies;ComputeResolvedFilesToPublishList;_ParseBundlerArguments;">
<!-- Validate the linker mode -->
<Error Text="Invalid link mode: '$(_LinkMode)'. Valid link modes are: 'None', 'SdkOnly' and 'Full'" Condition="'$(_LinkMode)' != 'None' And '$(_LinkMode)' != 'SdkOnly' And '$(_LinkMode)' != 'Full'" />

Expand All @@ -164,6 +164,7 @@
LinkMode=$(_LinkMode)
MarshalManagedExceptionMode=$(_MarshalManagedExceptionMode)
MarshalObjectiveCExceptionMode=$(_MarshalObjectiveCExceptionMode)
Optimize=$(_BundlerOptimize)
PartialStaticRegistrarLibrary=$(_LibPartialStaticRegistrar)
Platform=$(_PlatformName)
PlatformAssembly=$(_PlatformAssemblyName).dll
Expand Down
17 changes: 14 additions & 3 deletions tools/dotnet-linker/LinkerConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public class LinkerConfiguration {

// The list of assemblies is populated in CollectAssembliesStep.
public List<AssemblyDefinition> Assemblies = new List<AssemblyDefinition> ();

string user_optimize_flags;

public static LinkerConfiguration GetInstance (LinkContext context)
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<ProductException> ();
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) {
Expand All @@ -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 ()
Expand All @@ -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");
Expand Down