[corlib] Import FileSystemInfo and family from CoreFX (#11342)
[mono-project.git] / sdks / wasm / Makefile
blob3362fac0601c07c63cd4070e0178eb04e86a5866
1 TOP=$(realpath $(CURDIR)/../..)
2 -include $(TOP)/sdks/Make.config
3 -include $(TOP)/mcs/build/config.make
4 include $(TOP)/sdks/versions.mk
5 include $(TOP)/sdks/paths.mk
7 all: build
9 MAKEFLAGS += --no-builtin-rules
10 #emcc has lots of bash'isms
11 SHELL:=/bin/bash
13 #Use either 'release' or 'debug' dependending on what you need
14 DRIVER_CONF=release
17 EMSCRIPTEN_SDKDIR=$(TOP)/sdks/builds/toolchains/emsdk
18 EMCC=source $(TOP)/sdks/builds/toolchains/emsdk/emsdk_env.sh && emcc
19 WASM_BCL_DIR=$(TOP)/sdks/out/wasm-bcl/wasm
20 WASM_RUNTIME_DIR=$(TOP)/sdks/out/wasm-runtime-release
21 MINI_PATH=$(TOP)/mono/mini
22 CSC?= MONO_PATH=$(TOP)/mcs/class/lib/build $(TOP)/sdks/builds/bcl/runtime/mono-wrapper $(CSC_LOCATION)
23 CSC_FLAGS := /debug:portable /noconfig /nostdlib /nologo /langversion:latest
24 API_REFS=$(TOP)/external/binary-reference-assemblies/v4.6
26 MINI_TEST_FILES= \
27 TestDriver.cs \
28 aot-tests.cs \
29 arrays.cs \
30 basic-calls.cs \
31 basic-float.cs \
32 basic-long.cs \
33 basic-math.cs \
34 basic.cs \
35 exceptions.cs \
36 generics.cs \
37 gshared.cs \
38 objects.cs \
39 builtin-types.cs \
40 devirtualization.cs \
41 mixed.cs \
42 gc-test.cs
44 APP_SOURCES = \
45 main.cs \
46 incrementalrunner.cs
48 BINDING_TEST_SOURCES = \
49 bindings-test.cs
51 MINI_TEST_SOURCES = $(patsubst %,$(MINI_PATH)/%,$(MINI_TEST_FILES))
53 UNAME := $(shell uname -s)
54 ifeq ($(UNAME),Linux)
55 JSVU_OS=linux64
56 endif
57 ifeq ($(UNAME),Darwin)
58 JSVU_OS=mac64
59 endif
60 .PHONY: jsup
62 jsup:
63 node node_modules/jsvu/cli.js --os=$(JSVU_OS) --engines=all
65 .stamp-jsvu:
66 npm install
67 node node_modules/jsvu/cli.js --os=$(JSVU_OS) --engines=all
68 touch $@
70 .PHONY: toolchain
71 toolchain: .stamp-jsvu
73 driver.o: driver.c
74 $(EMCC) -g -Os -s WASM=1 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN=1 -s "BINARYEN_TRAP_MODE='clamp'" -s ALIASING_FUNCTION_POINTERS=0 -I$(WASM_RUNTIME_DIR)/include/mono-2.0 driver.c -c -o driver.o
76 debug/:
77 mkdir -p $@
78 release/:
79 mkdir -p $@
81 MONO_LIBS = $(TOP)/sdks/out/wasm-runtime-release/lib/libmono-ee-interp.a $(TOP)/sdks/out/wasm-runtime-release/lib/libmonosgen-2.0.a $(TOP)/sdks/out/wasm-runtime-release/lib/libmono-ilgen.a $(TOP)/sdks/out/wasm-runtime-release/lib/libmono-icall-table.a
83 debug/.stamp-build: driver.o library_mono.js binding_support.js dotnet_support.js $(TOP)/sdks/out/wasm-runtime-release/lib/libmonosgen-2.0.a | debug/
84 $(EMCC) -g4 -Os -s WASM=1 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN=1 -s "BINARYEN_TRAP_MODE='clamp'" -s ALIASING_FUNCTION_POINTERS=0 -s ASSERTIONS=1 --js-library library_mono.js --js-library binding_support.js --js-library dotnet_support.js driver.o $(MONO_LIBS) -o debug/mono.js -s NO_EXIT_RUNTIME=1 -s "EXTRA_EXPORTED_RUNTIME_METHODS=['ccall', 'FS_createPath', 'FS_createDataFile', 'cwrap', 'setValue', 'getValue', 'UTF8ToString']"
85 touch $@
87 # Notice that release/.stamp-build depends on debug/.stamp-build. This is the case as emcc is believed to not work well with parallel builds.
88 release/.stamp-build: driver.o library_mono.js binding_support.js dotnet_support.js $(TOP)/sdks/out/wasm-runtime-release/lib/libmonosgen-2.0.a debug/.stamp-build | release/
89 $(EMCC) -Oz --llvm-opts 2 --llvm-lto 1 -s WASM=1 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN=1 -s "BINARYEN_TRAP_MODE='clamp'" -s ALIASING_FUNCTION_POINTERS=0 --js-library library_mono.js --js-library binding_support.js --js-library dotnet_support.js driver.o $(MONO_LIBS) -o release/mono.js -s NO_EXIT_RUNTIME=1 -s "EXPORTED_FUNCTIONS=['_putchar']" -s "EXTRA_EXPORTED_RUNTIME_METHODS=['ccall', 'FS_createPath', 'FS_createDataFile', 'cwrap', 'setValue', 'getValue', 'UTF8ToString']"
90 touch $@
92 build-native: debug/.stamp-build release/.stamp-build
94 do-runtime:
95 make -j4 -C ../builds package-wasm-runtime
96 make -j4 -C ../builds package-wasm-bcl
97 make build-native
99 runtime:
100 $(MAKE) -C ../builds package-wasm-runtime
102 cross:
103 $(MAKE) -C ../builds package-wasm-cross
105 bcl:
106 $(MAKE) -C ../builds package-wasm-bcl
108 BCL_DEPS=/r:$(WASM_BCL_DIR)/mscorlib.dll /r:$(WASM_BCL_DIR)/System.Core.dll /r:$(WASM_BCL_DIR)/System.dll /r:$(WASM_BCL_DIR)/System.Net.Http.dll
110 main.exe: $(APP_SOURCES)
111 $(CSC) $(CSC_FLAGS) /unsafe -out:$@ $(BCL_DEPS) /r:$(WASM_BCL_DIR)/nunitlite.dll $(APP_SOURCES)
113 mini_tests.dll: $(MINI_TEST_SOURCES) mini-test-runner.cs
114 $(CSC) $(CSC_FLAGS) /unsafe -target:library -out:$@ -define:__MOBILE__,ARCH_32 $(BCL_DEPS) /r:$(WASM_BCL_DIR)/nunitlite.dll $(MINI_TEST_SOURCES) mini-test-runner.cs
116 binding_tests.dll: WebAssembly.Bindings.dll $(BINDING_TEST_SOURCES)
117 $(CSC) $(CSC_FLAGS) /unsafe -target:library -out:$@ /r:WebAssembly.Bindings.dll $(BCL_DEPS) /r:$(WASM_BCL_DIR)/nunitlite.dll $(BINDING_TEST_SOURCES)
119 WebAssembly.Bindings.dll: bindings.cs
120 $(CSC) $(CSC_FLAGS) /target:library -out:$@ /r:$(WASM_BCL_DIR)/mscorlib.dll bindings.cs
122 WebAssembly.Net.Http.dll: WebAssembly.Bindings.dll WasmHttpMessageHandler.cs
123 $(CSC) $(CSC_FLAGS) /target:library -out:$@ /r:WebAssembly.Bindings.dll /r:$(WASM_BCL_DIR)/mscorlib.dll /r:$(WASM_BCL_DIR)/System.dll /r:$(WASM_BCL_DIR)/System.Core.dll /r:$(WASM_BCL_DIR)/System.Net.dll /r:$(WASM_BCL_DIR)/System.Net.Http.dll WasmHttpMessageHandler.cs
125 Simple.Dependency.dll: dependency.cs
126 $(CSC) $(CSC_FLAGS) /target:library -out:$@ /r:$(WASM_BCL_DIR)/mscorlib.dll /r:$(WASM_BCL_DIR)/System.Core.dll dependency.cs
128 sample.dll: Simple.Dependency.dll sample.cs WebAssembly.Bindings.dll WebAssembly.Net.Http.dll
129 $(CSC) $(CSC_FLAGS) /target:library -out:$@ /r:Simple.Dependency.dll /r:$(WASM_BCL_DIR)/mscorlib.dll /r:$(WASM_BCL_DIR)/System.dll /r:$(WASM_BCL_DIR)/System.Core.dll /r:$(WASM_BCL_DIR)/System.Net.Http.dll /r:WebAssembly.Bindings.dll /r:WebAssembly.Net.Http.dll sample.cs
131 OPTIONS_CS = $(TOP)/mcs/class/Mono.Options/Mono.Options/Options.cs
133 Mono.Cecil.dll: $(TOP)/mcs/class/lib/wasm_tools/Mono.Cecil.dll
134 cp $< $@
136 # Should use .csproj file and msbuild
137 packager.exe: packager.cs Mono.Cecil.dll $(OPTIONS_CS)
138 $(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
140 .stamp-build-debug-sample: $(DRIVER_CONF)/.stamp-build packager.exe WebAssembly.Bindings.dll WebAssembly.Net.Http.dll sample.dll debug.html runtime.js
141 mono packager.exe -debug -out=debug_sample sample.dll
142 cp debug.html debug_sample
143 touch $@
145 TEST_ASSEMBLIES = $(WASM_BCL_DIR)/nunitlite.dll $(WASM_BCL_DIR)/tests/wasm_corlib_test.dll $(WASM_BCL_DIR)/tests/wasm_System_test.dll $(WASM_BCL_DIR)/tests/wasm_System.Core_test.dll
147 .stamp-build-test-suite: $(DRIVER_CONF)/.stamp-build packager.exe WebAssembly.Bindings.dll binding_tests.dll WebAssembly.Net.Http.dll mini_tests.dll main.exe runtime-tests.js
148 mono --debug packager.exe --template=runtime-tests.js --appdir=bin/test-suite --builddir=obj/test-suite binding_tests.dll WebAssembly.Net.Http.dll mini_tests.dll main.exe $(TEST_ASSEMBLIES)
149 ninja -v -C obj/test-suite
150 touch $@
152 # For development
153 aot-sample: packager.exe mini_tests.dll main.exe runtime.js bug.exe
154 mono packager.exe --emscripten-sdkdir=$(EMSCRIPTEN_SDKDIR) --mono-sdkdir=$(TOP)/sdks/out -appdir=bin/aot-sample --nobinding --builddir=obj/aot-sample --aot --template=runtime-tests.js bug.exe
155 ninja -v -C obj/aot-sample
157 do-aot-sample: aot-sample
158 (cd bin/aot-sample && $(SM) runtime.js --run bug.exe)
160 build-aot-mini: packager.exe mini_tests.dll main.exe runtime.js
161 mono packager.exe --emscripten-sdkdir=$(EMSCRIPTEN_SDKDIR) --mono-sdkdir=$(TOP)/sdks/out -appdir=bin/aot-mini --nobinding --builddir=obj/aot-mini --aot --template=runtime-tests.js mini_tests.dll
162 ninja -v -C obj/aot-mini
164 check-aot-mini run-aot-mini: build-aot-mini
165 (cd bin/aot-mini && $(SM) runtime.js --regression mini_tests.dll)
168 # Parameters:
169 # $(1) - make target suffix
170 # $(2) - test assembly filename
171 # $(3) - main.exe argument
172 define AotTestTemplate
174 build-aot-$(1): packager.exe runtime-tests.js main.exe WebAssembly.Bindings.dll binding_tests.dll $$(WASM_BCL_DIR)/nunitlite.dll $$(WASM_BCL_DIR)/tests/$(2)
175 mono packager.exe --emscripten-sdkdir=$$(EMSCRIPTEN_SDKDIR) --mono-sdkdir=$$(TOP)/sdks/out -appdir=bin/aot-$(1) --nobinding --builddir=obj/aot-$(1) --aot --template=runtime-tests.js main.exe WebAssembly.Bindings.dll binding_tests.dll $$(WASM_BCL_DIR)/tests/$(2)
176 ninja -v -C obj/aot-$(1)
178 clean-aot-$(1):
179 $(RM) -r obj/aot-$(1) bin/aot-$(1)
181 check-aot-$(1) run-aot-$(1): build-aot-$(1)
182 (cd bin/aot-$(1) && $$(SM) runtime.js --exclude StackWalks,StaticAotNotWorking,StaticLinkedAotNotWorking $(3))
184 endef
186 $(eval $(call AotTestTemplate,corlib,wasm_corlib_test.dll,corlib))
187 $(eval $(call AotTestTemplate,System.Core,wasm_System.Core_test.dll,system-core))
188 $(eval $(call AotTestTemplate,System,wasm_System_test.dll,system))
190 AOT_TEST_SUITES=corlib System.Core
192 build-aot-all:
193 $(MAKE) $(patsubst %,build-aot-%,$(AOT_TEST_SUITES))
195 run-aot-all:
196 for suite in System.Core; do make run-aot-$$suite || exit 1; done
198 build-debug-sample: .stamp-build-debug-sample
200 build-test-suite: .stamp-build-test-suite
202 build-managed: build-debug-sample build-test-suite
204 build-dbg-proxy:
205 dotnet build ProxyDriver
207 build-framework-nuget:
208 nuget pack WebAssembly.Framework.nuspec
210 build: build-native build-managed
212 CHAKRA=~/.jsvu/ch
213 D8=~/.jsvu/v8
214 JSC=~/.jsvu/jsc
215 SM=~/.jsvu/sm
217 run-ch-%: toolchain build-test-suite
218 (cd bin/test-suite && $(CHAKRA) runtime.js -args $*)
220 run-v8-%: toolchain build-test-suite
221 (cd bin/test-suite && $(D8) --expose_wasm runtime.js -- $*)
223 run-jsc-%: toolchain build-test-suite
224 (cd bin/test-suite && $(JSC) runtime.js -- $*)
226 run-sm-%: toolchain build-test-suite
227 (cd bin/test-suite && $(SM) runtime.js $*)
229 # Leaving JSC for now cuz it aborts when it encounters wasm
230 run-all-%:
231 make -C . run-ch-$*
232 make -C . run-v8-$*
233 make -C . run-sm-$*
234 make -C . run-jsc-$*
236 clean:
238 package: build build-dbg-proxy build-framework-nuget
239 rm -rf tmp
240 mkdir tmp
241 mkdir tmp/wasm-bcl
242 mkdir tmp/wasm-bcl/wasm
243 cp -r $(TOP)/sdks/out/wasm-bcl/wasm/* tmp/wasm-bcl/wasm/
244 rm -rf tmp/wasm-bcl/wasm/bare
245 rm -rf tmp/wasm-bcl/wasm/secxml
246 rm -rf tmp/wasm-bcl/wasm/tests
247 rm -rf tmp/wasm-bcl/wasm/corlib.unsafe.dll.tmp
248 cp driver.c tmp/
249 cp $(MONO_LIBS) tmp/
250 cp library_mono.js tmp/
251 cp binding_support.js tmp/
252 cp dotnet_support.js tmp/
253 cp -r debug tmp/
254 cp -r release tmp/
255 rm tmp/debug/.stamp-build
256 rm tmp/release/.stamp-build
257 cp bindings.cs tmp
258 mkdir tmp/framework
259 cp WebAssembly.Bindings.dll tmp/framework
260 cp WebAssembly.Bindings.pdb tmp/framework
261 cp WasmHttpMessageHandler.cs tmp
262 cp WebAssembly.Net.Http.dll tmp/framework
263 cp WebAssembly.Net.Http.pdb tmp/framework
264 cp WebAssembly.Framework.0.1.0-alpha.nupkg tmp/framework
265 cp sample.html tmp/
266 cp sample.cs tmp/
267 cp dependency.cs tmp/
268 cp README.md tmp/
269 cp server.py tmp/
270 cp Mono.Cecil.dll tmp/
271 cp $(OPTIONS_CS) tmp/
272 cp packager.exe tmp/
273 cp runtime.js tmp/
274 cp Mono.WebAssembly.DebuggerProxy/bin/Debug/netstandard2.0/Mono.WebAssembly.DebuggerProxy.dll tmp/
275 cp Mono.WebAssembly.DebuggerProxy/bin/Debug/netstandard2.0/Mono.WebAssembly.DebuggerProxy.pdb tmp/
276 mkdir tmp/dbg-proxy
277 cp -r ProxyDriver/bin/Debug/netcoreapp2.1/ tmp/dbg-proxy/
278 mkdir tmp/docs
279 cp -r ./docs/ tmp/docs/
280 (cd tmp; zip -r9 ../mono-wasm-$(shell git rev-parse --short HEAD).zip .)
281 rm -rf tmp
283 serve:
284 python server.py
286 canary:
287 /Applications/Google\ Chrome\ Canary.app/Contents/MacOS/Google\ Chrome\ Canary --remote-debugging-port=9222
289 check-aot: do-aot-sample