Skip to content

Commit

Permalink
Prepare for PR
Browse files Browse the repository at this point in the history
Disable all marshal methods code by default, we don't want it in
`main` yet
  • Loading branch information
grendello committed May 16, 2022
1 parent ba47852 commit 890fc04
Show file tree
Hide file tree
Showing 21 changed files with 57 additions and 386 deletions.
4 changes: 0 additions & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,3 @@
path = external/xamarin-android-tools
url = https://github.com/xamarin/xamarin-android-tools
branch = main
[submodule "external/magic_enum"]
path = external/magic_enum
url = https://github.com/Neargye/magic_enum.git
branch = master
4 changes: 4 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
<RollForward>Major</RollForward>
</PropertyGroup>

<PropertyGroup Condition=" '$(MSBuildRuntimeType)' == 'Core' ">
<_EnableMarshalMethods>NoThanks</_EnableMarshalMethods> <!-- set to YesPlease to enable -->
</PropertyGroup>

<PropertyGroup>
<ProductVersion>12.3.99</ProductVersion>
<!-- NuGet package version numbers. See Documentation/guides/OneDotNet.md.
Expand Down
61 changes: 0 additions & 61 deletions Java.Interop.diff

This file was deleted.

6 changes: 0 additions & 6 deletions Xamarin.Android.sln
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "relnote-gen", "tools\relnote-gen\relnote-gen.csproj", "{D8E14B43-E929-4C18-9FA6-2C3DC47EFC17}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Java.Runtime.Environment", "external\Java.Interop\src\Java.Runtime.Environment\Java.Runtime.Environment.csproj", "{C0E44558-FEE3-4DD3-986A-3F46DD1BF41B}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "mgen", "tools\mgen\mgen.csproj", "{1771A814-349B-4B0C-918D-0A989E78CB73}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
Expand Down Expand Up @@ -433,10 +432,6 @@ Global
{C0E44558-FEE3-4DD3-986A-3F46DD1BF41B}.Debug|AnyCPU.Build.0 = Debug|Any CPU
{C0E44558-FEE3-4DD3-986A-3F46DD1BF41B}.Release|AnyCPU.ActiveCfg = Release|Any CPU
{C0E44558-FEE3-4DD3-986A-3F46DD1BF41B}.Release|AnyCPU.Build.0 = Release|Any CPU
{1771A814-349B-4B0C-918D-0A989E78CB73}.Debug|AnyCPU.ActiveCfg = Debug|Any CPU
{1771A814-349B-4B0C-918D-0A989E78CB73}.Debug|AnyCPU.Build.0 = Debug|Any CPU
{1771A814-349B-4B0C-918D-0A989E78CB73}.Release|AnyCPU.ActiveCfg = Release|Any CPU
{1771A814-349B-4B0C-918D-0A989E78CB73}.Release|AnyCPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -508,7 +503,6 @@ Global
{4EFCED6E-9A6B-453A-94E4-CE4B736EC684} = {864062D3-A415-4A6F-9324-5820237BA058}
{D8E14B43-E929-4C18-9FA6-2C3DC47EFC17} = {864062D3-A415-4A6F-9324-5820237BA058}
{C0E44558-FEE3-4DD3-986A-3F46DD1BF41B} = {04E3E11E-B47D-4599-8AFC-50515A95E715}
{1771A814-349B-4B0C-918D-0A989E78CB73} = {864062D3-A415-4A6F-9324-5820237BA058}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {53A1F287-EFB2-4D97-A4BB-4A5E145613F6}
Expand Down
2 changes: 1 addition & 1 deletion external/Java.Interop
1 change: 0 additions & 1 deletion external/magic_enum
Submodule magic_enum deleted from ab2bf8
13 changes: 9 additions & 4 deletions src/Xamarin.Android.Build.Tasks/Tasks/GenerateJavaStubs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,9 @@ bool CreateJavaSources (IEnumerable<TypeDefinition> javaTypes, TypeDefinitionCac
string monoInit = GetMonoInitSource (AndroidSdkPlatform);
bool hasExportReference = ResolvedAssemblies.Any (assembly => Path.GetFileName (assembly.ItemSpec) == "Mono.Android.Export.dll");
bool generateOnCreateOverrides = int.Parse (AndroidSdkPlatform) <= 10;
var overriddenMethods = new List<string> ();
#if ENABLE_MARSHAL_METHODS
var overriddenMethodDescriptors = new List<OverriddenMethodDescriptor> ();
#endif

bool ok = true;
foreach (var t in javaTypes) {
Expand All @@ -358,7 +360,9 @@ bool CreateJavaSources (IEnumerable<TypeDefinition> javaTypes, TypeDefinitionCac
};

jti.Generate (writer);
overriddenMethods.AddRange (jti.OverriddenMethods);
#if ENABLE_MARSHAL_METHODS
overriddenMethodDescriptors.AddRange (jti.OverriddenMethodDescriptors);
#endif
writer.Flush ();

var path = jti.GetDestinationPath (outputPath);
Expand Down Expand Up @@ -392,8 +396,9 @@ bool CreateJavaSources (IEnumerable<TypeDefinition> javaTypes, TypeDefinitionCac
}
}
}

BuildEngine4.RegisterTaskObjectAssemblyLocal (MarshalMethodsRegisterTaskKey, overriddenMethods, RegisteredTaskObjectLifetime.Build);
#if ENABLE_MARSHAL_METHODS
BuildEngine4.RegisterTaskObjectAssemblyLocal (MarshalMethodsRegisterTaskKey, overriddenMethodDescriptors, RegisteredTaskObjectLifetime.Build);
#endif
return ok;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,15 +299,16 @@ void AddEnvironment ()

int assemblyCount = 0;
HashSet<string> archAssemblyNames = null;
#if ENABLE_MARSHAL_METHODS
var uniqueAssemblyNames = new HashSet<string> (StringComparer.OrdinalIgnoreCase);

#endif
Action<ITaskItem> updateAssemblyCount = (ITaskItem assembly) => {
string assemblyName = Path.GetFileName (assembly.ItemSpec);
#if ENABLE_MARSHAL_METHODS
if (!uniqueAssemblyNames.Contains (assemblyName)) {
uniqueAssemblyNames.Add (assemblyName);
}
#endif
if (!UseAssemblyStore) {
assemblyCount++;
return;
Expand Down Expand Up @@ -437,14 +438,14 @@ void AddEnvironment ()
JNIEnvRegisterJniNativesToken = jnienv_registerjninatives_method_token,
};
appConfigAsmGen.Init ();

#if ENABLE_MARSHAL_METHODS
var marshalMethodsAsmGen = new MarshalMethodsNativeAssemblyGenerator () {
NumberOfAssembliesInApk = assemblyCount,
UniqueAssemblyNames = uniqueAssemblyNames,
OverriddenMethods = BuildEngine4.GetRegisteredTaskObjectAssemblyLocal<List<string>> (GenerateJavaStubs.MarshalMethodsRegisterTaskKey, RegisteredTaskObjectLifetime.Build)
OverriddenMethodDescriptors = BuildEngine4.GetRegisteredTaskObjectAssemblyLocal<List<Java.Interop.Tools.JavaCallableWrappers.OverriddenMethodDescriptor>> (GenerateJavaStubs.MarshalMethodsRegisterTaskKey, RegisteredTaskObjectLifetime.Build)
};
marshalMethodsAsmGen.Init ();

#endif
foreach (string abi in SupportedAbis) {
string targetAbi = abi.ToLowerInvariant ();
string environmentBaseAsmFilePath = Path.Combine (EnvironmentOutputDirectory, $"environment.{targetAbi}");
Expand All @@ -458,12 +459,13 @@ void AddEnvironment ()
sw.Flush ();
Files.CopyIfStreamChanged (sw.BaseStream, environmentLlFilePath);
}

#if ENABLE_MARSHAL_METHODS
using (var sw = MemoryStreamPool.Shared.CreateStreamWriter ()) {
marshalMethodsAsmGen.Write (targetArch, sw, marshalMethodsLlFilePath);
sw.Flush ();
Files.CopyIfStreamChanged (sw.BaseStream, marshalMethodsLlFilePath);
}
#endif
}

void AddEnvironmentVariable (string name, string value)
Expand Down
5 changes: 4 additions & 1 deletion src/Xamarin.Android.Build.Tasks/Tasks/PrepareAbiItems.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ public class PrepareAbiItems : AndroidTask
const string TypeMapBase = "typemaps";
const string EnvBase = "environment";
const string CompressedAssembliesBase = "compressed_assemblies";
#if ENABLE_MARSHAL_METHODS
const string MarshalMethodsBase = "marshal_methods";

#endif
public override string TaskPrefix => "PAI";

[Required]
Expand Down Expand Up @@ -51,8 +52,10 @@ public override bool RunTask ()
baseName = EnvBase;
} else if (String.Compare ("compressed", Mode, StringComparison.OrdinalIgnoreCase) == 0) {
baseName = CompressedAssembliesBase;
#if ENABLE_MARSHAL_METHODS
} else if (String.Compare ("marshal_methods", Mode, StringComparison.OrdinalIgnoreCase) == 0) {
baseName = MarshalMethodsBase;
#endif
} else {
Log.LogError ($"Unknown mode: {Mode}");
return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#if ENABLE_MARSHAL_METHODS
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

using Java.Interop.Tools.TypeNameMappings;
using Java.Interop.Tools.JavaCallableWrappers;

using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;

Expand All @@ -28,20 +31,13 @@ struct MarshalMethodsManagedClass

public ICollection<string> UniqueAssemblyNames { get; set; }
public int NumberOfAssembliesInApk { get; set; }
public List<string> OverriddenMethods { get; set; }
public List<OverriddenMethodDescriptor> OverriddenMethodDescriptors { get; set; }

StructureInfo<TypeMappingReleaseNativeAssemblyGenerator.MonoImage> monoImage;
StructureInfo<MonoClass> monoClass;

public override void Init ()
{
if (OverriddenMethods != null) {
Console.WriteLine ("Overridden methods:");
foreach (string om in OverriddenMethods) {
Console.WriteLine ($" {om}");
}
}
}
{}

protected override void MapStructures (LlvmIrGenerator generator)
{
Expand Down Expand Up @@ -115,3 +111,4 @@ void WriteHashes<T> () where T: struct
}
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
<NoWarn>$(NoWarn);CA1310</NoWarn>
</PropertyGroup>

<PropertyGroup Condition=" '$(_EnableMarshalMethods)' == 'YesPlease' ">
<DefineConstants>$(DefineConstants);ENABLE_MARSHAL_METHODS</DefineConstants>
</PropertyGroup>

<ItemGroup>
<Reference Include="pdb2mdb.exe">
<HintPath>..\..\bin\$(Configuration)\lib\xamarin.android\xbuild\Xamarin\Android\pdb2mdb.exe</HintPath>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1542,6 +1542,7 @@ because xbuild doesn't support framework reference assemblies.
<Output TaskParameter="AssemblySources" ItemName="_CompressedAssembliesAssemblySource" />
</PrepareAbiItems>
<PrepareAbiItems
Condition=" '$(_EnableMarshalMethods)' == 'YesPlease' "
BuildTargetAbis="@(_BuildTargetAbis)"
NativeSourcesDir="$(_NativeAssemblySourceDir)"
InstantRunEnabled="$(_InstantRunEnabled)"
Expand Down
21 changes: 15 additions & 6 deletions src/monodroid/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ option(STRIP_DEBUG "Strip debugging information when linking" ${STRIP_DEBUG_DEFA
option(DISABLE_DEBUG "Disable the built-in debugging code" OFF)
option(USE_CCACHE "Use ccache, if found, to speed up recompilation" ${CCACHE_OPTION_DEFAULT})

set(ENABLE_MARSHAL_METHODS True)

if((MINGW OR NOT WIN32) AND USE_CCACHE)
if(CMAKE_CXX_COMPILER MATCHES "/ccache/")
message(STATUS "ccache: compiler already uses ccache")
Expand Down Expand Up @@ -271,6 +273,9 @@ add_compile_definitions(HAVE_CONFIG_H)
add_compile_definitions(_REENTRANT)
add_compile_definitions(JI_DLL_EXPORT)
add_compile_definitions(MONO_DLL_EXPORT)
if(ENABLE_MARSHAL_METHODS)
add_compile_definitions(ENABLE_MARSHAL_METHODS)
endif()

if(ENABLE_NET6)
add_compile_definitions(NET6)
Expand Down Expand Up @@ -468,7 +473,9 @@ endif()
set(XAMARIN_INTERNAL_API_LIB xa-internal-api${CHECKED_BUILD_INFIX})
set(XAMARIN_DEBUG_APP_HELPER_LIB xamarin-debug-app-helper${CHECKED_BUILD_INFIX})
set(XAMARIN_APP_STUB_LIB xamarin-app)
set(XAMARIN_APP_MARSHALING_LIB xamarin-app-marshaling)
if(ENABLE_MARSHAL_METHODS)
set(XAMARIN_APP_MARSHALING_LIB xamarin-app-marshaling)
endif()

string(TOLOWER ${CMAKE_BUILD_TYPE} XAMARIN_MONO_ANDROID_SUFFIX)
set(XAMARIN_MONO_ANDROID_LIB "mono-android${CHECKED_BUILD_INFIX}.${XAMARIN_MONO_ANDROID_SUFFIX}")
Expand Down Expand Up @@ -503,7 +510,7 @@ if(ANDROID)
${LZ4_SOURCES}
)

if(NOT DEBUG_BUILD AND ENABLE_NET6)
if(NOT DEBUG_BUILD AND ENABLE_NET6 AND ENABLE_MARSHAL_METHODS)
list(APPEND XAMARIN_MONODROID_SOURCES
${SOURCES_DIR}/xamarin-android-app-context.cc
)
Expand Down Expand Up @@ -565,9 +572,11 @@ set(XAMARIN_DEBUG_APP_HELPER_SOURCES
${SOURCES_DIR}/shared-constants.cc
)

set(XAMARIN_APP_MARSHALING_LIB_SOURCES
${SOURCES_DIR}/xamarin-app-marshaling.cc
if(ENABLE_MARSHAL_METHODS)
set(XAMARIN_APP_MARSHALING_LIB_SOURCES
${SOURCES_DIR}/xamarin-app-marshaling.cc
)
endif()

# Build
configure_file(jni/host-config.h.in ${CMAKE_CURRENT_BINARY_DIR}/include/host-config.h)
Expand Down Expand Up @@ -608,7 +617,7 @@ target_link_options(
)

if(ANDROID)
if(NOT DEBUG_BUILD AND ENABLE_NET6)
if(NOT DEBUG_BUILD AND ENABLE_NET6 AND ENABLE_MARSHAL_METHODS)
# The marshaling lib is used only when building for devices
add_library(
${XAMARIN_APP_MARSHALING_LIB}
Expand Down Expand Up @@ -730,7 +739,7 @@ target_link_libraries(
${LINK_LIBS} xamarin-app
)

if((NOT DEBUG_BUILD) AND ANDROID AND ENABLE_NET6)
if((NOT DEBUG_BUILD) AND ANDROID AND ENABLE_NET6 AND ENABLE_MARSHAL_METHODS)
target_link_libraries(
${XAMARIN_MONO_ANDROID_LIB}
${XAMARIN_APP_MARSHALING_LIB}
Expand Down
Loading

0 comments on commit 890fc04

Please sign in to comment.