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] Implement support for our different link modes. #9460

Merged
merged 2 commits into from
Aug 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
22 changes: 21 additions & 1 deletion dotnet/targets/Xamarin.Shared.Sdk.targets
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,10 @@
<_AdditionalTaskAssemblyDirectory>$(_XamarinSdkRootDirectory)tools/dotnet-linker/</_AdditionalTaskAssemblyDirectory>
<_AdditionalTaskAssembly>$(_AdditionalTaskAssemblyDirectory)dotnet-linker.dll</_AdditionalTaskAssembly>
</PropertyGroup>
<Target Name="_ComputeLinkerArguments" DependsOnTargets="_ComputeLinkMode">
<Target Name="_ComputeLinkerArguments" DependsOnTargets="_ComputeLinkMode;ComputeResolvedFilesToPublishList">
<!-- 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'" />

<PropertyGroup>
<!-- Pass the custom options to our custom steps -->
<_CustomLinkerOptionsFile>$([System.IO.Path]::GetFullPath('$(IntermediateOutputPath)custom-linker-options.txt'))</_CustomLinkerOptionsFile>
Expand Down Expand Up @@ -146,6 +149,11 @@
<!-- System.Runtime.dll isn't always copied to the .app -->
<_ExtraTrimmerArgs>$(_ExtraTrimmerArgs) -p copy "System.Runtime"</_ExtraTrimmerArgs>

<!-- TrimMode specifies what the linker will do with framework assemblies -->
<TrimMode Condition="'$(_LinkMode)' == 'None'">copy</TrimMode> <!-- Don't use 'copyused', because that might still end up saving some assemblies, and if that's the platform assembly, it may break the partial static registrar -->
<TrimMode Condition="'$(_LinkMode)' == 'SdkOnly' Or '$(_LinkMode)' == 'Full'">link</TrimMode>
<!-- For Full link mode we also need to set TrimMode for all non-framework assemblies. This is done further below -->

<!-- Verbose output, so that we get something to stdout when something goes wrong -->
<_ExtraTrimmerArgs>$(_ExtraTrimmerArgs) --verbose</_ExtraTrimmerArgs>

Expand All @@ -161,7 +169,19 @@
-->
<_ExtraTrimmerArgs>$(_ExtraTrimmerArgs) -b</_ExtraTrimmerArgs>
</PropertyGroup>

<ItemGroup>
<!-- Mark all assemblies to be linked if we're linking all assemblies -->
<ResolvedFileToPublish
Update="@(ResolvedFileToPublish)"
Condition="'$(_LinkMode)' == 'Full' And '%(ResolvedFileToPublish.Extension)' == '.dll' And '%(ResolvedFileToPublish.AssetType)' != 'native'"
>
<TrimMode>link</TrimMode>
</ResolvedFileToPublish>

<!-- Mark our entry assembly as a root assembly. -->
<TrimmerRootAssembly Include="$(AssemblyName)" />

<!-- add a custom step which inserts any other steps we need -->
<_TrimmerCustomSteps Include="$(_AdditionalTaskAssembly)">
<BeforeStep>LoadReferencesStep</BeforeStep>
Expand Down
2 changes: 1 addition & 1 deletion tools/common/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public partial class Application
public ApplePlatform Platform { get { return Driver.TargetFramework.Platform; } }

// Linker config
public LinkMode LinkMode = LinkMode.All;
public LinkMode LinkMode = LinkMode.Full;
public List<string> LinkSkipped = new List<string> ();
public List<string> Definitions = new List<string> ();
public I18nAssemblies I18n;
Expand Down
2 changes: 1 addition & 1 deletion tools/common/LinkMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Xamarin.Bundler {
public enum LinkMode {
None,
SDKOnly,
All,
Full,
Platform,
}
}
2 changes: 1 addition & 1 deletion tools/mmp/driver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ static void Pack (IList<string> unprocessed)
if (generate_plist)
GeneratePList ();

if (App.LinkMode != LinkMode.All && App.RuntimeOptions != null)
if (App.LinkMode != LinkMode.Full && App.RuntimeOptions != null)
App.RuntimeOptions.Write (resources_dir);

if (App.AOTOptions != null && App.AOTOptions.IsAOT) {
Expand Down