Skip to content

Commit

Permalink
Build deps + application config for CLR
Browse files Browse the repository at this point in the history
  • Loading branch information
grendello committed Dec 3, 2024
1 parent 4f1aaf5 commit 13bbd93
Show file tree
Hide file tree
Showing 12 changed files with 534 additions and 39 deletions.
75 changes: 50 additions & 25 deletions src/Xamarin.Android.Build.Tasks/Tasks/GeneratePackageManagerJava.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ public class GeneratePackageManagerJava : AndroidTask
[Required]
public bool EnablePreloadAssembliesDefault { get; set; }

[Required]
public bool TargetsCLR { get; set; }

public bool EnableMarshalMethods { get; set; }
public string RuntimeConfigBinFilePath { get; set; }
public string BoundExceptionType { get; set; }
Expand Down Expand Up @@ -321,31 +324,53 @@ void AddEnvironment ()

bool haveRuntimeConfigBlob = !String.IsNullOrEmpty (RuntimeConfigBinFilePath) && File.Exists (RuntimeConfigBinFilePath);
var jniRemappingNativeCodeInfo = BuildEngine4.GetRegisteredTaskObjectAssemblyLocal<GenerateJniRemappingNativeCode.JniRemappingNativeCodeInfo> (ProjectSpecificTaskObjectKey (GenerateJniRemappingNativeCode.JniRemappingNativeCodeInfoKey), RegisteredTaskObjectLifetime.Build);
var appConfigAsmGen = new ApplicationConfigNativeAssemblyGenerator (environmentVariables, systemProperties, Log) {
UsesMonoAOT = usesMonoAOT,
UsesMonoLLVM = EnableLLVM,
UsesAssemblyPreload = environmentParser.UsesAssemblyPreload,
MonoAOTMode = aotMode.ToString ().ToLowerInvariant (),
AotEnableLazyLoad = AndroidAotEnableLazyLoad,
AndroidPackageName = AndroidPackageName,
BrokenExceptionTransitions = environmentParser.BrokenExceptionTransitions,
PackageNamingPolicy = pnp,
BoundExceptionType = boundExceptionType,
JniAddNativeMethodRegistrationAttributePresent = NativeCodeGenState.TemplateJniAddNativeMethodRegistrationAttributePresent,
HaveRuntimeConfigBlob = haveRuntimeConfigBlob,
NumberOfAssembliesInApk = assemblyCount,
BundledAssemblyNameWidth = assemblyNameWidth,
MonoComponents = (MonoComponent)monoComponents,
NativeLibraries = uniqueNativeLibraries,
HaveAssemblyStore = UseAssemblyStore,
AndroidRuntimeJNIEnvToken = android_runtime_jnienv_class_token,
JNIEnvInitializeToken = jnienv_initialize_method_token,
JNIEnvRegisterJniNativesToken = jnienv_registerjninatives_method_token,
JniRemappingReplacementTypeCount = jniRemappingNativeCodeInfo == null ? 0 : jniRemappingNativeCodeInfo.ReplacementTypeCount,
JniRemappingReplacementMethodIndexEntryCount = jniRemappingNativeCodeInfo == null ? 0 : jniRemappingNativeCodeInfo.ReplacementMethodIndexEntryCount,
MarshalMethodsEnabled = EnableMarshalMethods,
IgnoreSplitConfigs = ShouldIgnoreSplitConfigs (),
};
LLVMIR.LlvmIrComposer appConfigAsmGen;

if (TargetsCLR) {
appConfigAsmGen = new ApplicationConfigNativeAssemblyGeneratorCLR (environmentVariables, systemProperties, Log) {
UsesAssemblyPreload = environmentParser.UsesAssemblyPreload,
AndroidPackageName = AndroidPackageName,
PackageNamingPolicy = pnp,
JniAddNativeMethodRegistrationAttributePresent = NativeCodeGenState.TemplateJniAddNativeMethodRegistrationAttributePresent,
HaveRuntimeConfigBlob = haveRuntimeConfigBlob,
NumberOfAssembliesInApk = assemblyCount,
BundledAssemblyNameWidth = assemblyNameWidth,
NativeLibraries = uniqueNativeLibraries,
AndroidRuntimeJNIEnvToken = android_runtime_jnienv_class_token,
JNIEnvInitializeToken = jnienv_initialize_method_token,
JNIEnvRegisterJniNativesToken = jnienv_registerjninatives_method_token,
JniRemappingReplacementTypeCount = jniRemappingNativeCodeInfo == null ? 0 : jniRemappingNativeCodeInfo.ReplacementTypeCount,
JniRemappingReplacementMethodIndexEntryCount = jniRemappingNativeCodeInfo == null ? 0 : jniRemappingNativeCodeInfo.ReplacementMethodIndexEntryCount,
MarshalMethodsEnabled = EnableMarshalMethods,
IgnoreSplitConfigs = ShouldIgnoreSplitConfigs (),
};
} else {
appConfigAsmGen = new ApplicationConfigNativeAssemblyGenerator (environmentVariables, systemProperties, Log) {
UsesMonoAOT = usesMonoAOT,
UsesMonoLLVM = EnableLLVM,
UsesAssemblyPreload = environmentParser.UsesAssemblyPreload,
MonoAOTMode = aotMode.ToString ().ToLowerInvariant (),
AotEnableLazyLoad = AndroidAotEnableLazyLoad,
AndroidPackageName = AndroidPackageName,
BrokenExceptionTransitions = environmentParser.BrokenExceptionTransitions,
PackageNamingPolicy = pnp,
BoundExceptionType = boundExceptionType,
JniAddNativeMethodRegistrationAttributePresent = NativeCodeGenState.TemplateJniAddNativeMethodRegistrationAttributePresent,
HaveRuntimeConfigBlob = haveRuntimeConfigBlob,
NumberOfAssembliesInApk = assemblyCount,
BundledAssemblyNameWidth = assemblyNameWidth,
MonoComponents = (MonoComponent)monoComponents,
NativeLibraries = uniqueNativeLibraries,
HaveAssemblyStore = UseAssemblyStore,
AndroidRuntimeJNIEnvToken = android_runtime_jnienv_class_token,
JNIEnvInitializeToken = jnienv_initialize_method_token,
JNIEnvRegisterJniNativesToken = jnienv_registerjninatives_method_token,
JniRemappingReplacementTypeCount = jniRemappingNativeCodeInfo == null ? 0 : jniRemappingNativeCodeInfo.ReplacementTypeCount,
JniRemappingReplacementMethodIndexEntryCount = jniRemappingNativeCodeInfo == null ? 0 : jniRemappingNativeCodeInfo.ReplacementMethodIndexEntryCount,
MarshalMethodsEnabled = EnableMarshalMethods,
IgnoreSplitConfigs = ShouldIgnoreSplitConfigs (),
};
}
LLVMIR.LlvmIrModule appConfigModule = appConfigAsmGen.Construct ();

foreach (string abi in SupportedAbis) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ sealed class InputFiles
[Required]
public string AndroidBinUtilsDirectory { get; set; }

[Required]
public bool TargetsCLR { get; set; }

public int ZipAlignmentPages { get; set; } = AndroidZipAlign.DefaultZipAlignment64Bit;

public override System.Threading.Tasks.Task RunTaskAsync ()
Expand Down Expand Up @@ -123,11 +126,12 @@ IEnumerable<Config> GetLinkerConfigs ()
abis [abi] = GatherFilesForABI (item.ItemSpec, abi, ObjectFiles, runtimeNativeLibsDir, runtimeNativeLibStubsDir);
}

const string commonLinkerArgs =
string soname = TargetsCLR ? "libxamarin-app-clr.so" : "libxamarin-app.so";
string commonLinkerArgs =
"--shared " +
"--allow-shlib-undefined " +
"--export-dynamic " +
"-soname libxamarin-app.so " +
$"-soname {soname} " +
"-z relro " +
"-z noexecstack " +
"--enable-new-dtags " +
Expand Down
52 changes: 52 additions & 0 deletions src/Xamarin.Android.Build.Tasks/Utilities/ApplicationConfigCLR.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System;

namespace Xamarin.Android.Tasks;

// Declaration order of fields and their types must correspond *exactly* to that in
// src/native-clr/xamarin-app-stub/xamarin-app.hh ApplicationConfig structure
//
// Type mappings:
//
// C++ C#
// -----------|----------
// bool | bool
// uint8_t | byte
// int8_t | sbyte
// uint16_t | ushort
// int16_t | short
// uint32_t | uint
// int32_t | int
// uint64_t | ulong
// int64_t | long
// char* | string
//
// Names should be the same as in the above struct, but it's not a requirement
// (they will be used only to generate comments in the native code)
sealed class ApplicationConfigCLR
{
public bool uses_assembly_preload;
public bool jni_add_native_method_registration_attribute_present;
public bool have_runtime_config_blob;
public bool marshal_methods_enabled;
public bool ignore_split_configs;
public uint package_naming_policy;
public uint environment_variable_count;
public uint system_property_count;
public uint number_of_assemblies_in_apk;
public uint bundled_assembly_name_width;
public uint number_of_dso_cache_entries;
public uint number_of_aot_cache_entries;
public uint number_of_shared_libraries;

[NativeAssembler (NumberFormat = LLVMIR.LlvmIrVariableNumberFormat.Hexadecimal)]
public uint android_runtime_jnienv_class_token;

[NativeAssembler (NumberFormat = LLVMIR.LlvmIrVariableNumberFormat.Hexadecimal)]
public uint jnienv_initialize_method_token;

[NativeAssembler (NumberFormat = LLVMIR.LlvmIrVariableNumberFormat.Hexadecimal)]
public uint jnienv_registerjninatives_method_token;
public uint jni_remapping_replacement_type_count;
public uint jni_remapping_replacement_method_index_entry_count;
public string android_package_name = String.Empty;
}
Loading

0 comments on commit 13bbd93

Please sign in to comment.