Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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