-
Notifications
You must be signed in to change notification settings - Fork 578
[TrimmableTypeMap] Pre-generate Mono.Android/Java.Interop typemaps at SDK build time #12127
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
Open
simonrozsival
wants to merge
24
commits into
main
Choose a base branch
from
dev/simonrozsival/pregenerate-mono-android-typemap
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
59e8c7e
[TrimmableTypeMap] Prototype: emit per-assembly typemaps without the …
simonrozsival 24be1cd
[TrimmableTypeMap] Root: reference pre-generated framework typemaps u…
simonrozsival 4038237
[TrimmableTypeMap] Pre-generate Mono.Android typemap at SDK build time
simonrozsival 0204e15
[TrimmableTypeMap] Emit pre-built Mono.Android typemap into the SDK p…
simonrozsival 2ecb273
[TrimmableTypeMap] Pre-compile Mono.Android JCWs into mono.android-ty…
simonrozsival cbd1c05
[TrimmableTypeMap] Support reference-only assemblies + framework type…
simonrozsival 0ac7bc0
[TrimmableTypeMap] App build: consume pre-generated Mono.Android typemap
simonrozsival b3d5711
[TrimmableTypeMap] Ship + merge pre-generated Mono.Android ACW map fo…
simonrozsival 7b28317
[TrimmableTypeMap] Pre-generate Mono.Android + Java.Interop together;…
simonrozsival 5e349c7
[TrimmableTypeMap] Fall back to normal scan for Debug NativeAOT (aggr…
simonrozsival f31eea5
Address code review feedback on pre-generated Mono.Android typemap
simonrozsival f039f94
Merge origin/main into pregenerated typemap work
simonrozsival 5eed13f
Fix pregenerated typemap packaging and CoreCLR builds
simonrozsival 90fbc3d
[TrimmableTypeMap] Skip redundant assembly reference scans
simonrozsival d8ec4f9
Revert "[TrimmableTypeMap] Skip redundant assembly reference scans"
simonrozsival 5e3ceb7
Fix pre-generated typemap Java packaging
simonrozsival 0ccfc85
Fix pre-generated typemap runtime handling
simonrozsival eb14959
Merge remote-tracking branch 'origin/main' into copilot/pr-12127-root…
simonrozsival 085942a
Fix merged typemap test call
simonrozsival 3386201
Include pre-generated framework Java classes
simonrozsival a227448
Ship trimmable framework Java wrappers
simonrozsival 8aaa658
Do not package framework wrappers in libraries
simonrozsival d55cfea
Fix pre-generated typemap incrementality
simonrozsival 19f36ee
Merge branch 'main' into dev/simonrozsival/pregenerate-mono-android-t…
simonrozsival File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
155 changes: 155 additions & 0 deletions
155
build-tools/create-packs/Microsoft.Android.Sdk.TrimmableTypeMap.targets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,155 @@ | ||
| <!-- | ||
| Pre-generates the trimmable type map for Mono.Android at SDK build time (issue #10792). | ||
|
|
||
| App builds otherwise rescan the ~8000 Mono.Android types on every (Debug) build. Instead we | ||
| scan Mono.Android once here and ship the resulting typemap assemblies and Java Callable Wrappers | ||
| in the SDK pack. The typemap anchors on Java.Lang.Object (ForceSharedTypemapUniverse=true) to | ||
| coordinate aliases across Mono.Android and Java.Interop. Debug app builds can consume it because | ||
| their remaining typemaps use separate per-assembly universes. Release builds must instead scan the | ||
| complete app closure so shared-universe alias ownership includes application types. The root | ||
| _Microsoft.Android.TypeMaps assembly is NOT generated here (GenerateRootAssembly=false) — the | ||
| Debug app build emits it and references this pre-generated typemap under Java.Lang.Object. | ||
| --> | ||
| <Project> | ||
|
|
||
| <UsingTask TaskName="Xamarin.Android.Tasks.GenerateTrimmableTypeMap" AssemblyFile="$(MicrosoftAndroidSdkOutDir)Xamarin.Android.Build.Tasks.dll" /> | ||
|
|
||
| <PropertyGroup> | ||
| <_PreBuiltTypeMapPackSubDir>data\prebuilt-typemap</_PreBuiltTypeMapPackSubDir> | ||
| <_PreBuiltTypeMapOutputDir>$(MicrosoftAndroidSdkPackDir)$(_PreBuiltTypeMapPackSubDir)\</_PreBuiltTypeMapOutputDir> | ||
| <!-- These DLLs are SDK runtime inputs consumed explicitly by the Android targets, not | ||
| compile-time references. NuGet otherwise warns that assemblies under data/ are outside | ||
| lib/, and this repository treats pack warnings as errors. --> | ||
| <NoWarn>$(NoWarn);NU5100</NoWarn> | ||
| <!-- Intermediate (not packaged): generated JCW .java and compiled .class files. --> | ||
| <_PreBuiltTypeMapIntDir>$([MSBuild]::NormalizeDirectory('$(MSBuildProjectDirectory)', 'obj', 'prebuilt-typemap'))</_PreBuiltTypeMapIntDir> | ||
| <_PreBuiltTypeMapJavaDir>$(_PreBuiltTypeMapIntDir)java\</_PreBuiltTypeMapJavaDir> | ||
| <_PreBuiltTypeMapAssembly>$(_PreBuiltTypeMapOutputDir)_Mono.Android.TypeMap.dll</_PreBuiltTypeMapAssembly> | ||
| <_PreBuiltTypeMapJavaInteropAssembly>$(_PreBuiltTypeMapOutputDir)_Java.Interop.TypeMap.dll</_PreBuiltTypeMapJavaInteropAssembly> | ||
| <_PreBuiltTypeMapAcwMap>$(_PreBuiltTypeMapOutputDir)mono.android-acw-map.txt</_PreBuiltTypeMapAcwMap> | ||
| <_PreBuiltTypeMapJavaFilesList>$(_PreBuiltTypeMapIntDir)java-files.txt</_PreBuiltTypeMapJavaFilesList> | ||
| <_PreBuiltTypeMapGenerationStamp>$(_PreBuiltTypeMapIntDir)_GeneratePreBuiltMonoAndroidTypeMap.stamp</_PreBuiltTypeMapGenerationStamp> | ||
| </PropertyGroup> | ||
|
|
||
| <!-- Generated files use content-based writes and can legitimately be older than the generator | ||
| inputs. Use a stamp for timestamp incrementality, but invalidate it whenever any real output | ||
| recorded by the previous generation pass is missing. --> | ||
| <Target Name="_InvalidatePreBuiltMonoAndroidTypeMapStampIfOutputsMissing"> | ||
| <ItemGroup> | ||
| <_ExpectedPreBuiltTypeMapJavaFile Remove="@(_ExpectedPreBuiltTypeMapJavaFile)" /> | ||
| <_ActualPreBuiltTypeMapJavaFile Remove="@(_ActualPreBuiltTypeMapJavaFile)" /> | ||
| <_MissingPreBuiltTypeMapJavaFile Remove="@(_MissingPreBuiltTypeMapJavaFile)" /> | ||
| <_UnexpectedPreBuiltTypeMapJavaFile Remove="@(_UnexpectedPreBuiltTypeMapJavaFile)" /> | ||
| </ItemGroup> | ||
| <ReadLinesFromFile | ||
| File="$(_PreBuiltTypeMapJavaFilesList)" | ||
| Condition="Exists('$(_PreBuiltTypeMapJavaFilesList)')"> | ||
| <Output TaskParameter="Lines" ItemName="_ExpectedPreBuiltTypeMapJavaFile" /> | ||
| </ReadLinesFromFile> | ||
| <ItemGroup> | ||
| <_ActualPreBuiltTypeMapJavaFile Include="$(_PreBuiltTypeMapJavaDir)**\*.java" /> | ||
| <_MissingPreBuiltTypeMapJavaFile Include="@(_ExpectedPreBuiltTypeMapJavaFile)" | ||
| Condition="!Exists('%(_ExpectedPreBuiltTypeMapJavaFile.Identity)')" /> | ||
| <_UnexpectedPreBuiltTypeMapJavaFile Include="@(_ActualPreBuiltTypeMapJavaFile->'%(FullPath)')" | ||
| Exclude="@(_ExpectedPreBuiltTypeMapJavaFile)" /> | ||
| </ItemGroup> | ||
| <Delete | ||
| Files="$(_PreBuiltTypeMapGenerationStamp)" | ||
| Condition="Exists('$(_PreBuiltTypeMapGenerationStamp)') and (!Exists('$(_PreBuiltTypeMapAssembly)') or !Exists('$(_PreBuiltTypeMapJavaInteropAssembly)') or !Exists('$(_PreBuiltTypeMapAcwMap)') or !Exists('$(_PreBuiltTypeMapJavaFilesList)') or '@(_MissingPreBuiltTypeMapJavaFile->Count())' != '0' or '@(_UnexpectedPreBuiltTypeMapJavaFile->Count())' != '0')" /> | ||
| <ItemGroup> | ||
| <_ExpectedPreBuiltTypeMapJavaFile Remove="@(_ExpectedPreBuiltTypeMapJavaFile)" /> | ||
| <_ActualPreBuiltTypeMapJavaFile Remove="@(_ActualPreBuiltTypeMapJavaFile)" /> | ||
| <_MissingPreBuiltTypeMapJavaFile Remove="@(_MissingPreBuiltTypeMapJavaFile)" /> | ||
| <_UnexpectedPreBuiltTypeMapJavaFile Remove="@(_UnexpectedPreBuiltTypeMapJavaFile)" /> | ||
| </ItemGroup> | ||
| </Target> | ||
|
|
||
| <Target Name="_GeneratePreBuiltMonoAndroidTypeMap" | ||
| BeforeTargets="ConfigureLocalWorkload;_GenerateXASdkContent" | ||
| DependsOnTargets="_InvalidatePreBuiltMonoAndroidTypeMapStampIfOutputsMissing" | ||
| Inputs="$(_MonoAndroidNETDefaultOutDir)Mono.Android.dll;$(_MonoAndroidNETDefaultOutDir)Java.Interop.dll;$(MicrosoftAndroidSdkOutDir)Xamarin.Android.Build.Tasks.dll" | ||
| Outputs="$(_PreBuiltTypeMapGenerationStamp)"> | ||
| <ItemGroup> | ||
| <!-- Scan Mono.Android and Java.Interop TOGETHER so their cross-assembly aliases (e.g. | ||
| java/lang/Object mapped by both Java.Lang.Object and Java.Interop.JavaObject) are | ||
| coordinated into a single primary + aliases, instead of colliding as duplicate keys in | ||
| the merged Java.Lang.Object universe at runtime. --> | ||
| <_PreBuiltTypeMapInput Include="$(_MonoAndroidNETDefaultOutDir)Mono.Android.dll" /> | ||
| <_PreBuiltTypeMapInput Include="$(_MonoAndroidNETDefaultOutDir)Java.Interop.dll" /> | ||
| <!-- Reference-only framework assemblies needed to resolve base types. | ||
| These are NOT scanned for peers; only @(_PreBuiltTypeMapInput) is. --> | ||
| <_PreBuiltTypeMapFramework Include="$(_MonoAndroidNETDefaultOutDir)*.dll" | ||
| Exclude="@(_PreBuiltTypeMapInput)" /> | ||
| </ItemGroup> | ||
| <MakeDir Directories="$(_PreBuiltTypeMapOutputDir);$(_PreBuiltTypeMapJavaDir)" /> | ||
| <GenerateTrimmableTypeMap | ||
| ResolvedAssemblies="@(_PreBuiltTypeMapInput)" | ||
| ResolvedFrameworkAssemblies="@(_PreBuiltTypeMapFramework)" | ||
| FrameworkAssemblyNames="@(_PreBuiltTypeMapFramework->'%(Filename)')" | ||
| OutputDirectory="$(_PreBuiltTypeMapOutputDir)" | ||
| JavaSourceOutputDirectory="$(_PreBuiltTypeMapJavaDir)" | ||
| AcwMapOutputFile="$(_PreBuiltTypeMapAcwMap)" | ||
| TargetFrameworkVersion="v$(DotNetTargetFrameworkVersion)" | ||
| ForceSharedTypemapUniverse="true" | ||
| GenerateRootAssembly="false"> | ||
| <Output TaskParameter="GeneratedJavaFiles" ItemName="_GeneratedPreBuiltTypeMapJavaFile" /> | ||
| </GenerateTrimmableTypeMap> | ||
| <WriteLinesToFile | ||
| File="$(_PreBuiltTypeMapJavaFilesList)" | ||
| Lines="@(_GeneratedPreBuiltTypeMapJavaFile->'%(FullPath)')" | ||
| Overwrite="true" | ||
| WriteOnlyWhenDifferent="true" /> | ||
| <Touch Files="$(_PreBuiltTypeMapGenerationStamp)" AlwaysCreate="true" /> | ||
| <ItemGroup> | ||
| <FileWrites Include="@(_GeneratedPreBuiltTypeMapJavaFile)" /> | ||
| <FileWrites Include="$(_PreBuiltTypeMapJavaFilesList)" /> | ||
| <FileWrites Include="$(_PreBuiltTypeMapGenerationStamp)" /> | ||
| </ItemGroup> | ||
| </Target> | ||
|
|
||
| <PropertyGroup> | ||
| <_PreBuiltTypeMapJcwJar>$(_PreBuiltTypeMapOutputDir)mono.android-typemaps.jar</_PreBuiltTypeMapJcwJar> | ||
| <_PreBuiltTypeMapJcwClassesDir>$(_PreBuiltTypeMapIntDir)jcw-classes\</_PreBuiltTypeMapJcwClassesDir> | ||
| <_PreBuiltTypeMapJcwSourceList>$(_PreBuiltTypeMapIntDir)jcw-sources.txt</_PreBuiltTypeMapJcwSourceList> | ||
| <_PreBuiltTypeMapAndroidJar>$(AndroidSdkDirectory)\platforms\android-$(AndroidPlatformId)\android.jar</_PreBuiltTypeMapAndroidJar> | ||
| <_PreBuiltTypeMapMonoAndroidJar>$(_MonoAndroidNETDefaultOutDir)mono.android.jar</_PreBuiltTypeMapMonoAndroidJar> | ||
| <_PreBuiltTypeMapRuntimeJar>$(MicrosoftAndroidSdkOutDir)java_runtime.jar</_PreBuiltTypeMapRuntimeJar> | ||
| </PropertyGroup> | ||
|
|
||
| <!-- Compile the generated Java Callable Wrappers into a jar shipped in the SDK pack. These | ||
| wrappers use the trimmable runtime registration path and cannot be replaced by the legacy | ||
| wrappers from mono.android.jar, which call TypeManager.n_activate. --> | ||
| <Target Name="_CompilePreBuiltMonoAndroidTypeMapJcwJarInputs" | ||
| DependsOnTargets="_GeneratePreBuiltMonoAndroidTypeMap"> | ||
| <ItemGroup> | ||
| <_PreBuiltTypeMapJavaFile Remove="@(_PreBuiltTypeMapJavaFile)" /> | ||
| </ItemGroup> | ||
| <ReadLinesFromFile File="$(_PreBuiltTypeMapJavaFilesList)"> | ||
| <Output TaskParameter="Lines" ItemName="_PreBuiltTypeMapJavaFile" /> | ||
| </ReadLinesFromFile> | ||
| </Target> | ||
|
|
||
| <Target Name="_CompilePreBuiltMonoAndroidTypeMapJcwJar" | ||
| BeforeTargets="ConfigureLocalWorkload;_GenerateXASdkContent" | ||
| DependsOnTargets="_CompilePreBuiltMonoAndroidTypeMapJcwJarInputs" | ||
| Inputs="$(_PreBuiltTypeMapGenerationStamp);$(_PreBuiltTypeMapJavaFilesList);@(_PreBuiltTypeMapJavaFile);$(_PreBuiltTypeMapAndroidJar);$(_PreBuiltTypeMapMonoAndroidJar);$(_PreBuiltTypeMapRuntimeJar)" | ||
| Outputs="$(_PreBuiltTypeMapJcwJar)"> | ||
| <RemoveDir Directories="$(_PreBuiltTypeMapJcwClassesDir)" /> | ||
| <MakeDir Directories="$(_PreBuiltTypeMapJcwClassesDir)" /> | ||
| <WriteLinesToFile File="$(_PreBuiltTypeMapJcwSourceList)" Lines="@(_PreBuiltTypeMapJavaFile)" Overwrite="true" /> | ||
| <Exec Command=""$(JavaCPath)" -source $(JavacSourceVersion) -target $(JavacTargetVersion) -nowarn -d "$(_PreBuiltTypeMapJcwClassesDir.TrimEnd('\'))" -classpath "$(_PreBuiltTypeMapAndroidJar)"$(PathSeparator)"$(_PreBuiltTypeMapMonoAndroidJar)"$(PathSeparator)"$(_PreBuiltTypeMapRuntimeJar)" @"$(_PreBuiltTypeMapJcwSourceList)"" /> | ||
| <Exec Command=""$(JarPath)" cf "$(_PreBuiltTypeMapJcwJar)" -C "$(_PreBuiltTypeMapJcwClassesDir.TrimEnd('\'))" ." /> | ||
| </Target> | ||
|
|
||
| <Target Name="_AddPreBuiltMonoAndroidTypeMapToPackage" | ||
| BeforeTargets="_GenerateXASdkContent" | ||
| DependsOnTargets="_GeneratePreBuiltMonoAndroidTypeMap;_CompilePreBuiltMonoAndroidTypeMapJcwJar"> | ||
| <ItemGroup> | ||
| <_PreBuiltTypeMapAllAssemblies Include="$(_PreBuiltTypeMapOutputDir)*.TypeMap.dll" /> | ||
| <FilesToPackage Include="@(_PreBuiltTypeMapAllAssemblies)" TargetPath="$(_PreBuiltTypeMapPackSubDir)" /> | ||
| <FilesToPackage Include="$(_PreBuiltTypeMapJcwJar)" TargetPath="$(_PreBuiltTypeMapPackSubDir)" /> | ||
| <FilesToPackage Include="$(_PreBuiltTypeMapAcwMap)" TargetPath="$(_PreBuiltTypeMapPackSubDir)" /> | ||
| </ItemGroup> | ||
| </Target> | ||
|
|
||
| </Project> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤖⚠️ MSBuild targets — These absolute Java source paths are written to the
javacresponse file without quoting. If the repository or intermediate path contains a space,javactokenizes one source path as multiple arguments and the SDK pack build fails even though the@response-filepath itself is quoted on the next line. Please quote and escape each response-file entry when writing the list.Rule: Paths with spaces must be handled correctly