diff --git a/eng/testing/tests.mobile.targets b/eng/testing/tests.mobile.targets index cf570790f1a48..31e2a3afa2ed5 100644 --- a/eng/testing/tests.mobile.targets +++ b/eng/testing/tests.mobile.targets @@ -191,8 +191,7 @@ $(BundleDir) - $(PublishDir) - $(PublishDir)WasmTestRunner.dll + WasmTestRunner.dll $(MonoProjectRoot)\wasm\runtime-test.js $(InvariantGlobalization) true diff --git a/src/mono/netcore/sample/mbr/browser/WasmDelta.csproj b/src/mono/netcore/sample/mbr/browser/WasmDelta.csproj index 92ee7ca3fbfd5..322a01ba8595a 100644 --- a/src/mono/netcore/sample/mbr/browser/WasmDelta.csproj +++ b/src/mono/netcore/sample/mbr/browser/WasmDelta.csproj @@ -30,11 +30,6 @@ - - $(MSBuildProjectDirectory)\$(PublishDir)\ - $(WasmBuildDir)$(AssemblyName).dll - - diff --git a/src/mono/netcore/sample/wasm/Directory.Build.targets b/src/mono/netcore/sample/wasm/Directory.Build.targets index e2c0589757e44..640ae9b714d3f 100644 --- a/src/mono/netcore/sample/wasm/Directory.Build.targets +++ b/src/mono/netcore/sample/wasm/Directory.Build.targets @@ -6,10 +6,6 @@ - - $(MSBuildProjectDirectory)\$(PublishDir)\ - $(WasmBuildDir)$(AssemblyName).dll - diff --git a/src/mono/netcore/sample/wasm/wasm.mk b/src/mono/netcore/sample/wasm/wasm.mk index a6b27256b9308..1858ca3791182 100644 --- a/src/mono/netcore/sample/wasm/wasm.mk +++ b/src/mono/netcore/sample/wasm/wasm.mk @@ -16,7 +16,7 @@ build: EMSDK_PATH=$(realpath $(TOP)/src/mono/wasm/emsdk) $(DOTNET) publish $(DOTNET_Q_ARGS) $(WASM_DEFAULT_BUILD_ARGS) $(MSBUILD_ARGS) $(PROJECT_NAME) clean: - rm -rf bin $(TOP)/artifacts/obj/mono/$(PROJECT_NAME) + rm -rf bin $(TOP)/artifacts/obj/mono/$(PROJECT_NAME:%.csproj=%) run-browser: if ! $(DOTNET) tool list --global | grep dotnet-serve; then \ diff --git a/src/mono/wasm/build/README.md b/src/mono/wasm/build/README.md index e8343abe90373..c019c01c2bbf0 100644 --- a/src/mono/wasm/build/README.md +++ b/src/mono/wasm/build/README.md @@ -47,3 +47,5 @@ The various task inputs correspond to properties as: - To control it's generation use `$(WasmGenerateRunV8Script)` (false by default) This should be a step towards eventually having this build as a sdk. + +Refer to `WasmApp.targets` for more information about the properties/items used as inputs to the process. diff --git a/src/mono/wasm/build/WasmApp.InTree.targets b/src/mono/wasm/build/WasmApp.InTree.targets index c5191b62d2335..7f1f3550e959e 100644 --- a/src/mono/wasm/build/WasmApp.InTree.targets +++ b/src/mono/wasm/build/WasmApp.InTree.targets @@ -10,7 +10,7 @@ $(ArtifactsBinDir)microsoft.netcore.app.runtime.browser-wasm\$(Configuration) - + diff --git a/src/mono/wasm/build/WasmApp.targets b/src/mono/wasm/build/WasmApp.targets index 18afa169ce1c1..2357b0f8e161f 100644 --- a/src/mono/wasm/build/WasmApp.targets +++ b/src/mono/wasm/build/WasmApp.targets @@ -6,14 +6,14 @@ + + + + + + + @@ -149,7 +179,7 @@ $(MicrosoftNetCoreAppRuntimePackRidDir)native\src\emcc-flags.txt $(MicrosoftNetCoreAppRuntimePackRidDir)native\src\emcc-version.txt - $(WasmBuildDir)emcc-version.txt + $(_WasmIntermediateOutputPath)emcc-version.txt @@ -167,7 +197,7 @@ - + @@ -177,24 +207,25 @@ <_WasmPInvokeModules Include="libSystem.Native" /> <_WasmPInvokeModules Include="libSystem.IO.Compression.Native" /> <_WasmPInvokeModules Include="libSystem.Globalization.Native" /> - <_WasmPInvokeAssemblies Include="$(WasmBuildDir)\*.dll" /> - + + Assemblies="@(_WasmAssemblies)" + OutputPath="$(_WasmIntermediateOutputPath)pinvoke-table.h" /> - <_WasmObjects Include="libmono-ee-interp.a"/> - <_WasmObjects Include="libmonosgen-2.0.a"/> - <_WasmObjects Include="libmono-ilgen.a"/> - <_WasmObjects Include="libmono-icall-table.a"/> - <_WasmObjects Include="libSystem.Native.a"/> - <_WasmObjects Include="libSystem.IO.Compression.Native.a"/> - <_WasmObjects Include="libmono-profiler-aot.a"/> - <_WasmObjects Include="libicuuc.a"/> - <_WasmObjects Include="libicui18n.a"/> + <_WasmRuntimePackNativeLibs Include="libmono-ee-interp.a"/> + <_WasmRuntimePackNativeLibs Include="libmonosgen-2.0.a"/> + <_WasmRuntimePackNativeLibs Include="libmono-ilgen.a"/> + <_WasmRuntimePackNativeLibs Include="libmono-icall-table.a"/> + <_WasmRuntimePackNativeLibs Include="libSystem.Native.a"/> + <_WasmRuntimePackNativeLibs Include="libSystem.IO.Compression.Native.a"/> + <_WasmRuntimePackNativeLibs Include="libmono-profiler-aot.a"/> + <_WasmRuntimePackNativeLibs Include="libicuuc.a"/> + <_WasmRuntimePackNativeLibs Include="libicui18n.a"/> + <_WasmObjects Include="@(_WasmRuntimePackNativeLibs->'$(MicrosoftNetCoreAppRuntimePackRidDir)\native\%(FileName)%(Extension)')" /> + <_WasmObjects Include="driver.o"/> <_WasmObjects Include="pinvoke.o"/> <_WasmObjects Include="corebindings.o"/> @@ -203,15 +234,20 @@ <_WasmIncludeDir>$(MicrosoftNetCoreAppRuntimePackRidDir)native/include <_WasmSrcDir>$(MicrosoftNetCoreAppRuntimePackRidDir)native/src - $(EmccFlags) -DCORE_BINDINGS -DGEN_PINVOKE=1 -I$(WasmBuildDir) -I$(_WasmIncludeDir)/mono-2.0 -I$(_WasmIncludeDir)/wasm + $(EmccFlags) -DCORE_BINDINGS -DGEN_PINVOKE=1 -I$(_WasmIntermediateOutputPath) -I$(_WasmIncludeDir)/mono-2.0 -I$(_WasmIncludeDir)/wasm $(EmccFlags) -s TOTAL_MEMORY=536870912 - - - - - + + + + + + + + + + @@ -222,7 +258,7 @@ void mono_profiler_init_aot (const char *desc)%3B EMSCRIPTEN_KEEPALIVE void mono_wasm_load_profiler_aot (const char *desc) { mono_profiler_init_aot (desc)%3B } - <_DriverGenCPath>$(WasmBuildDir)driver-gen.c + <_DriverGenCPath>$(_WasmIntermediateOutputPath)driver-gen.c @@ -238,9 +274,10 @@ EMSCRIPTEN_KEEPALIVE void mono_wasm_load_profiler_aot (const char *desc) { mono_ $(WasmAppDir)run-v8.sh + 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 91e81aeef9e73..988b3b2e5d9a0 100644 --- a/src/mono/wasm/debugger/tests/debugger-test/debugger-test.csproj +++ b/src/mono/wasm/debugger/tests/debugger-test/debugger-test.csproj @@ -19,7 +19,6 @@ - $(OutDir)debugger-test.dll $(AppDir) $(MonoProjectRoot)wasm\runtime-test.js 1 @@ -28,6 +27,7 @@ + diff --git a/src/tasks/AotCompilerTask/MonoAOTCompiler.cs b/src/tasks/AotCompilerTask/MonoAOTCompiler.cs index c3a5bb3a075b0..b7c0cf365cd16 100644 --- a/src/tasks/AotCompilerTask/MonoAOTCompiler.cs +++ b/src/tasks/AotCompilerTask/MonoAOTCompiler.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Collections.Concurrent; +using System.Diagnostics.CodeAnalysis; using System.IO; using System.Linq; using System.Text; @@ -29,6 +30,13 @@ public class MonoAOTCompiler : Microsoft.Build.Utilities.Task [Required] public ITaskItem[] Assemblies { get; set; } = Array.Empty(); + /// + /// Directory where the AOT'ed files will be emitted + /// + [NotNull] + [Required] + public string? OutputDir { get; set; } + /// /// Assemblies which were AOT compiled. /// @@ -133,6 +141,12 @@ public override bool Execute() throw new ArgumentException($"'{nameof(Assemblies)}' is required.", nameof(Assemblies)); } + if (!Directory.Exists(OutputDir)) + { + Log.LogError($"OutputDir={OutputDir} doesn't exist"); + return false; + } + if (!string.IsNullOrEmpty(AotProfilePath) && !File.Exists(AotProfilePath)) { Log.LogError($"'{AotProfilePath}' doesn't exist.", nameof(AotProfilePath)); @@ -242,12 +256,14 @@ private bool PrecompileLibrary(ITaskItem assemblyItem) processArgs.Add("--nollvm"); } + string assemblyFilename = Path.GetFileName(assembly); + // compute output mode and file names if (parsedAotMode == MonoAotMode.LLVMOnly || parsedAotMode == MonoAotMode.AotInterp) { aotArgs.Add("llvmonly"); - string llvmBitcodeFile = Path.ChangeExtension(assembly, ".dll.bc"); + string llvmBitcodeFile = Path.Combine(OutputDir, Path.ChangeExtension(assemblyFilename, ".dll.bc")); aotAssembly.SetMetadata("LlvmBitcodeFile", llvmBitcodeFile); if (parsedAotMode == MonoAotMode.AotInterp) @@ -276,20 +292,20 @@ private bool PrecompileLibrary(ITaskItem assemblyItem) { aotArgs.Add("asmonly"); - string assemblerFile = Path.ChangeExtension(assembly, ".dll.s"); + string assemblerFile = Path.Combine(OutputDir, Path.ChangeExtension(assemblyFilename, ".dll.s")); aotArgs.Add($"outfile={assemblerFile}"); aotAssembly.SetMetadata("AssemblerFile", assemblerFile); } else { - string objectFile = Path.ChangeExtension(assembly, ".dll.o"); + string objectFile = Path.Combine(OutputDir, Path.ChangeExtension(assemblyFilename, ".dll.o")); aotArgs.Add($"outfile={objectFile}"); aotAssembly.SetMetadata("ObjectFile", objectFile); } if (UseLLVM) { - string llvmObjectFile = Path.ChangeExtension(assembly, ".dll-llvm.o"); + string llvmObjectFile = Path.Combine(OutputDir, Path.ChangeExtension(assemblyFilename, ".dll-llvm.o")); aotArgs.Add($"llvm-outfile={llvmObjectFile}"); aotAssembly.SetMetadata("LlvmObjectFile", llvmObjectFile); } diff --git a/src/tasks/WasmAppBuilder/WasmAppBuilder.cs b/src/tasks/WasmAppBuilder/WasmAppBuilder.cs index d43a09d07e6f9..de7c0e3741b74 100644 --- a/src/tasks/WasmAppBuilder/WasmAppBuilder.cs +++ b/src/tasks/WasmAppBuilder/WasmAppBuilder.cs @@ -24,15 +24,15 @@ public class WasmAppBuilder : Task [NotNull] [Required] - public string? MicrosoftNetCoreAppRuntimePackDir { get; set; } + public string? MainJS { get; set; } [NotNull] [Required] - public string? MainJS { get; set; } + public string[]? Assemblies { get; set; } [NotNull] [Required] - public string[]? Assemblies { get; set; } + public ITaskItem[]? NativeAssets { get; set; } private List _fileWrites = new(); @@ -41,7 +41,7 @@ public class WasmAppBuilder : Task // full list of ICU data files we produce can be found here: // https://github.com/dotnet/icu/tree/maint/maint-67/icu-filters - public string? IcuDataFileName { get; set; } = "icudt.dat"; + public string? IcuDataFileName { get; set; } public int DebugLevel { get; set; } public ITaskItem[]? SatelliteAssemblies { get; set; } @@ -127,22 +127,18 @@ public override bool Execute () throw new ArgumentException($"File MainJS='{MainJS}' doesn't exist."); if (!InvariantGlobalization && string.IsNullOrEmpty(IcuDataFileName)) throw new ArgumentException("IcuDataFileName property shouldn't be empty if InvariantGlobalization=false"); - if (Assemblies == null) + + if (Assemblies?.Length == 0) { - Log.LogError($"Assemblies should not be null."); + Log.LogError("Cannot build Wasm app without any assemblies"); return false; } var _assemblies = new List(); - var runtimeSourceDir = Path.Join(MicrosoftNetCoreAppRuntimePackDir, "native"); - - foreach (var asm in Assemblies) + foreach (var asm in Assemblies!) { if (!_assemblies.Contains(asm)) _assemblies.Add(asm); - - if (asm.EndsWith("System.Private.CoreLib.dll")) - runtimeSourceDir = Path.GetDirectoryName(asm); } var config = new WasmAppConfig (); @@ -163,15 +159,11 @@ public override bool Execute () } } - List nativeAssets = new List() { "dotnet.wasm", "dotnet.js", "dotnet.timezones.blat" }; - - if (!InvariantGlobalization) - nativeAssets.Add(IcuDataFileName!); - - if (Path.TrimEndingDirectorySeparator(Path.GetFullPath(runtimeSourceDir)) != Path.TrimEndingDirectorySeparator(Path.GetFullPath(AppDir!))) + foreach (ITaskItem item in NativeAssets) { - foreach (var f in nativeAssets) - FileCopyChecked(Path.Join(runtimeSourceDir, f), Path.Join(AppDir, f), "NativeAssets"); + string dest = Path.Combine(AppDir!, Path.GetFileName(item.ItemSpec)); + if (!FileCopyChecked(item.ItemSpec, dest, "NativeAssets")) + return false; } FileCopyChecked(MainJS!, Path.Join(AppDir, "runtime.js"), string.Empty); @@ -278,7 +270,7 @@ public override bool Execute () } } - return true; + return !Log.HasLoggedErrors; } private bool TryParseExtraConfigValue(ITaskItem extraItem, out object? valueObject) diff --git a/src/tests/Common/CLRTest.Execute.Bash.targets b/src/tests/Common/CLRTest.Execute.Bash.targets index d7b4830d8bb0c..cf2bdfe7254f7 100644 --- a/src/tests/Common/CLRTest.Execute.Bash.targets +++ b/src/tests/Common/CLRTest.Execute.Bash.targets @@ -274,7 +274,7 @@ else __Command+=" dotnet" fi -$__Command msbuild $CORE_ROOT/wasm-test-runner/WasmTestRunner.proj /p:NetCoreAppCurrent=$(NetCoreAppCurrent) /p:TestAssembly=`pwd`/$(MsBuildProjectName).dll /p:TestBinDir=`pwd` || exit $? +$__Command msbuild $CORE_ROOT/wasm-test-runner/WasmTestRunner.proj /p:NetCoreAppCurrent=$(NetCoreAppCurrent) /p:TestAssemblyFileName=$(MsBuildProjectName).dll /p:TestBinDir=`pwd` || exit $? ]]> diff --git a/src/tests/Common/wasm-test-runner/WasmTestRunner.proj b/src/tests/Common/wasm-test-runner/WasmTestRunner.proj index 99c21b0560a6d..c28b704c4f3be 100644 --- a/src/tests/Common/wasm-test-runner/WasmTestRunner.proj +++ b/src/tests/Common/wasm-test-runner/WasmTestRunner.proj @@ -16,7 +16,7 @@ - $(TestAssembly) + $(TestAssemblyFileName) $(AppDir) $(CORE_ROOT)\runtime-test\runtime-test.js true @@ -25,6 +25,7 @@ + diff --git a/src/tests/FunctionalTests/wasm/AOT/browser/Wasm.Aot.Browser.Test.csproj b/src/tests/FunctionalTests/wasm/AOT/browser/Wasm.Aot.Browser.Test.csproj index 0a84ee716ea00..bd206a8dff838 100644 --- a/src/tests/FunctionalTests/wasm/AOT/browser/Wasm.Aot.Browser.Test.csproj +++ b/src/tests/FunctionalTests/wasm/AOT/browser/Wasm.Aot.Browser.Test.csproj @@ -3,6 +3,7 @@ true WasmTestOnBrowser 42 + runtime.js @@ -15,11 +16,4 @@ - - - - $(PublishDir)Wasm.AOT.Browser.Test.dll - runtime.js - - diff --git a/src/tests/FunctionalTests/wasm/Directory.Build.targets b/src/tests/FunctionalTests/wasm/Directory.Build.targets index 55390cd9c918b..b0d320fabe377 100644 --- a/src/tests/FunctionalTests/wasm/Directory.Build.targets +++ b/src/tests/FunctionalTests/wasm/Directory.Build.targets @@ -3,14 +3,10 @@ PrepareForWasmBuild;$(WasmBuildAppDependsOn) + $(OutputPath)\$(Configuration)\AppBundle\ - - $(OutputPath)\$(Configuration)\AppBundle\ - $(PublishDir) - $(WasmBuildDir)$(AssemblyName).dll - diff --git a/src/tests/FunctionalTests/wasm/Interpreter/browser/Wasm.Interpreter.Browser.Test.csproj b/src/tests/FunctionalTests/wasm/Interpreter/browser/Wasm.Interpreter.Browser.Test.csproj index 47c4c6c69c71d..db384e014d64a 100644 --- a/src/tests/FunctionalTests/wasm/Interpreter/browser/Wasm.Interpreter.Browser.Test.csproj +++ b/src/tests/FunctionalTests/wasm/Interpreter/browser/Wasm.Interpreter.Browser.Test.csproj @@ -5,6 +5,7 @@ true WasmTestOnBrowser 42 + runtime.js @@ -16,11 +17,4 @@ - - - - $(PublishDir)Wasm.Interpreter.Browser.Test.dll - runtime.js - -