Skip to content

[TrimmableTypeMap] MSBuild task + targets wiring + incremental builds #10800

@simonrozsival

Description

@simonrozsival

Part of #10789
Depends on: Generator sub-issue (PR2)

Overview

Wire the scanner and generators into the MSBuild pipeline: implement the GenerateTypeMapAssembly task and fill in the trimmable .targets stubs.

MSBuild Task (GenerateTypeMapAssembly)

Thin orchestrator extending AndroidTask:

Inputs:

  • [Required] ResolvedAssemblies (ITaskItem[]) — all resolved assemblies to scan
  • [Required] OutputDirectory (string) — output dir for generated assemblies
  • [Required] JavaSourceOutputDirectory (string) — output dir for JCW .java files
  • CustomViewMapFile (string) — custom view types from layout XML
  • ErrorOnCustomJavaObject (bool)

Outputs:

  • [Output] GeneratedAssemblies (ITaskItem[]) — per-assembly typemaps + root assembly
  • [Output] GeneratedJavaFiles (ITaskItem[]) — generated .java files
  • [Output] TypeMapEntryAssemblyName (string)
  • [Output] UpdatedResolvedAssemblies (ITaskItem[])

RunTask() flow:

  1. Scan assemblies → List<JavaPeerInfo> (per-assembly, with incremental caching)
  2. Load custom view map → mark matching types unconditional
  3. Generate per-assembly typemap assemblies (only for changed inputs)
  4. Generate root assembly (alias detection, cross-ref unconditional forcing)
  5. Generate JCW .java files for ACW types
  6. Set output properties

Targets Wiring

Microsoft.Android.Sdk.TypeMap.Trimmable.targets

  • UsingTask declaration for GenerateTypeMapAssembly (from Microsoft.Android.Build.TypeMap.dll)
  • Define _TypeMapAssemblyName = _Microsoft.Android.TypeMaps
  • RuntimeHostConfigurationOption for System.Runtime.InteropServices.TypeMappingEntryAssembly

Microsoft.Android.Sdk.TypeMap.Trimmable.CoreCLR.targets

  • _GeneratePerAssemblyTypeMaps target with per-assembly Inputs/Outputs for incrementality
  • _GenerateRootTypeMap target for root assembly generation
  • Adds generated assemblies to resolved assemblies list for ILLink with TrimmerRootAssembly metadata
  • Adds --typemap-entry-assembly:$(_TypeMapAssemblyName) to ILLink args
  • Override _PrepareNativeAssemblySources as empty (no native typemap)

Microsoft.Android.Sdk.TypeMap.Trimmable.NativeAOT.targets

  • Same generation targets
  • Adds assemblies to IlcReference, UnmanagedEntryPointsAssembly, and TrimmerRootAssembly

Incremental Build Support

Per-assembly typemap generation with MSBuild Inputs/Outputs:

<Target Name="_GeneratePerAssemblyTypeMaps"
        Inputs="@(_ResolvedUserMonoAndroidAssemblies)"
        Outputs="@(_ResolvedUserMonoAndroidAssemblies->'$(IntermediateOutputPath)typemaps/%(Filename).TypeMap.dll')">

Typical incremental build: only app assembly changed → rescan app, regenerate app's typemap + root assembly. Cost: <0.5s.

Tests

  • Task integration tests with MockBuildEngine
  • Full build with _AndroidTypeMapImplementation=trimmable succeeds
  • Artifact validation: no .o typemap objects, no legacy mono.android.jar copy
  • Incremental build: second build with no changes skips generation
  • Incremental build: app assembly change only regenerates app typemap

Metadata

Metadata

Assignees

Labels

Area: CoreCLRIssues that only occur when using CoreCLR.Area: NativeAOTIssues that only occur when using NativeAOT.needs-triageIssues that need to be assigned.trimmable-type-map

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions