Ver código fonte

[wasm] Change netcore support to use a prebuilt corefx runtime. (#17773)

* [wasm] Change netcore support to use a prebuilt corefx runtime.

* [wasm] Build and test netcore support on CI.

* [wasm] Disable netcore tests on CI for now.

* [wasm] Add an error check.

* [wasm] Add a linker exclusion.

* [wasm] Add netcore runtimes to the nupkg.
Zoltan Varga 6 anos atrás
pai
commit
eaf895f2d0

+ 2 - 0
netcore/System.Private.CoreLib/src/LinkerDescriptor/System.Private.CoreLib.xml

@@ -31,6 +31,8 @@
 		  <method name="MonoResolveUsingResolveSatelliteAssembly" />
 		  <!-- appdomain.c: mono_try_assembly_resolve_handle () -->
 		  <method name="OnAssemblyResolve"/>
+		  <!-- native-library.c: netcore_resolve_with_load () -->
+		  <method name="MonoResolveUnmanagedDll"/>
 		</type>
 		
 		<!-- marshal.c: emit_marshal_custom (should not be used on devices)

+ 3 - 0
scripts/ci/run-jenkins.sh

@@ -343,6 +343,7 @@ if [[ ${CI_TAGS} == *'webassembly'* ]] || [[ ${CI_TAGS} == *'wasm'* ]];
         fi
 
         echo "ENABLE_WASM_THREADS=1" >> sdks/Make.config
+        echo "ENABLE_WASM_NETCORE=1" >> sdks/Make.config
 
         export aot_test_suites="System.Core"
         export mixed_test_suites="System.Core"
@@ -373,6 +374,8 @@ if [[ ${CI_TAGS} == *'webassembly'* ]] || [[ ${CI_TAGS} == *'wasm'* ]];
             ${TESTCMD} --label=build-aot-all --timeout=20m $gnumake -j ${CI_CPU_COUNT} -C sdks/wasm build-aot-all
             for suite in ${aot_test_suites}; do ${TESTCMD} --label=run-aot-${suite} --timeout=10m $gnumake -C sdks/wasm run-aot-${suite}; done
             for suite in ${mixed_test_suites}; do ${TESTCMD} --label=run-aot-mixed-${suite} --timeout=10m $gnumake -C sdks/wasm run-aot-mixed-${suite}; done
+            # Requires a net 3.0 sdk
+            #${TESTCMD} --label=netcore --timeout=20m $gnumake -j ${CI_CPU_COUNT} -C sdks/wasm run-hello-netcore
             #${TESTCMD} --label=check-aot --timeout=20m $gnumake -C sdks/wasm check-aot
             ${TESTCMD} --label=package --timeout=20m $gnumake -C sdks/wasm package
         fi

+ 16 - 12
sdks/wasm/Makefile

@@ -192,8 +192,17 @@ bcl:
 
 ifdef ENABLE_WASM_NETCORE
 
-NETCOREAPP_VERSION := $(shell cat ../../eng/Versions.props | sed -n 's/.*MicrosoftNETCoreAppVersion>\(.*\)<\/MicrosoftNETCoreAppVersion.*/\1/p' )
-NETCOREAPP_DIR=../../netcore/shared/Microsoft.NETCore.App/$(NETCOREAPP_VERSION)
+#NETCOREAPP_VERSION := $(shell cat ../../eng/Versions.props | sed -n 's/.*MicrosoftNETCoreAppVersion>\(.*\)<\/MicrosoftNETCoreAppVersion.*/\1/p' )
+NETCOREAPP_FEED=https://dotnetfeed.blob.core.windows.net/dotnet-core/index.json
+NETCOREAPP_VERSION := 5.0.0-alpha.1.19559.6
+NETCOREAPP_NAME=runtime.webassembly-wasm.Microsoft.Private.CoreFx.NETCoreApp
+NETCOREAPP_DIR=$(NETCOREAPP_NAME).$(NETCOREAPP_VERSION)
+
+$(NETCOREAPP_DIR):
+	nuget install $(NETCOREAPP_NAME) -Version $(NETCOREAPP_VERSION) -Source $(NETCOREAPP_FEED)
+
+netcore-System.Native.bc: $(NETCOREAPP_DIR)
+	cp $(NETCOREAPP_DIR)/runtimes/webassembly-wasm/native/System.Native.bc $@
 
 .PHONY: runtime-netcore
 runtime-netcore:
@@ -205,20 +214,14 @@ bcl-netcore:
 
 build-managed: bcl-netcore
 
-# Set COREFX_ROOT to a compatible corefx source repo
-# Apply netcore-corefx.diff
-netcore-System.Native.bc:
-	@if test x$(COREFX_ROOT) == x; then echo "Set COREFX_ROOT."; exit 1; fi
-	cd $(COREFX_ROOT)/src/Native && touch _version.c && cd Unix && mkdir -p build && cd build && source $(TOP)/sdks/builds/toolchains/emsdk/emsdk_env.sh && emcmake cmake "-DEMSCRIPTEN_GENERATE_BITCODE_STATIC_LIBRARIES=1" "-DCMAKE_TOOLCHAIN_FILE=$(TOP)/sdks/builds/toolchains/emsdk/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake" -G Ninja -DCMAKE_BUILD_TYPE=Debug .. && ninja && cp System.Native/System.Native.bc $(PWD)/$@
-
 src/pinvoke-tables-default-netcore.h:
 	mono ../../mcs/class/lib/wasm_tools/wasm-tuner.exe --gen-pinvoke-table System.Native $(NETCOREAPP_DIR)/System.Private.CoreLib.dll $(NETCOREAPP_DIR)/System.Console.dll > $@
 
 samples/hello/bin/Debug/netcoreapp3.0/hello.dll:
-	netcore build samples/hello -f netcoreapp3.0
+	dotnet build samples/hello -f netcoreapp3.0
 
-build-hello-netcore: packager.exe samples/hello/bin/Debug/netcoreapp3.0/hello.dll
-	$(PACKAGER) --debugrt --emscripten-sdkdir=$(EMSCRIPTEN_SDK_DIR) --mono-sdkdir=$(TOP)/sdks/out -appdir=bin/hello-netcore --nobinding --builddir=obj/hello-netcore --framework=netcoreapp3.0 --netcore-sdkdir=$(NETCOREAPP_DIR) --template=runtime-tests.js --linker samples/hello/bin/Debug/netcoreapp3.0/hello.dll
+build-hello-netcore: packager.exe samples/hello/bin/Debug/netcoreapp3.0/hello.dll $(NETCOREAPP_DIR)
+	$(PACKAGER) --debugrt --emscripten-sdkdir=$(EMSCRIPTEN_SDK_DIR) --mono-sdkdir=$(TOP)/sdks/out -appdir=bin/hello-netcore --nobinding --builddir=obj/hello-netcore --framework=netcoreapp3.0 --netcore-sdkdir=$(NETCOREAPP_DIR)/runtimes/webassembly-wasm/lib/netcoreapp3.0 --template=runtime-tests.js --linker samples/hello/bin/Debug/netcoreapp3.0/hello.dll
 	ninja -v -C obj/hello-netcore
 
 bin/hello-netcore/bin/mono.js: build-hello-netcore
@@ -271,7 +274,7 @@ Mono.Cecil.dll: $(TOP)/mcs/class/lib/wasm_tools/Mono.Cecil.dll
 	cp $< $@
 
 # Should use .csproj file and msbuild
-$(PACKAGER): packager.cs Mono.Cecil.dll $(OPTIONS_CS) | build-native
+packager.exe: packager.cs Mono.Cecil.dll $(OPTIONS_CS) | build-native
 	$(CSC) $(CSC_FLAGS) /out:$@ /r:Mono.Cecil.dll packager.cs $(OPTIONS_CS) /r:$(API_REFS)/mscorlib.dll /r:$(API_REFS)/System.dll /r:$(API_REFS)/System.Core.dll
 
 .stamp-build-debug-sample: packager.exe $(WASM_FRAMEWORK)/.stamp-framework sample.dll debug.html runtime.js
@@ -560,6 +563,7 @@ clean: clean-browser-tests
 	$(RM) $(WASM_FRAMEWORK)/WebAssembly.*.dll
 	$(RM) $(WASM_FRAMEWORK)/WebAssembly.*.pdb
 	$(RM) $(WASM_FRAMEWORK)/WebAssembly.*.xml
+	$(RM) netcore-System.Native.bc
 	$(RM) -r builds
 	$(RM) emsdk_env.sh
 	$(RM) .configured

+ 0 - 55
sdks/wasm/netcore-corefx.diff

@@ -1,55 +0,0 @@
-diff --git a/src/Native/Unix/CMakeLists.txt b/src/Native/Unix/CMakeLists.txt
-index f1d6a9ac59..4a8c99e140 100644
---- a/src/Native/Unix/CMakeLists.txt
-+++ b/src/Native/Unix/CMakeLists.txt
-@@ -18,7 +18,7 @@ add_compile_options(-Wno-empty-translation-unit)
- add_compile_options(-Wno-cast-align)
- add_compile_options(-Wno-typedef-redefinition)
- add_compile_options(-Wno-c11-extensions)
--add_compile_options(-fPIC)
-+#add_compile_options(-fPIC)
- add_compile_options(-I${CMAKE_CURRENT_SOURCE_DIR}/Common)
- add_compile_options(-I${CMAKE_CURRENT_BINARY_DIR}/Common)
- add_compile_options(-g)
-@@ -26,7 +26,7 @@ if(CMAKE_C_COMPILER_ID STREQUAL Clang)
-     add_compile_options(-Wthread-safety)
-     add_compile_options(-Wno-thread-safety-analysis)
- endif()
--add_compile_options(-Werror)
-+#add_compile_options(-Werror)
- 
- if(CMAKE_SYSTEM_NAME STREQUAL Emscripten)
-     set(CLR_CMAKE_PLATFORM_WASM 1)
-@@ -95,7 +95,8 @@ else ()
-     message(FATAL_ERROR "Unknown build type. Set CMAKE_BUILD_TYPE to DEBUG or RELEASE.")
- endif ()
- 
--if (APPLE)
-+if(CMAKE_SYSTEM_NAME STREQUAL Emscripten)
-+elseif (APPLE)
-     add_definitions(-D__APPLE_USE_RFC_3542)
- 
-    # We cannot enable "stack-protector-strong" on OS X due to a bug in clang compiler (current version 7.0.2)
-diff --git a/src/Native/Unix/System.Native/pal_networking.c b/src/Native/Unix/System.Native/pal_networking.c
-index 1ece3b6487..638ed7d6cd 100644
---- a/src/Native/Unix/System.Native/pal_networking.c
-+++ b/src/Native/Unix/System.Native/pal_networking.c
-@@ -55,6 +55,7 @@
- #include <ifaddrs.h>
- #endif
- #endif
-+#undef AF_CAN
- #ifdef AF_CAN
- #include <linux/can.h>
- #endif
-@@ -2492,8 +2493,8 @@ static int32_t WaitForSocketEventsInner(int32_t port, SocketEvent* buffer, int32
- }
- 
- #else
--#warning epoll/kqueue not detected; building with stub socket events support
--static const size_t SocketEventBufferElementSize = sizeof(struct pollfd);
-+//#warning epoll/kqueue not detected; building with stub socket events support
-+static const size_t SocketEventBufferElementSize = 0;//sizeof(struct pollfd);
- 
- static SocketEvents GetSocketEvents(int16_t filter, uint16_t flags)
- {

+ 4 - 0
sdks/wasm/packager.cs

@@ -527,6 +527,10 @@ class Driver {
 					Console.Error.WriteLine ("The --netcore-sdkdir= argument is required.");
 					return 1;
 				}
+				if (!Directory.Exists (netcore_sdkdir)) {
+					Console.Error.WriteLine ($"The directory '{netcore_sdkdir}' doesn't exist.");
+					return 1;
+				}
 			} else {
 				Console.Error.WriteLine ("The only valid value for --framework is 'netcoreapp...'");
 				return 1;

+ 7 - 2
sdks/wasm/sdk/Mono.WebAssembly.Runtime.Framework/Mono.WebAssembly.Runtime.csproj

@@ -16,13 +16,18 @@
     <Content Include="..\..\..\wasm\builds\threads-debug\mono.worker.js" PackagePath="mono-wasm-runtime\threads-debug\%(Filename)%(Extension)" Link="mono-wasm-runtime\threads-debug\mono.worker.js" Condition="Exists('..\..\..\wasm\builds\threads-debug\mono.worker.js')" />
     <Content Include="..\..\..\wasm\builds\threads-debug\mono.wasm" PackagePath="mono-wasm-runtime\threads-debug\%(Filename)%(Extension)" Link="mono-wasm-runtime\threads-debug\mono.wasm" Condition="Exists('..\..\..\wasm\builds\threads-debug\mono.wasm')" />
     <Content Include="..\..\..\wasm\builds\threads-debug\mono.wasm.map" PackagePath="mono-wasm-runtime\threads-debug\%(Filename)%(Extension)" Link="mono-wasm-runtime\threads-debug\mono.wasm.map" Condition="Exists('..\..\..\wasm\builds\threads-debug\mono.wasm.map')" />
-    <Content Include="..\..\..\wasm\builds\threads-debug\mono.js.mem" PackagePath="mono-wasm-runtime\threads-debug\%(Filename)%(Extension)" Link="mono-wasm-runtime\threads-debug\mono.js.mem" Condition="Exists('..\..\..\wasm\builds\threads-debug\mono.js.mem')" />
     <Content Include="..\..\..\wasm\builds\release\mono.js" PackagePath="mono-wasm-runtime\release\%(Filename)%(Extension)" Link="mono-wasm-runtime\release\mono.js" />
     <Content Include="..\..\..\wasm\builds\release\mono.wasm" PackagePath="mono-wasm-runtime\release\%(Filename)%(Extension)" Link="mono-wasm-runtime\release\mono.wasm" />
     <Content Include="..\..\..\wasm\builds\threads-release\mono.js" PackagePath="mono-wasm-runtime\threads-release\%(Filename)%(Extension)" Link="mono-wasm-runtime\threads-release\mono.js" Condition="Exists('..\..\..\wasm\builds\threads-release\mono.js')" />
     <Content Include="..\..\..\wasm\builds\threads-release\mono.worker.js" PackagePath="mono-wasm-runtime\threads-release\%(Filename)%(Extension)" Link="mono-wasm-runtime\threads-release\mono.worker.js"  Condition="Exists('..\..\..\wasm\builds\threads-release\mono.worker.js')" />
     <Content Include="..\..\..\wasm\builds\threads-release\mono.wasm" PackagePath="mono-wasm-runtime\threads-release\%(Filename)%(Extension)" Link="mono-wasm-runtime\threads-release\mono.wasm"  Condition="Exists('..\..\..\wasm\builds\threads-release\mono.wasm')" />
-    <Content Include="..\..\..\wasm\builds\threads-release\mono.js.mem" PackagePath="mono-wasm-runtime\threads-release\%(Filename)%(Extension)" Link="mono-wasm-runtime\threads-release\mono.js.mem"  Condition="Exists('..\..\..\wasm\builds\threads-release\mono.js.mem')" />
+
+    <Content Include="..\..\..\wasm\builds\netcore-debug\mono.js" PackagePath="mono-wasm-runtime\netcore-debug\%(Filename)%(Extension)" Link="mono-wasm-runtime\netcore-debug\mono.js" Condition="Exists('..\..\..\wasm\builds\netcore-debug\mono.js')" />
+    <Content Include="..\..\..\wasm\builds\netcore-debug\mono.wasm" PackagePath="mono-wasm-runtime\netcore-debug\%(Filename)%(Extension)" Link="mono-wasm-runtime\netcore-debug\mono.wasm"  Condition="Exists('..\..\..\wasm\builds\netcore-debug\mono.wasm')" />
+
+    <Content Include="..\..\..\wasm\builds\netcore-release\mono.js" PackagePath="mono-wasm-runtime\netcore-release\%(Filename)%(Extension)" Link="mono-wasm-runtime\netcore-release\mono.js" Condition="Exists('..\..\..\wasm\builds\netcore-release\mono.js')" />
+    <Content Include="..\..\..\wasm\builds\netcore-release\mono.wasm" PackagePath="mono-wasm-runtime\netcore-release\%(Filename)%(Extension)" Link="mono-wasm-runtime\netcore-release\mono.wasm"  Condition="Exists('..\..\..\wasm\builds\netcore-release\mono.wasm')" />
+
     <None Update="build\netstandard2.0\Mono.WebAssembly.Runtime.props" PackagePath="build\netstandard2.0\Mono.WebAssembly.Runtime.props" Pack="True" />
   </ItemGroup>
 </Project>