-
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
Draft
simonrozsival
wants to merge
11
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.
Draft
Changes from 10 commits
Commits
Show all changes
11 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 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
There are no files selected for viewing
95 changes: 95 additions & 0 deletions
95
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,95 @@ | ||
| <!-- | ||
| 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 _Mono.Android.TypeMap.dll (and, later, the | ||
| Java Callable Wrapper jar) in the SDK pack. The typemap always anchors on Java.Lang.Object | ||
| (ForceSharedTypemapUniverse=true) so a single artifact serves both app-build universe modes: | ||
| merged (Release) and aggregate (Debug). The root _Microsoft.Android.TypeMaps assembly is NOT | ||
| generated here (GenerateRootAssembly=false) — the 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> | ||
| <!-- 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> | ||
| <_PreBuiltTypeMapAcwMap>$(_PreBuiltTypeMapOutputDir)mono.android-acw-map.txt</_PreBuiltTypeMapAcwMap> | ||
| </PropertyGroup> | ||
|
|
||
| <Target Name="_GeneratePreBuiltMonoAndroidTypeMap" | ||
| BeforeTargets="ConfigureLocalWorkload;_GenerateXASdkContent" | ||
| Inputs="$(_MonoAndroidNETDefaultOutDir)Mono.Android.dll;$(_MonoAndroidNETDefaultOutDir)Java.Interop.dll;$(MicrosoftAndroidSdkOutDir)Xamarin.Android.Build.Tasks.dll" | ||
| Outputs="$(_PreBuiltTypeMapAssembly)"> | ||
| <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" | ||
| MaxArrayRank="3" | ||
|
simonrozsival marked this conversation as resolved.
Outdated
|
||
| GenerateRootAssembly="false" /> | ||
| </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 pre-generated Java Callable Wrappers into a jar shipped in the pack. The app | ||
| build adds this jar to its dex inputs instead of re-generating and re-compiling the | ||
| Mono.Android JCWs. Classpath mirrors build-tools/scripts/JavaCallableWrappers.targets: | ||
| android.jar + mono.android.jar + java_runtime.jar. --> | ||
| <Target Name="_CompilePreBuiltMonoAndroidTypeMapJcwJar" | ||
| BeforeTargets="ConfigureLocalWorkload;_GenerateXASdkContent" | ||
| DependsOnTargets="_GeneratePreBuiltMonoAndroidTypeMap" | ||
| Inputs="$(_PreBuiltTypeMapAssembly)" | ||
| Outputs="$(_PreBuiltTypeMapJcwJar)"> | ||
| <ItemGroup> | ||
| <_PreBuiltTypeMapJavaFile Include="$(_PreBuiltTypeMapJavaDir)**\*.java" /> | ||
| </ItemGroup> | ||
| <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
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.
Uh oh!
There was an error while loading. Please reload this page.