Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
d865766
[marshal methods] Move marshal method classification and rewriting to…
sbomer Apr 3, 2026
096e4ae
[marshal methods] Consolidate .ll generation into the inner build
sbomer Apr 3, 2026
e92f56e
[marshal methods] Write rewritten assemblies to separate output direc…
sbomer Apr 9, 2026
8857691
[marshal methods] Skip NativeAOT builds and fix PDB output items
sbomer Apr 13, 2026
853fdaf
Fix resource leak and missing lookup info in RewriteMarshalMethods
sbomer Apr 14, 2026
5c4ad1f
Generate ApplicationRegistration.java in inner build when marshal met…
sbomer Apr 14, 2026
28ebcaf
Retry CI
sbomer Apr 15, 2026
5f0e4cb
Merge branch 'main' into dev/sbomer/rewrite-marshal-methods-v2
sbomer Apr 16, 2026
5a116d4
Fix test failures for per-RID marshal method rewriting
sbomer Apr 16, 2026
2dd29df
Merge branch 'main' into dev/sbomer/rewrite-marshal-methods-v2
sbomer Apr 22, 2026
55ba3a2
Merge branch 'main' into dev/sbomer/rewrite-marshal-methods-v2
sbomer Apr 27, 2026
b2d1bde
Remove marshal method classification from outer build
sbomer Apr 27, 2026
3f278de
Move _RewriteMarshalMethodsInner to Common.targets for all typemap paths
sbomer Apr 28, 2026
be65be9
Merge remote-tracking branch 'origin/main' into marshal-methods-v2
sbomer Apr 29, 2026
469456f
Remove test scripts and pr-message from tracked files
sbomer Apr 29, 2026
e5d6f9b
Merge remote-tracking branch 'origin/main' into marshal-methods-v2
sbomer May 7, 2026
b54a50f
Merge remote-tracking branch 'origin/main' into marshal-methods-v2
sbomer May 12, 2026
087190e
Merge remote-tracking branch 'origin/main' into marshal-methods-v2
sbomer May 14, 2026
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
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,6 @@
EnableNativeRuntimeLinking="$(_AndroidEnableNativeRuntimeLinking)">
</GenerateJavaStubs>

<RewriteMarshalMethods
Condition=" '$(_AndroidUseMarshalMethods)' == 'true' And '$(AndroidIncludeDebugSymbols)' == 'false' "
EnableManagedMarshalMethodsLookup="$(_AndroidUseManagedMarshalMethodsLookup)"
Environments="@(_EnvironmentFiles)"
IntermediateOutputDirectory="$(IntermediateOutputPath)">
</RewriteMarshalMethods>

<GenerateTypeMappings
AndroidRuntime="$(_AndroidRuntime)"
Debug="$(AndroidIncludeDebugSymbols)"
Expand Down Expand Up @@ -250,6 +243,44 @@
Deterministic="$(Deterministic)" />
</Target>

<!--
Inner-build marshal method handling. Always runs (for every RID) to generate
the marshal_methods.<abi>.ll LLVM IR file.

When marshal methods are enabled (Release + PublishTrimmed), the task also
classifies marshal methods, rewrites assemblies (adds [UnmanagedCallersOnly]
wrappers, removes connectors), and generates a full .ll with marshal method
native functions.

When marshal methods are disabled (Debug, or Release without marshal methods),
the task generates an empty/minimal .ll containing only the structural
scaffolding the native runtime always links against.

Runs AfterTargets="_PostTrimmingPipeline" which is itself AfterTargets="ILLink".
MSBuild fires AfterTargets hooks even when the referenced target is
condition-skipped, so this target runs in both trimmed and untrimmed builds.
When trimming IS active, _PostTrimmingPipeline completes first, ensuring
assemblies are trimmed before any rewrite. Runs before ReadyToRun/crossgen2
so that R2R images are generated from the rewritten assemblies.

The .ll file is written to $(_OuterIntermediateOutputPath)android/ so the
outer build's _CompileNativeAssemblySources can compile it.
-->
<Target Name="_RewriteMarshalMethodsInner"
AfterTargets="_PostTrimmingPipeline">
<ItemGroup>
<_MarshalMethodsAssembly Include="@(ResolvedFileToPublish)" Condition=" '%(Extension)' == '.dll' " />
</ItemGroup>
<RewriteMarshalMethods
Assemblies="@(_MarshalMethodsAssembly)"
EnableManagedMarshalMethodsLookup="$(_AndroidUseManagedMarshalMethodsLookup)"
EnableMarshalMethods="$(_AndroidUseMarshalMethods)"
Environments="@(_EnvironmentFiles)"
MarshalMethodsOutputDirectory="$(_OuterIntermediateOutputPath)android"
AndroidRuntime="$(_AndroidRuntime)"
RuntimeIdentifier="$(RuntimeIdentifier)" />
</Target>

<!-- Inject _TypeMapKind into the property cache -->
<Target Name="_SetTypemapProperties"
BeforeTargets="_CreatePropertiesCache">
Expand Down
10 changes: 4 additions & 6 deletions src/Xamarin.Android.Build.Tasks/Tasks/GenerateJavaStubs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,10 @@ internal static Dictionary<string, ITaskItem> MaybeGetArchAssemblies (Dictionary
return (false, null);
}

MarshalMethodsCollection? marshalMethodsCollection = null;

if (useMarshalMethods)
marshalMethodsCollection = MarshalMethodsCollection.FromAssemblies (arch, assemblies.Values.ToList (), resolver, Log);

return (true, new NativeCodeGenState (arch, tdCache, resolver, allJavaTypes, javaTypesForJCW, marshalMethodsCollection));
// Marshal method classification is now done in the inner build by
// RewriteMarshalMethods, so we never classify here. The NativeCodeGenState
// will have a null Classifier; downstream tasks must handle that.
return (true, new NativeCodeGenState (arch, tdCache, resolver, allJavaTypes, javaTypesForJCW, classifier: null));
}

(List<TypeDefinition> allJavaTypes, List<TypeDefinition> javaTypesForJCW) ScanForJavaTypes (XAAssemblyResolver res, TypeDefinitionCache cache, Dictionary<string, ITaskItem> assemblies, Dictionary<string, ITaskItem> userAssemblies, bool useMarshalMethods)
Expand Down
Loading
Loading