From 85d2df801ab4c91fc7e3c1f61752c4d305b2a7d0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alexander=20K=C3=B6plinger?= Date: Fri, 13 Nov 2020 17:25:02 +0100 Subject: [PATCH] Enable WASM AOT option in build and update MonoAOTCompiler (#44468) Allows creating AOT images for WASM with the AOT compiler and consuming them in the runtime. Use `make build AOT=1` in `src/mono/netcore/sample/wasm/console` to try it out. -- Also fix a regression in aot-compiler.c regarding SPC->corlib assembly name: In https://github.com/dotnet/runtime/commit/035ebeab160b9a281e5fbb3fa0c237f244c81b7a we added a simplified prefix for symbol names in System.Private.CoreLib. However this shouldn't happen for the actual assembly name otherwise we aren't able to find the AOT module linked statically into the binary. --- eng/liveBuilds.targets | 3 +- eng/testing/tests.mobile.targets | 2 + .../Microsoft.NETCore.App/Directory.Build.props | 1 + .../Microsoft.NETCore.App.Runtime.sfxproj | 4 +- src/mono/mono.proj | 2 +- src/mono/mono/mini/aot-compiler.c | 4 +- src/mono/mono/mini/mini-wasm.c | 6 +- src/mono/netcore/sample/iOS/Program.csproj | 9 +- src/mono/netcore/sample/wasm/browser/Makefile | 7 +- .../netcore/sample/wasm/browser/WasmSample.csproj | 6 +- src/mono/netcore/sample/wasm/console/Makefile | 13 ++- .../netcore/sample/wasm/console/WasmSample.csproj | 64 +++++++++-- src/mono/wasm/Makefile | 19 ++-- .../tests/debugger-test/debugger-test.csproj | 6 +- src/mono/wasm/wasm.proj | 3 +- .../AotCompilerTask/MonoAOTCompiler.cs | 118 ++++++++++++++++++++- .../AotCompilerTask/MonoAOTCompiler.props | 6 ++ .../AppleAppBuilder/AppleAppBuilder.cs | 58 ---------- .../Templates/CMakeLists.txt.template | 2 +- .../AppleAppBuilder/Templates/runtime.m | 4 +- .../tasks/mobile.tasks/AppleAppBuilder/Xcode.cs | 1 + .../mobile.tasks/WasmAppBuilder/WasmAppBuilder.cs | 4 +- 22 files changed, 240 insertions(+), 102 deletions(-) diff --git a/eng/liveBuilds.targets b/eng/liveBuilds.targets index 8cbde5f..957ff8b 100644 --- a/eng/liveBuilds.targets +++ b/eng/liveBuilds.targets @@ -166,7 +166,8 @@ diff --git a/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props b/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props index 71ea5d2..60673af 100644 --- a/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props +++ b/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props @@ -355,6 +355,7 @@ + diff --git a/src/installer/pkg/sfx/Microsoft.NETCore.App/Microsoft.NETCore.App.Runtime.sfxproj b/src/installer/pkg/sfx/Microsoft.NETCore.App/Microsoft.NETCore.App.Runtime.sfxproj index b192352..75ef79b 100644 --- a/src/installer/pkg/sfx/Microsoft.NETCore.App/Microsoft.NETCore.App.Runtime.sfxproj +++ b/src/installer/pkg/sfx/Microsoft.NETCore.App/Microsoft.NETCore.App.Runtime.sfxproj @@ -87,7 +87,9 @@ + Condition="'%(LibrariesRuntimeFiles.Extension)' != '.a' or '$(TargetsMobile)' == 'true'"> + runtimes/$(RuntimeIdentifier)/native/%(LibrariesRuntimeFiles.NativeSubDirectory)%(RecursiveDir) + diff --git a/src/mono/mono.proj b/src/mono/mono.proj index 95f4672..6963823 100644 --- a/src/mono/mono.proj +++ b/src/mono/mono.proj @@ -186,7 +186,7 @@ <_MonoMinimal Condition="'$(Configuration)' == 'Release'">,assert_messages - <_MonoCMakeArgs Include="-DENABLE_MINIMAL=ssa,com,jit,reflection_emit_save,portability,assembly_remapping,attach,verifier,appdomains,shadowcopy,security,sgen_marksweep_conc,sgen_split_nursery,sgen_gc_bridge,sgen_toggleref,logging,remoting,shared_perfcounters,sgen_debug_helpers,sgen_binary_protocol,soft_debug,interpreter,cleanup,mdb,gac,threads,eventpipe,aot,interpreter,qcalls$(_MonoMinimal)"/> + <_MonoCMakeArgs Include="-DENABLE_MINIMAL=ssa,com,jit,reflection_emit_save,portability,assembly_remapping,attach,verifier,appdomains,shadowcopy,security,sgen_marksweep_conc,sgen_split_nursery,sgen_gc_bridge,sgen_toggleref,logging,remoting,shared_perfcounters,sgen_debug_helpers,sgen_binary_protocol,soft_debug,interpreter,cleanup,mdb,gac,threads,eventpipe,qcalls$(_MonoMinimal)"/> <_MonoCMakeArgs Include="-DENABLE_INTERP_LIB=1"/> <_MonoCMakeArgs Include="-DDISABLE_ICALL_TABLES=1"/> <_MonoCMakeArgs Include="-DDISABLE_CRASH_REPORTING=1"/> diff --git a/src/mono/mono/mini/aot-compiler.c b/src/mono/mono/mini/aot-compiler.c index 291c7a168..a66eeb8 100644 --- a/src/mono/mono/mini/aot-compiler.c +++ b/src/mono/mono/mini/aot-compiler.c @@ -11619,7 +11619,7 @@ emit_file_info (MonoAotCompile *acfg) emit_string_symbol (acfg, "assembly_guid" , acfg->image->guid); /* Emit a string holding the assembly name */ - emit_string_symbol (acfg, "assembly_name", get_assembly_prefix (acfg->image)); + emit_string_symbol (acfg, "assembly_name", acfg->image->assembly->aname.name); info = g_new0 (MonoAotFileInfo, 1); init_aot_file_info (acfg, info); @@ -11633,7 +11633,7 @@ emit_file_info (MonoAotCompile *acfg) * mono_aot_register_module (). The symbol points to a pointer to the the file info * structure. */ - sprintf (symbol, "%smono_aot_module_%s_info", acfg->user_symbol_prefix, get_assembly_prefix (acfg->image)); + sprintf (symbol, "%smono_aot_module_%s_info", acfg->user_symbol_prefix, acfg->image->assembly->aname.name); /* Get rid of characters which cannot occur in symbols */ p = symbol; diff --git a/src/mono/mono/mini/mini-wasm.c b/src/mono/mono/mini/mini-wasm.c index 2cf652d..f8d3e18 100644 --- a/src/mono/mono/mini/mini-wasm.c +++ b/src/mono/mono/mini/mini-wasm.c @@ -613,23 +613,25 @@ tp_cb (void) } } +#ifdef HOST_WASM void mono_wasm_queue_tp_cb (void) { -#ifdef HOST_WASM mono_threads_schedule_background_job (tp_cb); -#endif } +#endif void mono_arch_register_icall (void) { +#ifdef HOST_WASM #ifdef ENABLE_NETCORE mono_add_internal_call_internal ("System.Threading.TimerQueue::SetTimeout", mono_wasm_set_timeout); mono_add_internal_call_internal ("System.Threading.ThreadPool::QueueCallback", mono_wasm_queue_tp_cb); #else mono_add_internal_call_internal ("System.Threading.WasmRuntime::SetTimeout", mono_wasm_set_timeout); #endif +#endif } void diff --git a/src/mono/netcore/sample/iOS/Program.csproj b/src/mono/netcore/sample/iOS/Program.csproj index 519a6e7..1a7d551 100644 --- a/src/mono/netcore/sample/iOS/Program.csproj +++ b/src/mono/netcore/sample/iOS/Program.csproj @@ -34,24 +34,27 @@ $(MSBuildThisFileDirectory)$(PublishDir)\app iPhone 11 True + true - - + + @(MonoAOTCompilerDefaultAotArguments, ';') @(MonoAOTCompilerDefaultProcessArguments, ';') diff --git a/src/mono/netcore/sample/wasm/browser/Makefile b/src/mono/netcore/sample/wasm/browser/Makefile index 05e22d8..8b14756 100644 --- a/src/mono/netcore/sample/wasm/browser/Makefile +++ b/src/mono/netcore/sample/wasm/browser/Makefile @@ -1,13 +1,18 @@ TOP=../../../../../.. +DOTNET=$(TOP)/dotnet.sh +ifeq ($(V),) DOTNET_Q_ARGS=--nologo -v:q -consoleloggerparameters:NoSummary +else +DOTNET_Q_ARGS=--nologo +endif CONFIG?=Release all: build build: - $(TOP)/.dotnet/dotnet build $(DOTNET_Q_ARGS) /p:TargetArchitecture=wasm /p:TargetOS=Browser /p:Configuration=$(CONFIG) WasmSample.csproj + $(DOTNET) build $(DOTNET_Q_ARGS) /p:TargetArchitecture=wasm /p:TargetOS=Browser /p:Configuration=$(CONFIG) WasmSample.csproj clean: rm -rf bin diff --git a/src/mono/netcore/sample/wasm/browser/WasmSample.csproj b/src/mono/netcore/sample/wasm/browser/WasmSample.csproj index 3047239..a944c91 100644 --- a/src/mono/netcore/sample/wasm/browser/WasmSample.csproj +++ b/src/mono/netcore/sample/wasm/browser/WasmSample.csproj @@ -17,16 +17,16 @@ + AssemblyFile="$(ArtifactsBinDir)WasmAppBuilder\Debug\$(NetCoreAppCurrent)\publish\WasmAppBuilder.dll"/> diff --git a/src/mono/netcore/sample/wasm/console/Makefile b/src/mono/netcore/sample/wasm/console/Makefile index 960f458..856a3a6 100644 --- a/src/mono/netcore/sample/wasm/console/Makefile +++ b/src/mono/netcore/sample/wasm/console/Makefile @@ -1,9 +1,15 @@ TOP=../../../../../.. +DOTNET=$(TOP)/dotnet.sh ifeq ($(V),) DOTNET_Q_ARGS=--nologo -v:q -consoleloggerparameters:NoSummary else DOTNET_Q_ARGS=--nologo +DOTNET_MONO_LOG_LEVEL=--setenv=MONO_LOG_LEVEL=debug +endif + +ifneq ($(AOT),) +DOTNET_RUN_AOT_COMPILATION_ARGS=/p:RunAOTCompilation=true endif CONFIG?=Release @@ -11,13 +17,10 @@ CONFIG?=Release all: build build: - $(TOP)/.dotnet/dotnet publish $(DOTNET_Q_ARGS) /p:TargetArchitecture=wasm /p:TargetOS=Browser /p:Configuration=$(CONFIG) WasmSample.csproj + $(DOTNET) publish $(DOTNET_Q_ARGS) $(DOTNET_RUN_AOT_COMPILATION_ARGS) /p:TargetArchitecture=wasm /p:TargetOS=Browser /p:Configuration=$(CONFIG) WasmSample.csproj clean: rm -rf bin run: - cd bin/$(CONFIG)/publish && ~/.jsvu/v8 --expose_wasm runtime.js -- --run WasmSample.dll - -runtimepack: - EMSDK_PATH=$(abspath $(TOP)/src/mono/wasm/emsdk) $(TOP)/build.sh -c $(CONFIG) -os Browser -arch wasm -subset Mono+Libs + cd bin/$(CONFIG)/AppBundle && ~/.jsvu/v8 --expose_wasm runtime.js -- $(DOTNET_MONO_LOG_LEVEL) --run WasmSample.dll diff --git a/src/mono/netcore/sample/wasm/console/WasmSample.csproj b/src/mono/netcore/sample/wasm/console/WasmSample.csproj index baa4083..72179f6 100644 --- a/src/mono/netcore/sample/wasm/console/WasmSample.csproj +++ b/src/mono/netcore/sample/wasm/console/WasmSample.csproj @@ -8,13 +8,23 @@ Browser $(ArtifactsBinDir)microsoft.netcore.app.runtime.browser-wasm\$(Configuration)\runtimes\browser-wasm\ $(MSBuildThisFileDirectory)obj\$(Configuration)\wasm - $(MSBuildThisFileDirectory)bin\$(Configuration)\publish + $(MSBuildThisFileDirectory)bin\$(Configuration)\AppBundle\ true link false true browser-wasm false + false + + + + + false + true + false + false + false @@ -33,28 +43,70 @@ + + AssemblyFile="$(ArtifactsBinDir)WasmAppBuilder\Debug\$(NetCoreAppCurrent)\publish\WasmAppBuilder.dll"/> + + + + - + + + @(MonoAOTCompilerDefaultAotArguments, ';') + @(MonoAOTCompilerDefaultProcessArguments, ';') + + + + + + + + + + + + + + + + + - + + + + + + <_managedAppAssemblies Include="$(AppDir)managed\*.dll"/> + + diff --git a/src/mono/wasm/Makefile b/src/mono/wasm/Makefile index b359f4c..08e20f8 100644 --- a/src/mono/wasm/Makefile +++ b/src/mono/wasm/Makefile @@ -1,6 +1,8 @@ TOP=$(realpath $(CURDIR)/../../..) -include Make.config +escape_quote = $(subst ",\",$(1)) + DOTNET=$(TOP)/dotnet.sh JSVU=$(HOME)/.jsvu CHROMEDRIVER?=$(HOME)/.chromedriver @@ -71,13 +73,13 @@ EMCC_RELEASE_FLAGS=-Oz --llvm-opts 2 -DENABLE_NETCORE=1 STRIP_CMD=&& $(EMSDK_PATH)/upstream/bin/wasm-opt --strip-dwarf $(NATIVE_BIN_DIR)/dotnet.wasm -o $(NATIVE_BIN_DIR)/dotnet.wasm # -# Interpreter builds +# Wasm builds # # $(1) - EMCC_FLAGS # $(2) - libs # $(3) - strip cmd -define InterpBuildTemplate +define WasmBuildTemplate $(NATIVE_BIN_DIR): mkdir -p $$@ @@ -97,23 +99,26 @@ $(NATIVE_BIN_DIR)/dotnet.js: $(BUILDS_OBJ_DIR)/driver.o $(BUILDS_OBJ_DIR)/pinvok $(BUILDS_OBJ_DIR)/pinvoke-table.h: $(PINVOKE_TABLE) | $(BUILDS_OBJ_DIR) if cmp -s $(PINVOKE_TABLE) $$@ ; then : ; else cp $(PINVOKE_TABLE) $$@ ; fi -$(BUILDS_OBJ_DIR)/driver.o: runtime/driver.c runtime/corebindings.c | $(BUILDS_OBJ_DIR) +$(BUILDS_OBJ_DIR)/driver.o: runtime/driver.c | $(BUILDS_OBJ_DIR) $(EMCC) $(EMCC_FLAGS) $(1) -Oz -DCORE_BINDINGS -I$(BUILDS_OBJ_DIR) -I$(MONO_INCLUDE_DIR) runtime/driver.c -c -o $$@ $(BUILDS_OBJ_DIR)/pinvoke.o: runtime/pinvoke.c runtime/pinvoke.h $(BUILDS_OBJ_DIR)/pinvoke-table.h | $(BUILDS_OBJ_DIR) - $(EMCC) $(EMCC_FLAGS) $(1) -Oz -DGEN_PINVOKE=1 -I$(BUILDS_OBJ_DIR) -I$(MONO_INCLUDE_DIR) runtime/pinvoke.c -c -o $$@ + $(EMCC) $(EMCC_FLAGS) $(1) -Oz -DGEN_PINVOKE=1 -I$(BUILDS_OBJ_DIR) runtime/pinvoke.c -c -o $$@ $(BUILDS_OBJ_DIR)/corebindings.o: runtime/corebindings.c | $(BUILDS_OBJ_DIR) $(EMCC) $(EMCC_FLAGS) $(1) -Oz -I$(MONO_INCLUDE_DIR) runtime/corebindings.c -c -o $$@ -build-native: $(NATIVE_BIN_DIR)/dotnet.js +$(NATIVE_BIN_DIR)/src/emcc-flags.txt: | $(NATIVE_BIN_DIR)/src + echo "$(call escape_quote,$(EMCC_FLAGS)) $(1) -Oz" > $$@ + +build-native: $(NATIVE_BIN_DIR)/dotnet.js $(NATIVE_BIN_DIR)/src/emcc-flags.txt endef ifeq ($(CONFIG),Debug) -$(eval $(call InterpBuildTemplate,$(EMCC_DEBUG_FLAGS),$(MONO_LIBS),)) +$(eval $(call WasmBuildTemplate,$(EMCC_DEBUG_FLAGS),$(MONO_LIBS),)) else -$(eval $(call InterpBuildTemplate,$(EMCC_RELEASE_FLAGS),$(MONO_LIBS),$(STRIP_CMD))) +$(eval $(call WasmBuildTemplate,$(EMCC_RELEASE_FLAGS),$(MONO_LIBS),$(STRIP_CMD))) endif clean-emsdk: diff --git a/src/mono/wasm/debugger/tests/debugger-test/debugger-test.csproj b/src/mono/wasm/debugger/tests/debugger-test/debugger-test.csproj index 77d067b..22a3aaa 100644 --- a/src/mono/wasm/debugger/tests/debugger-test/debugger-test.csproj +++ b/src/mono/wasm/debugger/tests/debugger-test/debugger-test.csproj @@ -24,16 +24,16 @@ + AssemblyFile="$(ArtifactsBinDir)WasmAppBuilder\Debug\$(NetCoreAppCurrent)\publish\WasmAppBuilder.dll"/> diff --git a/src/mono/wasm/wasm.proj b/src/mono/wasm/wasm.proj index d21b20c..022e15b 100644 --- a/src/mono/wasm/wasm.proj +++ b/src/mono/wasm/wasm.proj @@ -96,7 +96,8 @@ + $(NativeBinDir)src\*.js; + $(NativeBinDir)src\emcc-flags.txt" /> diff --git a/tools-local/tasks/mobile.tasks/AotCompilerTask/MonoAOTCompiler.cs b/tools-local/tasks/mobile.tasks/AotCompilerTask/MonoAOTCompiler.cs index debd10c..a7db3fa 100644 --- a/tools-local/tasks/mobile.tasks/AotCompilerTask/MonoAOTCompiler.cs +++ b/tools-local/tasks/mobile.tasks/AotCompilerTask/MonoAOTCompiler.cs @@ -53,6 +53,24 @@ public class MonoAOTCompiler : Microsoft.Build.Utilities.Task public bool UseLLVM { get; set; } /// + /// Use a separate .aotdata file for the AOT data. + /// Defaults to true. + /// + public bool UseAotDataFile { get; set; } = true; + + /// + /// Generate a file containing mono_aot_register_module() calls for each AOT module + /// Defaults to false. + /// + public string? AotModulesTablePath { get; set; } + + /// + /// Source code language of the AOT modules table. Supports "C" or "ObjC". + /// Defaults to "C". + /// + public string? AotModulesTableLanguage { get; set; } = nameof(MonoAotModulesTableLanguage.C); + + /// /// Choose between 'Normal', 'Full', 'LLVMOnly'. /// LLVMOnly means to use only LLVM for FullAOT, AOT result will be a LLVM Bitcode file (the cross-compiler must be built with LLVM support) /// @@ -78,6 +96,7 @@ public class MonoAOTCompiler : Microsoft.Build.Utilities.Task private ConcurrentBag compiledAssemblies = new ConcurrentBag(); private MonoAotMode parsedAotMode; private MonoAotOutputType parsedOutputType; + private MonoAotModulesTableLanguage parsedAotModulesTableLanguage; public override bool Execute() { @@ -126,6 +145,19 @@ public class MonoAOTCompiler : Microsoft.Build.Utilities.Task throw new ArgumentException($"'{nameof(UseLLVM)}' must be true when '{nameof(Mode)}' is {nameof(MonoAotMode.LLVMOnly)}.", nameof(UseLLVM)); } + switch (AotModulesTableLanguage) + { + case "C": parsedAotModulesTableLanguage = MonoAotModulesTableLanguage.C; break; + case "ObjC": parsedAotModulesTableLanguage = MonoAotModulesTableLanguage.ObjC; break; + default: + throw new ArgumentException($"'{nameof(AotModulesTableLanguage)}' must be one of: '{nameof(MonoAotModulesTableLanguage.C)}', '{nameof(MonoAotModulesTableLanguage.ObjC)}'. Received: '{AotModulesTableLanguage}'.", nameof(AotModulesTableLanguage)); + } + + if (!string.IsNullOrEmpty(AotModulesTablePath)) + { + GenerateAotModulesTable(Assemblies); + } + Parallel.ForEach(Assemblies, new ParallelOptions { MaxDegreeOfParallelism = DisableParallelAot ? 1 : Environment.ProcessorCount }, assemblyItem => PrecompileLibrary (assemblyItem)); @@ -178,8 +210,17 @@ public class MonoAOTCompiler : Microsoft.Build.Utilities.Task aotArgs.Add("llvmonly"); string llvmBitcodeFile = Path.ChangeExtension(assembly, ".dll.bc"); - aotArgs.Add($"outfile={llvmBitcodeFile}"); aotAssembly.SetMetadata("LlvmBitcodeFile", llvmBitcodeFile); + + if (parsedOutputType == MonoAotOutputType.AsmOnly) + { + aotArgs.Add("asmonly"); + aotArgs.Add($"llvm-outfile={llvmBitcodeFile}"); + } + else + { + aotArgs.Add($"outfile={llvmBitcodeFile}"); + } } else { @@ -217,9 +258,12 @@ public class MonoAOTCompiler : Microsoft.Build.Utilities.Task aotArgs.Add($"msym-dir={MsymPath}"); } - string aotDataFile = Path.ChangeExtension(assembly, ".aotdata"); - aotArgs.Add($"data-outfile={aotDataFile}"); - aotAssembly.SetMetadata("AotDataFile", aotDataFile); + if (UseAotDataFile) + { + string aotDataFile = Path.ChangeExtension(assembly, ".aotdata"); + aotArgs.Add($"data-outfile={aotDataFile}"); + aotAssembly.SetMetadata("AotDataFile", aotDataFile); + } // we need to quote the entire --aot arguments here to make sure it is parsed // on Windows as one argument. Otherwise it will be split up into multiple @@ -239,6 +283,66 @@ public class MonoAOTCompiler : Microsoft.Build.Utilities.Task compiledAssemblies.Add(aotAssembly); } + + private void GenerateAotModulesTable(ITaskItem[] assemblies) + { + var symbols = new List(); + foreach (var asm in assemblies) + { + var name = Path.GetFileNameWithoutExtension(asm.ItemSpec).Replace ('.', '_').Replace ('-', '_'); + symbols.Add($"mono_aot_module_{name}_info"); + } + + Directory.CreateDirectory(Path.GetDirectoryName(AotModulesTablePath!)!); + + using (var writer = File.CreateText(AotModulesTablePath!)) + { + if (parsedAotModulesTableLanguage == MonoAotModulesTableLanguage.C) + { + foreach (var symbol in symbols) + { + writer.WriteLine($"extern void *{symbol};"); + } + writer.WriteLine("static void register_aot_modules ()"); + writer.WriteLine("{"); + foreach (var symbol in symbols) + { + writer.WriteLine($"\tmono_aot_register_module ({symbol});"); + } + writer.WriteLine("}"); + + if (parsedAotMode == MonoAotMode.LLVMOnly) + { + writer.WriteLine("#define EE_MODE_LLVMONLY 1"); + } + } + else if (parsedAotModulesTableLanguage == MonoAotModulesTableLanguage.ObjC) + { + writer.WriteLine("#include "); + writer.WriteLine("#include "); + writer.WriteLine(""); + writer.WriteLine("#if TARGET_OS_IPHONE && (!TARGET_IPHONE_SIMULATOR || USE_AOT_FOR_SIMULATOR)"); + + foreach (var symbol in symbols) + { + writer.WriteLine($"extern void *{symbol};"); + } + + writer.WriteLine("void register_aot_modules (void)"); + writer.WriteLine("{"); + foreach (var symbol in symbols) + { + writer.WriteLine($"\tmono_aot_register_module ({symbol});"); + } + writer.WriteLine("}"); + writer.WriteLine("#endif"); + } + else + { + throw new NotSupportedException(); + } + } + } } public enum MonoAotMode @@ -253,3 +357,9 @@ public enum MonoAotOutputType Normal, AsmOnly, } + +public enum MonoAotModulesTableLanguage +{ + C, + ObjC +} diff --git a/tools-local/tasks/mobile.tasks/AotCompilerTask/MonoAOTCompiler.props b/tools-local/tasks/mobile.tasks/AotCompilerTask/MonoAOTCompiler.props index 6824a7f..db518b2 100644 --- a/tools-local/tasks/mobile.tasks/AotCompilerTask/MonoAOTCompiler.props +++ b/tools-local/tasks/mobile.tasks/AotCompilerTask/MonoAOTCompiler.props @@ -14,4 +14,10 @@ + + + + + + diff --git a/tools-local/tasks/mobile.tasks/AppleAppBuilder/AppleAppBuilder.cs b/tools-local/tasks/mobile.tasks/AppleAppBuilder/AppleAppBuilder.cs index 0743f79..7066651 100644 --- a/tools-local/tasks/mobile.tasks/AppleAppBuilder/AppleAppBuilder.cs +++ b/tools-local/tasks/mobile.tasks/AppleAppBuilder/AppleAppBuilder.cs @@ -154,11 +154,6 @@ public class AppleAppBuilderTask : Task throw new InvalidOperationException("Need list of AOT files for device builds."); } - // generate modules.m - GenerateLinkAllFile( - assemblerFiles, - Path.Combine(binDir, "modules.m")); - if (GenerateXcodeProject) { XcodeProjectPath = Xcode.GenerateXCode(ProjectName, MainLibraryFileName, assemblerFiles, @@ -180,57 +175,4 @@ public class AppleAppBuilderTask : Task return true; } - - private static void GenerateLinkAllFile(IEnumerable asmFiles, string outputFile) - { - // Generates 'modules.m' in order to register all managed libraries - // - // - // extern void *mono_aot_module_Lib1_info; - // extern void *mono_aot_module_Lib2_info; - // ... - // - // void mono_ios_register_modules (void) - // { - // mono_aot_register_module (mono_aot_module_Lib1_info); - // mono_aot_register_module (mono_aot_module_Lib2_info); - // ... - // } - - Utils.LogInfo("Generating 'modules.m'..."); - - var lsDecl = new StringBuilder(); - lsDecl - .AppendLine("#include ") - .AppendLine("#include ") - .AppendLine() - .AppendLine("#if TARGET_OS_IPHONE && (!TARGET_IPHONE_SIMULATOR || USE_AOT_FOR_SIMULATOR)") - .AppendLine(); - - var lsUsage = new StringBuilder(); - lsUsage - .AppendLine("void mono_ios_register_modules (void)") - .AppendLine("{"); - foreach (string asmFile in asmFiles) - { - string symbol = "mono_aot_module_" + - Path.GetFileName(asmFile) - .Replace(".dll.s", "") - .Replace(".", "_") - .Replace("-", "_") + "_info"; - - lsDecl.Append("extern void *").Append(symbol).Append(';').AppendLine(); - lsUsage.Append("\tmono_aot_register_module (").Append(symbol).Append(");").AppendLine(); - } - lsDecl - .AppendLine() - .Append(lsUsage) - .AppendLine("}") - .AppendLine() - .AppendLine("#endif") - .AppendLine(); - - File.WriteAllText(outputFile, lsDecl.ToString()); - Utils.LogInfo($"Saved to {outputFile}."); - } } diff --git a/tools-local/tasks/mobile.tasks/AppleAppBuilder/Templates/CMakeLists.txt.template b/tools-local/tasks/mobile.tasks/AppleAppBuilder/Templates/CMakeLists.txt.template index ecd3d6c..ce8595e 100644 --- a/tools-local/tasks/mobile.tasks/AppleAppBuilder/Templates/CMakeLists.txt.template +++ b/tools-local/tasks/mobile.tasks/AppleAppBuilder/Templates/CMakeLists.txt.template @@ -12,7 +12,7 @@ add_executable( %MainSource% runtime.h runtime.m - modules.m + %AotModulesSource% ${APP_RESOURCES} ) diff --git a/tools-local/tasks/mobile.tasks/AppleAppBuilder/Templates/runtime.m b/tools-local/tasks/mobile.tasks/AppleAppBuilder/Templates/runtime.m index 02c0070..ba8b39c 100644 --- a/tools-local/tasks/mobile.tasks/AppleAppBuilder/Templates/runtime.m +++ b/tools-local/tasks/mobile.tasks/AppleAppBuilder/Templates/runtime.m @@ -198,7 +198,7 @@ register_dllmap (void) #if TARGET_OS_IPHONE && (!TARGET_IPHONE_SIMULATOR || USE_AOT_FOR_SIMULATOR) void mono_jit_set_aot_mode (MonoAotMode mode); -void mono_ios_register_modules (void); +void register_aot_modules (void); #endif void @@ -231,7 +231,7 @@ mono_ios_runtime_init (void) #if TARGET_OS_IPHONE && (!TARGET_IPHONE_SIMULATOR || USE_AOT_FOR_SIMULATOR) register_dllmap (); // register modules - mono_ios_register_modules (); + register_aot_modules (); mono_jit_set_aot_mode (MONO_AOT_MODE_FULL); #endif diff --git a/tools-local/tasks/mobile.tasks/AppleAppBuilder/Xcode.cs b/tools-local/tasks/mobile.tasks/AppleAppBuilder/Xcode.cs index fba4d5d..2184137 100644 --- a/tools-local/tasks/mobile.tasks/AppleAppBuilder/Xcode.cs +++ b/tools-local/tasks/mobile.tasks/AppleAppBuilder/Xcode.cs @@ -85,6 +85,7 @@ internal class Xcode cmakeLists = cmakeLists.Replace("%NativeLibrariesToLink%", toLink); cmakeLists = cmakeLists.Replace("%AotSources%", aotSources); + cmakeLists = cmakeLists.Replace("%AotModulesSource%", string.IsNullOrEmpty(aotSources) ? "" : "modules.m"); cmakeLists = cmakeLists.Replace("%Defines%", useAotForSimulator ? "add_definitions(-DUSE_AOT_FOR_SIMULATOR=1)" : ""); diff --git a/tools-local/tasks/mobile.tasks/WasmAppBuilder/WasmAppBuilder.cs b/tools-local/tasks/mobile.tasks/WasmAppBuilder/WasmAppBuilder.cs index 348e33b..fce387d 100644 --- a/tools-local/tasks/mobile.tasks/WasmAppBuilder/WasmAppBuilder.cs +++ b/tools-local/tasks/mobile.tasks/WasmAppBuilder/WasmAppBuilder.cs @@ -111,6 +111,7 @@ public class WasmAppBuilder : Task var paths = new List(); _assemblies = new SortedDictionary(); + var runtimeSourceDir = Path.Join (MicrosoftNetCoreAppRuntimePackDir, "native"); if (AssemblySearchPaths != null) { @@ -153,6 +154,7 @@ public class WasmAppBuilder : Task if (v.ItemSpec.EndsWith ("System.Private.CoreLib.dll")) corelibPath = Path.GetDirectoryName (v.ItemSpec)!; } + runtimeSourceDir = corelibPath!; _resolver = new Resolver(new List() { corelibPath }); var mlc = new MetadataLoadContext(_resolver, "System.Private.CoreLib"); @@ -184,7 +186,7 @@ public class WasmAppBuilder : Task nativeAssets.Add(IcuDataFileName!); foreach (var f in nativeAssets) - File.Copy(Path.Join (MicrosoftNetCoreAppRuntimePackDir, "native", f), Path.Join(AppDir, f), true); + File.Copy(Path.Join (runtimeSourceDir, f), Path.Join(AppDir, f), true); File.Copy(MainJS!, Path.Join(AppDir, "runtime.js"), true); var html = @""; -- 2.7.4