diff --git a/.gitmodules b/.gitmodules index ab928cf6fbc..d7800cca83f 100644 --- a/.gitmodules +++ b/.gitmodules @@ -25,7 +25,7 @@ [submodule "external/mono"] path = external/mono url = https://github.com/mono/mono.git - branch = 2018-02 + branch = 2018-04 [submodule "external/mxe"] path = external/mxe url = https://github.com/xamarin/mxe.git diff --git a/Configuration.props b/Configuration.props index 80ce32d99bd..1d745dd75f4 100644 --- a/Configuration.props +++ b/Configuration.props @@ -65,8 +65,8 @@ $(MSBuildThisFileDirectory)external\Java.Interop $(MSBuildThisFileDirectory)external\llvm $(MSBuildThisFileDirectory)external\mono - 5.12.0 - 5.13.0 + 5.14.0 + 5.15.0 True $(MonoRequiredMinimumVersion).0 $(MSBuildThisFileDirectory)external\mono\external\linker diff --git a/build-tools/dependencies/dependencies.projitems b/build-tools/dependencies/dependencies.projitems index ab1ed36ad08..f4a2f60e7da 100644 --- a/build-tools/dependencies/dependencies.projitems +++ b/build-tools/dependencies/dependencies.projitems @@ -1,7 +1,7 @@ - <_DarwinMonoFramework>MonoFramework-MDK-5.12.0.210.macos10.xamarin.universal.pkg + <_DarwinMonoFramework>MonoFramework-MDK-5.14.0.141.macos10.xamarin.universal.pkg <_AptGetInstall>apt-get -f -u install @@ -59,7 +59,7 @@ $(MonoRequiredMaximumVersion) $(MonoRequiredDarwinMinimumVersion) $(MSBuildThisFileDirectory)..\scripts\mono-version - https://xamjenkinsartifact.azureedge.net/build-package-osx-mono/2018-02/177/9bbc930d620487446f537e729f018eb965523fcd/$(_DarwinMonoFramework) + https://xamjenkinsartifact.azureedge.net/build-package-osx-mono/2018-04/116/8ae8c52383b43892fb7a35dbf0992738bd52fa90/$(_DarwinMonoFramework) installer -pkg "$(AndroidToolchainCacheDirectory)\$(_DarwinMonoFramework)" -target / diff --git a/external/mono b/external/mono index 4fe3280bba1..f3a2216b65a 160000 --- a/external/mono +++ b/external/mono @@ -1 +1 @@ -Subproject commit 4fe3280bba14cb9e81e2480bfdc6d934bcbc5c3c +Subproject commit f3a2216b65aa881c40ee34763b8517296f9f8a63 diff --git a/src/Mono.Android/Test/Xamarin.Android.Net/HttpClientIntegrationTests.cs b/src/Mono.Android/Test/Xamarin.Android.Net/HttpClientIntegrationTests.cs index 830503800d7..54c89e5ae05 100644 --- a/src/Mono.Android/Test/Xamarin.Android.Net/HttpClientIntegrationTests.cs +++ b/src/Mono.Android/Test/Xamarin.Android.Net/HttpClientIntegrationTests.cs @@ -590,7 +590,7 @@ public void Send_Transfer_Encoding_Custom () client.SendAsync (request, HttpCompletionOption.ResponseHeadersRead).Wait (); Assert.Fail ("#1"); } catch (AggregateException e) { - Assert.AreEqual (typeof (ProtocolViolationException), e.InnerException.GetType (), "#2"); + Assert.AreEqual (typeof (InvalidOperationException), e.InnerException.GetType (), "#2"); } Assert.IsNull (failed, "#102"); } finally { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/MakeBundleNativeCodeExternal.cs b/src/Xamarin.Android.Build.Tasks/Tasks/MakeBundleNativeCodeExternal.cs index 916fc7f4ac6..698aeaab84c 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/MakeBundleNativeCodeExternal.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/MakeBundleNativeCodeExternal.cs @@ -39,6 +39,9 @@ public class MakeBundleNativeCodeExternal : Task public bool EmbedDebugSymbols { get; set; } public bool KeepTemp { get; set; } + [Required] + public string BundleApiPath { get; set; } + [Output] public ITaskItem [] OutputNativeLibraries { get; set; } @@ -113,6 +116,8 @@ bool DoExecute () clb.AppendSwitch ("--nomain"); clb.AppendSwitch ("--i18n none"); clb.AppendSwitch ("--bundled-header"); + clb.AppendSwitch ("--mono-api-struct-path"); + clb.AppendFileNameIfNotNull (BundleApiPath); clb.AppendSwitch ("--style"); clb.AppendSwitch ("linux"); clb.AppendSwitch ("-c"); @@ -157,22 +162,6 @@ bool DoExecute () return false; } - Log.LogDebugMessage ("[mkbundle] modifying mono_mkbundle_init"); - // make some changes in the mkbundle output so that it does not require libmonodroid.so - var mkbundleOutput = new StringBuilder (File.ReadAllText (Path.Combine (outpath, "temp.c"))); - - mkbundleOutput.Replace ("mono_jit_set_aot_mode", "mono_jit_set_aot_mode_ptr") - .Replace ("void mono_mkbundle_init ()", "void mono_mkbundle_init (void (register_bundled_assemblies_func)(const MonoBundledAssembly **), void (register_config_for_assembly_func)(const char *, const char *), void (mono_jit_set_aot_mode_func) (int mode))") - .Replace ("mono_register_config_for_assembly (\"", "register_config_for_assembly_func (\"") - .Replace ("install_dll_config_files (void)", "install_dll_config_files (void (register_config_for_assembly_func)(const char *, const char *))") - .Replace ("install_dll_config_files ()", "install_dll_config_files (register_config_for_assembly_func)") - .Replace ("mono_register_bundled_assemblies(", "register_bundled_assemblies_func(") - .Replace ("int nbundles;", "int nbundles;\n\n\tmono_jit_set_aot_mode_ptr = mono_jit_set_aot_mode_func;"); - - mkbundleOutput.Insert (0, "void (*mono_jit_set_aot_mode_ptr) (int mode);\n"); - - File.WriteAllText (Path.Combine (outpath, "temp.c"), mkbundleOutput.ToString ()); - // then compile temp.c into temp.o and ... clb = new CommandLineBuilder (); @@ -182,6 +171,10 @@ bool DoExecute () // defined even if we don't use them clb.AppendSwitch ($"-D__ANDROID_API__={level}"); + // This is necessary because of the injected code, which is reused between libmonodroid + // and the bundle + clb.AppendSwitch ("-DANDROID"); + clb.AppendSwitch ("-o"); clb.AppendFileNameIfNotNull (Path.Combine (outpath, "temp.o")); if (!string.IsNullOrWhiteSpace (IncludePath)) { diff --git a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.csproj b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.csproj index c2f04033f82..0427fceec87 100644 --- a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.csproj +++ b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.csproj @@ -341,6 +341,9 @@ Linker\Linker\AssemblyResolver.cs + + Linker\Linker\AssemblyUtilities.cs + Linker\Linker\I18nAssemblies.cs @@ -359,6 +362,9 @@ Linker\Linker\Pipeline.cs + + Linker\Linker\TypeNameParser.cs + Linker\Linker\TypePreserve.cs @@ -576,6 +582,10 @@ LayoutBinding.cs PreserveNewest + + mkbundle-api.h + PreserveNewest + diff --git a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets index da364b9e28f..b208480beb3 100755 --- a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets +++ b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets @@ -307,9 +307,8 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved. <_InstantRunEnabled Condition=" '$(_InstantRunEnabled)' == '' ">False <_AndroidBuildPropertiesCache>$(IntermediateOutputPath)build.props <_AndroidDesignTimeBuildPropertiesCache>$(_AndroidIntermediateDesignTimeBuildDirectory)build.props - False - + False @@ -2720,12 +2719,14 @@ because xbuild doesn't support framework reference assemblies. + ToolPath="$(_MonoAndroidToolsDirectory)" + BundleApiPath="$(MSBuildThisFileDirectory)\mkbundle-api.h"> diff --git a/src/mono-runtimes/mono-runtimes.projitems b/src/mono-runtimes/mono-runtimes.projitems index 8fbcdc9296b..52fae26212b 100644 --- a/src/mono-runtimes/mono-runtimes.projitems +++ b/src/mono-runtimes/mono-runtimes.projitems @@ -10,7 +10,7 @@ runtime's build --> - <_ArmeabiRuntimeConfigure Condition="$(AndroidSupportedTargetJitAbisForConditionalChecks.Contains (':armeabi:')) Or $(AndroidSupportedTargetAotAbisForConditionalChecks.Contains (':win-armeabi:'))">true + <_ArmeabiRuntimeConfigure Condition="$(AndroidSupportedTargetJitAbisForConditionalChecks.Contains (':armeabi:')) Or $(AndroidSupportedTargetAotAbisForConditionalChecks.Contains (':armeabi:')) Or $(AndroidSupportedTargetAotAbisForConditionalChecks.Contains (':win-armeabi:')) ">true <_ArmeabiRuntimeBuild Condition="$(AndroidSupportedTargetJitAbisForConditionalChecks.Contains (':armeabi:'))">true @@ -41,7 +41,7 @@ - <_Arm64RuntimeConfigure Condition="$(AndroidSupportedTargetJitAbisForConditionalChecks.Contains (':arm64-v8a:')) Or $(AndroidSupportedTargetAotAbisForConditionalChecks.Contains (':win-arm64:'))">true + <_Arm64RuntimeConfigure Condition="$(AndroidSupportedTargetJitAbisForConditionalChecks.Contains (':arm64-v8a:')) Or $(AndroidSupportedTargetAotAbisForConditionalChecks.Contains (':arm64:')) Or $(AndroidSupportedTargetAotAbisForConditionalChecks.Contains (':win-arm64:'))">true <_Arm64RuntimeBuild Condition="$(AndroidSupportedTargetJitAbisForConditionalChecks.Contains (':arm64-v8a:'))">true @@ -58,7 +58,7 @@ - <_X86RuntimeConfigure Condition="$(AndroidSupportedTargetJitAbisForConditionalChecks.Contains (':x86:')) Or $(AndroidSupportedTargetAotAbisForConditionalChecks.Contains (':win-x86:'))">true + <_X86RuntimeConfigure Condition="$(AndroidSupportedTargetJitAbisForConditionalChecks.Contains (':x86:')) Or $(AndroidSupportedTargetAotAbisForConditionalChecks.Contains (':x86:')) Or $(AndroidSupportedTargetAotAbisForConditionalChecks.Contains (':win-x86:'))">true <_X86RuntimeBuild Condition="$(AndroidSupportedTargetJitAbisForConditionalChecks.Contains (':x86:'))">true @@ -75,7 +75,7 @@ - <_X8664RuntimeConfigure Condition="$(AndroidSupportedTargetJitAbisForConditionalChecks.Contains (':x86_64:')) Or $(AndroidSupportedTargetAotAbisForConditionalChecks.Contains (':win-x86_64:'))">true + <_X8664RuntimeConfigure Condition="$(AndroidSupportedTargetJitAbisForConditionalChecks.Contains (':x86_64:')) Or $(AndroidSupportedTargetAotAbisForConditionalChecks.Contains (':x86_64:')) Or $(AndroidSupportedTargetAotAbisForConditionalChecks.Contains (':win-x86_64:'))">true <_X8664RuntimeBuild Condition="$(AndroidSupportedTargetJitAbisForConditionalChecks.Contains (':x86_64:'))">true diff --git a/src/monodroid/jni/dylib-mono.c b/src/monodroid/jni/dylib-mono.c index 8e1675a7042..67dd46b566d 100644 --- a/src/monodroid/jni/dylib-mono.c +++ b/src/monodroid/jni/dylib-mono.c @@ -139,7 +139,7 @@ int monodroid_dylib_mono_init (struct DylibMono *mono_imports, const char *libmo LOAD_SYMBOL(mono_thread_create) LOAD_SYMBOL(mono_thread_current) LOAD_SYMBOL(mono_use_llvm) - + LOAD_SYMBOL(mono_aot_register_module) if (symbols_missing) { log_fatal (LOG_DEFAULT, "Failed to load some Mono symbols, aborting..."); diff --git a/src/monodroid/jni/dylib-mono.h b/src/monodroid/jni/dylib-mono.h index 25cb828adfd..9d95e4fb7a3 100644 --- a/src/monodroid/jni/dylib-mono.h +++ b/src/monodroid/jni/dylib-mono.h @@ -254,6 +254,7 @@ typedef MonoThread* (*monodroid_mono_thread_current_fptr) (void); typedef void (*monodroid_mono_gc_disable_fptr) (void); typedef void* (*monodroid_mono_install_assembly_refonly_preload_hook_fptr) (MonoAssemblyPreLoadFunc func, void *user_data); typedef int (*monodroid_mono_runtime_set_main_args_fptr) (int argc, char* argv[]); +typedef void (*mono_aot_register_module_fptr) (void* aot_info); /* NOTE: structure members MUST NOT CHANGE ORDER. */ struct DylibMono { @@ -342,6 +343,7 @@ struct DylibMono { monodroid_mono_class_get_property_from_name_fptr mono_class_get_property_from_name; monodroid_mono_domain_from_appdomain_fptr mono_domain_from_appdomain; monodroid_mono_thread_current_fptr mono_thread_current; + mono_aot_register_module_fptr mono_aot_register_module; }; MONO_API struct DylibMono* monodroid_dylib_mono_new (const char *libmono_path); diff --git a/src/monodroid/jni/mkbundle-api.h b/src/monodroid/jni/mkbundle-api.h new file mode 100644 index 00000000000..aa833a70b00 --- /dev/null +++ b/src/monodroid/jni/mkbundle-api.h @@ -0,0 +1,27 @@ +#ifndef __MKBUNDLE_API_H +#define __MKBUNDLE_API_H +typedef struct BundleMonoAPI +{ + void (*mono_register_bundled_assemblies) (const MonoBundledAssembly **assemblies); + void (*mono_register_config_for_assembly) (const char* assembly_name, const char* config_xml); + void (*mono_jit_set_aot_mode) (int mode); + void (*mono_aot_register_module) (void* aot_info); + void (*mono_config_parse_memory) (const char *buffer); + void (*mono_register_machine_config) (const char *config_xml); +} BundleMonoAPI; + +#if ANDROID +#include +#include + +static void +mkbundle_log_error (const char *format, ...) +{ + va_list ap; + + va_start (ap, format); + __android_log_vprint (ANDROID_LOG_ERROR, "mkbundle", format, ap); + va_end (ap); +} +#endif // ANDROID +#endif // __MKBUNDLE_API_H diff --git a/src/monodroid/jni/monodroid-glue.c b/src/monodroid/jni/monodroid-glue.c index 9c54a6e1e81..9d92d4857ee 100644 --- a/src/monodroid/jni/monodroid-glue.c +++ b/src/monodroid/jni/monodroid-glue.c @@ -67,6 +67,7 @@ #include "unzip.h" #include "ioapi.h" #include "monodroid-glue.h" +#include "mkbundle-api.h" #ifndef WINDOWS #include "xamarin_getifaddrs.h" @@ -697,6 +698,7 @@ get_libmonosgen_path () typedef void* (*mono_mkbundle_init_ptr) (void (*)(const MonoBundledAssembly **), void (*)(const char* assembly_name, const char* config_xml),void (*) (int mode)); mono_mkbundle_init_ptr mono_mkbundle_init; +void (*mono_mkbundle_initialize_mono_api) (const BundleMonoAPI *info); static void setup_bundled_app (const char *libappso) @@ -709,7 +711,11 @@ setup_bundled_app (const char *libappso) log_fatal (LOG_BUNDLE, "bundled app initialization error: %s", dlerror ()); exit (FATAL_EXIT_CANNOT_LOAD_BUNDLE); } - + + mono_mkbundle_initialize_mono_api = dlsym (libapp, "initialize_mono_api"); + if (!mono_mkbundle_initialize_mono_api) + log_error (LOG_BUNDLE, "Missing initialize_mono_api in the application"); + mono_mkbundle_init = dlsym (libapp, "mono_mkbundle_init"); if (!mono_mkbundle_init) log_error (LOG_BUNDLE, "Missing mono_mkbundle_init in the application"); @@ -2647,6 +2653,20 @@ mono_runtime_init (char *runtime_args) register_gc_hooks (); + if (mono_mkbundle_initialize_mono_api) { + BundleMonoAPI bundle_mono_api = { + .mono_register_bundled_assemblies = mono.mono_register_bundled_assemblies, + .mono_register_config_for_assembly = mono.mono_register_config_for_assembly, + .mono_jit_set_aot_mode = mono.mono_jit_set_aot_mode, + .mono_aot_register_module = mono.mono_aot_register_module, + .mono_config_parse_memory = mono.mono_config_parse_memory, + .mono_register_machine_config = mono.mono_register_machine_config, + }; + + /* The initialization function copies the struct */ + mono_mkbundle_initialize_mono_api (&bundle_mono_api); + } + if (mono_mkbundle_init) mono_mkbundle_init (mono.mono_register_bundled_assemblies, mono.mono_register_config_for_assembly, mono.mono_jit_set_aot_mode);