[mkbundle] Fix mapping length (#13061)
[mono-project.git] / sdks / builds / wasm.mk
blob609d45abf79aaa004d3b857c1b36683d1bfc6bc1
1 #emcc has lots of bash'isms
2 SHELL:=/bin/bash
4 EMSCRIPTEN_VERSION=1.38.28
5 EMSCRIPTEN_SDK_DIR=$(TOP)/sdks/builds/toolchains/emsdk
7 $(TOP)/sdks/builds/toolchains/emsdk:
8 git clone https://github.com/juj/emsdk.git $(EMSCRIPTEN_SDK_DIR)
10 .stamp-wasm-checkout-and-update-emsdk: | $(EMSCRIPTEN_SDK_DIR)
11 cd $(TOP)/sdks/builds/toolchains/emsdk && git reset --hard && git clean -xdff && git pull
12 touch $@
14 #This is a weird rule to workaround the circularity of the next rule.
15 #.stamp-wasm-install-and-select-$(EMSCRIPTEN_VERSION) depends on .emscripten and, at the same time, it updates it.
16 #This is designed to force the .stamp target to rerun when a different emscripten version is selected, which causes .emscripten to be updated
17 $(EMSCRIPTEN_SDK_DIR)/.emscripten: | $(EMSCRIPTEN_SDK_DIR)
18 touch $@
20 .stamp-wasm-install-and-select-$(EMSCRIPTEN_VERSION): .stamp-wasm-checkout-and-update-emsdk $(EMSCRIPTEN_SDK_DIR)/.emscripten
21 cd $(TOP)/sdks/builds/toolchains/emsdk && ./emsdk install sdk-$(EMSCRIPTEN_VERSION)-64bit
22 cd $(TOP)/sdks/builds/toolchains/emsdk && ./emsdk activate --embedded sdk-$(EMSCRIPTEN_VERSION)-64bit
23 #cd $(TOP)/sdks/builds/toolchains/emsdk/emscripten/$(EMSCRIPTEN_VERSION) && (patch -N -p1 < $(TOP)/sdks/builds/fix-emscripten-7399.diff; exit 0)
24 touch $@
26 .PHONY: provision-wasm
27 provision-wasm: .stamp-wasm-install-and-select-$(EMSCRIPTEN_VERSION)
29 WASM_RUNTIME_AC_VARS= \
30 ac_cv_func_shm_open_working_with_mmap=no
32 WASM_RUNTIME_CFLAGS=-fexceptions $(if $(RELEASE),-Os -g,-O0 -ggdb3 -fno-omit-frame-pointer)
34 WASM_RUNTIME_CONFIGURE_FLAGS = \
35 --cache-file=$(TOP)/sdks/builds/wasm-runtime-$(CONFIGURATION).config.cache \
36 --prefix=$(TOP)/sdks/out/wasm-runtime-$(CONFIGURATION) \
37 --disable-mcs-build \
38 --disable-nls \
39 --disable-boehm \
40 --disable-btls \
41 --with-lazy-gc-thread-creation=yes \
42 --with-libgc=none \
43 --disable-executables \
44 --disable-support-build \
45 --disable-visibility-hidden \
46 --enable-maintainer-mode \
47 --enable-minimal=ssa,com,jit,reflection_emit_save,portability,assembly_remapping,attach,verifier,full_messages,appdomains,security,sgen_marksweep_conc,sgen_split_nursery,sgen_gc_bridge,logging,remoting,shared_perfcounters,sgen_debug_helpers,soft_debug,interpreter,assert_messages,cleanup,mdb \
48 --host=wasm32 \
49 --enable-llvm-runtime \
50 --enable-icall-export \
51 --disable-icall-tables \
52 --disable-crash-reporting \
53 --with-bitcode=yes \
54 $(if $(ENABLE_CXX),--enable-cxx) \
55 CFLAGS="$(WASM_RUNTIME_CFLAGS)"
57 .stamp-wasm-runtime-toolchain:
58 touch $@
60 .stamp-wasm-runtime-$(CONFIGURATION)-configure: $(TOP)/configure | $(if $(IGNORE_PROVISION_WASM),,provision-wasm)
61 mkdir -p $(TOP)/sdks/builds/wasm-runtime-$(CONFIGURATION)
62 cd $(TOP)/sdks/builds/wasm-runtime-$(CONFIGURATION) && source $(TOP)/sdks/builds/toolchains/emsdk/emsdk_env.sh && emconfigure $(TOP)/configure $(WASM_RUNTIME_AC_VARS) $(WASM_RUNTIME_CONFIGURE_FLAGS)
63 touch $@
65 .PHONY: .stamp-wasm-runtime-configure
66 .stamp-wasm-runtime-configure: .stamp-wasm-runtime-$(CONFIGURATION)-configure
68 .PHONY: build-custom-wasm-runtime
69 build-custom-wasm-runtime:
70 source $(TOP)/sdks/builds/toolchains/emsdk/emsdk_env.sh && $(MAKE) -C wasm-runtime-$(CONFIGURATION)
72 .PHONY: setup-custom-wasm-runtime
73 setup-custom-wasm-runtime:
74 mkdir -p $(TOP)/sdks/out/wasm-runtime-$(CONFIGURATION)
76 .PHONY: package-wasm-runtime
77 package-wasm-runtime:
78 $(MAKE) -C $(TOP)/sdks/builds/wasm-runtime-$(CONFIGURATION)/mono install
80 .PHONY: clean-wasm-runtime
81 clean-wasm-runtime:
82 rm -rf .stamp-wasm-runtime-toolchain .stamp-wasm-runtime-$(CONFIGURATION)-configure $(TOP)/sdks/builds/wasm-runtime-$(CONFIGURATION) $(TOP)/sdks/builds/wasm-runtime-$(CONFIGURATION).config.cache $(TOP)/sdks/out/wasm-runtime-$(CONFIGURATION)
84 $(eval $(call TargetTemplate,wasm,runtime))
86 .PHONY: configure-wasm
87 configure-wasm: configure-wasm-runtime
89 .PHONY: build-wasm
90 build-wasm: build-wasm-runtime
92 .PHONY: archive-wasm
93 archive-wasm: package-wasm-runtime
95 wasm_ARCHIVE += wasm-runtime-$(CONFIGURATION)
98 # Parameters
99 # $(1): target
100 # $(2): host arch
101 # $(3): target arch
102 # $(4): device target
103 # $(5): llvm
104 # $(6): offsets dumper abi
105 define WasmCrossTemplate
107 _wasm-$(1)_OFFSETS_DUMPER_ARGS=--emscripten-sdk="$$(EMSCRIPTEN_SDK_DIR)/emscripten/$$(EMSCRIPTEN_VERSION)"
109 _wasm-$(1)_CONFIGURE_FLAGS= \
110 --disable-boehm \
111 --disable-btls \
112 --disable-mcs-build \
113 --disable-nls \
114 --disable-support-build \
115 --enable-maintainer-mode \
116 --enable-minimal=appdomains,com,remoting \
117 --enable-icall-symbol-map \
118 --with-cooperative-gc=no \
119 --enable-hybrid-suspend=no \
120 --with-cross-offsets=wasm32-unknown-none.h
122 $$(eval $$(call CrossRuntimeTemplate,wasm,$(1),$$(if $$(filter $$(UNAME),Darwin),$(2)-apple-darwin10,$$(if $$(filter $$(UNAME),Linux),$(2)-linux-gnu,$$(error "Unknown UNAME='$$(UNAME)'"))),$(3)-unknown-none,$(4),$(5),$(6)))
124 endef
126 # 64 bit cross compiler
127 $(eval $(call WasmCrossTemplate,cross,x86_64,wasm32,runtime,llvm-llvm64,wasm32-unknown-unknown))
130 # Parameters
131 # $(1): target
132 # $(2): host arch
133 # $(3): target arch
134 # $(4): device target
135 # $(5): llvm
136 # $(6): offsets dumper abi
137 define WasmCrossMXETemplate
139 _wasm-$(1)_OFFSETS_DUMPER_ARGS=--emscripten-sdk="$(EMSCRIPTEN_SDK_DIR)/emscripten/$(EMSCRIPTEN_VERSION)"
141 _wasm-$(1)_PATH=$$(MXE_PREFIX)/bin
143 _wasm-$(1)_AR=$$(MXE_PREFIX)/bin/$(2)-w64-mingw32$$(if $$(filter $$(UNAME),Darwin),.static)-ar
144 _wasm-$(1)_AS=$$(MXE_PREFIX)/bin/$(2)-w64-mingw32$$(if $$(filter $$(UNAME),Darwin),.static)-as
145 _wasm-$(1)_CC=$$(MXE_PREFIX)/bin/$(2)-w64-mingw32$$(if $$(filter $$(UNAME),Darwin),.static)-gcc
146 _wasm-$(1)_CXX=$$(MXE_PREFIX)/bin/$(2)-w64-mingw32$$(if $$(filter $$(UNAME),Darwin),.static)-g++
147 _wasm-$(1)_DLLTOOL=$$(MXE_PREFIX)/bin/$(2)-w64-mingw32$$(if $$(filter $$(UNAME),Darwin),.static)-dlltool
148 _wasm-$(1)_LD=$$(MXE_PREFIX)/bin/$(2)-w64-mingw32$$(if $$(filter $$(UNAME),Darwin),.static)-ld
149 _wasm-$(1)_OBJDUMP=$$(MXE_PREFIX)/bin/$(2)-w64-mingw32$$(if $$(filter $$(UNAME),Darwin),.static)-objdump
150 _wasm-$(1)_RANLIB=$$(MXE_PREFIX)/bin/$(2)-w64-mingw32$$(if $$(filter $$(UNAME),Darwin),.static)-ranlib
151 _wasm-$(1)_STRIP=$$(MXE_PREFIX)/bin/$(2)-w64-mingw32$$(if $$(filter $$(UNAME),Darwin),.static)-strip
153 _wasm-$(1)_CFLAGS= \
154 $$(if $$(RELEASE),,-DDEBUG_CROSS) \
155 -static \
156 -static-libgcc
158 _wasm-$(1)_CXXFLAGS= \
159 $$(if $$(RELEASE),,-DDEBUG_CROSS) \
160 -static \
161 -static-libgcc \
162 -static-libstdc++
164 _wasm-$(1)_LDFLAGS= \
165 -static \
166 -static-libgcc
168 _wasm-$(1)_CONFIGURE_FLAGS= \
169 --disable-boehm \
170 --disable-btls \
171 --disable-mcs-build \
172 --disable-nls \
173 --disable-nls \
174 --disable-support-build \
175 --enable-maintainer-mode \
176 --enable-minimal=appdomains,com,remoting \
177 --with-tls=pthread \
178 --enable-icall-symbol-map \
179 --with-cross-offsets=wasm32-unknown-none.h
181 .stamp-wasm-$(1)-$$(CONFIGURATION)-configure: | $$(if $$(IGNORE_PROVISION_MXE),,provision-mxe)
183 $$(eval $$(call CrossRuntimeTemplate,wasm,$(1),$(2)-w64-mingw32$$(if $$(filter $(UNAME),Darwin),.static),$(3)-unknown-none,$(4),$(5),$(6)))
185 endef
187 $(eval $(call WasmCrossMXETemplate,cross-win,i686,wasm32,runtime,llvm-llvmwin32,wasm32-unknown-unknown))
189 $(eval $(call BclTemplate,wasm,wasm wasm_tools,wasm))