Skip to content

Commit 39526e3

Browse files
[One .NET] set %(IsTrimmable) for @(KnownFrameworkReference) (dotnet#5115)
Context: https://github.com/dotnet/installer/blob/97f447f228824c0217d2c8b845b003118673ff22/src/redist/targets/GenerateBundledVersions.targets#L208-L218 Context: https://docs.microsoft.com/dotnet/core/deploying/trimming-options Right now we are modifying the `@(ResolvedFileToPublish)` item group and setting `%(IsTrimmable)` for `Mono.Android.dll`, `Mono.Android.Export.dll`, and `Java.Interop.dll`. Instead we can set this metadata on `@(KnownFrameworkReference)`, which is the way that `Microsoft.NETCore.App` is setup. This way these assembly references will be "trimmable" by default. We should also rename `Microsoft.Android.Sdk.Linker.targets` to `Microsoft.Android.ILLink.targets` to better match the naming in .NET 5. I updated the `LibraryProjectTargetsDoNotBreak` test to use `Touch()`, as it seems like it was randomly failing after these changes.
1 parent 28add0d commit 39526e3

File tree

4 files changed

+17
-30
lines changed

4 files changed

+17
-30
lines changed

build-tools/create-packs/Microsoft.Android.Sdk.proj

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -113,17 +113,19 @@ WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and
113113
<XamarinAndroidVersion>$(AndroidPackVersionLong)</XamarinAndroidVersion>
114114
</PropertyGroup>
115115
<ItemGroup>
116-
<KnownFrameworkReference Include="Microsoft.Android"
117-
TargetFramework="$(_AndroidNETAppTargetFramework)"
118-
RuntimeFrameworkName="Microsoft.Android"
119-
DefaultRuntimeFrameworkVersion="$(AndroidPackVersionLong)"
120-
LatestRuntimeFrameworkVersion="$(AndroidPackVersionLong)"
121-
TargetingPackName="Microsoft.Android.Ref"
122-
TargetingPackVersion="$(AndroidPackVersionLong)"
123-
RuntimePackNamePatterns="Microsoft.Android.Runtime.**RID**"
124-
RuntimePackRuntimeIdentifiers="@(_AndroidNETAppRuntimePackRids, '%3B')"
125-
Profile="Android"
126-
/>
116+
<KnownFrameworkReference
117+
Include="Microsoft.Android"
118+
TargetFramework="$(_AndroidNETAppTargetFramework)"
119+
RuntimeFrameworkName="Microsoft.Android"
120+
DefaultRuntimeFrameworkVersion="$(AndroidPackVersionLong)"
121+
LatestRuntimeFrameworkVersion="$(AndroidPackVersionLong)"
122+
TargetingPackName="Microsoft.Android.Ref"
123+
TargetingPackVersion="$(AndroidPackVersionLong)"
124+
RuntimePackNamePatterns="Microsoft.Android.Runtime.**RID**"
125+
RuntimePackRuntimeIdentifiers="@(_AndroidNETAppRuntimePackRids, '%3B')"
126+
Profile="Android"
127+
IsTrimmable="true"
128+
/>
127129
</ItemGroup>
128130
</Project>
129131
]]>
Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!--
22
***********************************************************************************************
3-
Microsoft.Android.Sdk.AssemblyResolution.targets
3+
Microsoft.Android.Sdk.ILLink.targets
44
55
This file contains the .NET 5-specific targets to customize ILLink
66
@@ -13,14 +13,6 @@ This file contains the .NET 5-specific targets to customize ILLink
1313
Condition=" '$(PublishTrimmed)' == 'true' "
1414
AfterTargets="ComputeResolvedFilesToPublishList"
1515
DependsOnTargets="GetReferenceAssemblyPaths">
16-
<ItemGroup>
17-
<ResolvedFileToPublish
18-
Update="@(ResolvedFileToPublish)"
19-
Condition="'%(ResolvedFileToPublish.Filename)%(ResolvedFileToPublish.Extension)' == 'Java.Interop.dll' or '%(ResolvedFileToPublish.Filename)%(ResolvedFileToPublish.Extension)' == 'Mono.Android.dll' or '%(ResolvedFileToPublish.Filename)%(ResolvedFileToPublish.Extension)' == 'Mono.Android.Export.dll'">
20-
<!-- This makes it so that the platform assembly isn't treated as a root assembly -->
21-
<IsTrimmable>true</IsTrimmable>
22-
</ResolvedFileToPublish>
23-
</ItemGroup>
2416
<PropertyGroup>
2517
<!-- make the output verbose to see what the linker is doing. FIXME: make dependent upon verbosity level -->
2618
<_ExtraTrimmerArgs>$(_ExtraTrimmerArgs) --verbose --deterministic --custom-data XATargetFrameworkDirectories="$(_XATargetFrameworkDirectories)"</_ExtraTrimmerArgs>

src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
<Import Project="$(MSBuildThisFileDirectory)..\tools\Xamarin.Android.Bindings.Core.targets" />
3434
<Import Project="$(MSBuildThisFileDirectory)..\tools\Xamarin.Android.Bindings.ClassParse.targets" />
3535
<Import Project="$(MSBuildThisFileDirectory)Microsoft.Android.Sdk.AssemblyResolution.targets" />
36-
<Import Project="$(MSBuildThisFileDirectory)Microsoft.Android.Sdk.Linker.targets" />
36+
<Import Project="$(MSBuildThisFileDirectory)Microsoft.Android.Sdk.ILLink.targets" />
3737
<Import Project="$(MSBuildThisFileDirectory)Microsoft.Android.Sdk.NuGet.targets" />
3838
<Import Project="$(MSBuildThisFileDirectory)Microsoft.Android.Sdk.Publish.targets" />
3939
<Import Project="$(MSBuildThisFileDirectory)Microsoft.Android.Sdk.Tooling.targets" />

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/IncrementalBuildTest.cs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -501,15 +501,8 @@ public void LibraryProjectTargetsDoNotBreak ()
501501
Assert.IsFalse (b.Output.IsTargetSkipped (target), $"`{target}` should *not* be skipped!");
502502
}
503503

504-
var intermediate = Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath);
505-
var filesToTouch = new [] {
506-
Path.Combine (Root, b.ProjectDirectory, "foo", "armeabi-v7a", "libtest.so"),
507-
Path.Combine (Root, b.ProjectDirectory, "Assets", "foo.txt"),
508-
};
509-
foreach (var file in filesToTouch) {
510-
FileAssert.Exists (file);
511-
File.SetLastWriteTimeUtc (file, DateTime.UtcNow);
512-
}
504+
proj.Touch ("foo\\armeabi-v7a\\libtest.so");
505+
proj.Touch ("Assets\\foo.txt");
513506

514507
//NOTE: second build, targets will run because inputs changed
515508
Assert.IsTrue (b.Build (proj, doNotCleanupOnUpdate: true, saveProject: false), "second build should succeed");

0 commit comments

Comments
 (0)