]> git.lizzy.rs Git - rust.git/blob - mk/rt.mk
Ignore tests broken by failing on ICE
[rust.git] / mk / rt.mk
1 # Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 # file at the top-level directory of this distribution and at
3 # http://rust-lang.org/COPYRIGHT.
4 #
5 # Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 # http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 # <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 # option. This file may not be copied, modified, or distributed
9 # except according to those terms.
10
11 ################################################################################
12 # Native libraries built as part of the rust build process
13 #
14 # This portion of the rust build system is meant to keep track of native
15 # dependencies and how to build them. It is currently required that all native
16 # dependencies are built as static libraries, as slinging around dynamic
17 # libraries isn't exactly the most fun thing to do.
18 #
19 # This section should need minimal modification to add new libraries. The
20 # relevant variables are:
21 #
22 #   NATIVE_LIBS
23 #       This is a list of all native libraries which are built as part of the
24 #       build process. It will build all libraries into RT_OUTPUT_DIR with the
25 #       appropriate name of static library as dictated by the target platform
26 #
27 #   NATIVE_DEPS_<lib>
28 #       This is a list of files relative to the src/rt directory which are
29 #       needed to build the native library. Each file will be compiled to an
30 #       object file, and then all the object files will be assembled into an
31 #       archive (static library). The list contains files of any extension
32 #
33 # If adding a new library, you should update the NATIVE_LIBS list, and then list
34 # the required files below it. The list of required files is a list of files
35 # that's per-target so you're allowed to conditionally add files based on the
36 # target.
37 ################################################################################
38 NATIVE_LIBS := rustrt sundown uv_support morestack miniz context_switch
39
40 # $(1) is the target triple
41 define NATIVE_LIBRARIES
42
43 NATIVE_DEPS_sundown_$(1) := sundown/src/autolink.c \
44                         sundown/src/buffer.c \
45                         sundown/src/stack.c \
46                         sundown/src/markdown.c \
47                         sundown/html/houdini_href_e.c \
48                         sundown/html/houdini_html_e.c \
49                         sundown/html/html_smartypants.c \
50                         sundown/html/html.c
51 NATIVE_DEPS_uv_support_$(1) := rust_uv.c
52 NATIVE_DEPS_miniz_$(1) = miniz.c
53 NATIVE_DEPS_rustrt_$(1) := rust_builtin.c \
54                         rust_android_dummy.c \
55                         rust_test_helpers.c \
56                         rust_try.ll \
57                         arch/$$(HOST_$(1))/record_sp.S
58 NATIVE_DEPS_morestack_$(1) := arch/$$(HOST_$(1))/morestack.S
59 NATIVE_DEPS_context_switch_$(1) := \
60                         arch/$$(HOST_$(1))/_context.S
61
62 ################################################################################
63 # You shouldn't find it that necessary to edit anything below this line.
64 ################################################################################
65
66 # While we're defining the native libraries for each target, we define some
67 # common rules used to build files for various targets.
68
69 RT_OUTPUT_DIR_$(1) := $(1)/rt
70
71 $$(RT_OUTPUT_DIR_$(1))/%.o: $(S)src/rt/%.ll $$(MKFILE_DEPS) \
72             $$(LLVM_CONFIG_$$(CFG_BUILD))
73         @mkdir -p $$(@D)
74         @$$(call E, compile: $$@)
75         $$(Q)$$(LLC_$$(CFG_BUILD)) $$(CFG_LLC_FLAGS_$(1)) \
76             -filetype=obj -mtriple=$(1) -relocation-model=pic -o $$@ $$<
77
78 $$(RT_OUTPUT_DIR_$(1))/%.o: $(S)src/rt/%.c $$(MKFILE_DEPS)
79         @mkdir -p $$(@D)
80         @$$(call E, compile: $$@)
81         $$(Q)$$(call CFG_COMPILE_C_$(1), $$@, \
82                 -I $$(S)src/rt/sundown/src -I $$(S)src/rt/sundown/html \
83                 -I $$(S)src/libuv/include -I $$(S)src/rt \
84                  $$(RUNTIME_CFLAGS_$(1))) $$<
85
86 $$(RT_OUTPUT_DIR_$(1))/%.o: $(S)src/rt/%.S $$(MKFILE_DEPS) \
87             $$(LLVM_CONFIG_$$(CFG_BUILD))
88         @mkdir -p $$(@D)
89         @$$(call E, compile: $$@)
90         $$(Q)$$(call CFG_ASSEMBLE_$(1),$$@,$$<)
91 endef
92
93 $(foreach target,$(CFG_TARGET),$(eval $(call NATIVE_LIBRARIES,$(target))))
94
95 # A macro for devining how to build third party libraries listed above (based
96 # on their dependencies).
97 #
98 # $(1) is the target
99 # $(2) is the lib name
100 define THIRD_PARTY_LIB
101
102 OBJS_$(2)_$(1) := $$(NATIVE_DEPS_$(2)_$(1):%=$$(RT_OUTPUT_DIR_$(1))/%)
103 OBJS_$(2)_$(1) := $$(OBJS_$(2)_$(1):.c=.o)
104 OBJS_$(2)_$(1) := $$(OBJS_$(2)_$(1):.cpp=.o)
105 OBJS_$(2)_$(1) := $$(OBJS_$(2)_$(1):.ll=.o)
106 OBJS_$(2)_$(1) := $$(OBJS_$(2)_$(1):.S=.o)
107 NATIVE_$(2)_$(1) := $$(call CFG_STATIC_LIB_NAME_$(1),$(2))
108 $$(RT_OUTPUT_DIR_$(1))/$$(NATIVE_$(2)_$(1)): $$(OBJS_$(2)_$(1))
109         @$$(call E, link: $$@)
110         $$(Q)$$(AR_$(1)) rcs $$@ $$^
111
112 endef
113
114 $(foreach target,$(CFG_TARGET),                                     \
115  $(eval $(call RUNTIME_RULES,$(target))))
116 $(foreach lib,$(NATIVE_LIBS),                                       \
117  $(foreach target,$(CFG_TARGET),                                    \
118   $(eval $(call THIRD_PARTY_LIB,$(target),$(lib)))))
119
120
121 ################################################################################
122 # Building third-party targets with external build systems
123 #
124 # The only current member of this section is libuv, but long ago this used to
125 # also be occupied by jemalloc. This location is meant for dependencies which
126 # have external build systems. It is still assumed that the output of each of
127 # these steps is a static library in the correct location.
128 ################################################################################
129
130 define DEF_LIBUV_ARCH_VAR
131   LIBUV_ARCH_$(1) = $$(subst i386,ia32,$$(subst x86_64,x64,$$(HOST_$(1))))
132 endef
133 $(foreach t,$(CFG_TARGET),$(eval $(call DEF_LIBUV_ARCH_VAR,$(t))))
134
135 ifdef CFG_ENABLE_FAST_MAKE
136 LIBUV_DEPS := $(S)/.gitmodules
137 else
138 LIBUV_DEPS := $(wildcard \
139               $(S)src/libuv/* \
140               $(S)src/libuv/*/* \
141               $(S)src/libuv/*/*/* \
142               $(S)src/libuv/*/*/*/*)
143 endif
144
145 LIBUV_NO_LOAD = run-benchmarks.target.mk run-tests.target.mk \
146                 uv_dtrace_header.target.mk uv_dtrace_provider.target.mk
147
148 export PYTHONPATH := $(PYTHONPATH):$(S)src/gyp/pylib
149
150 define DEF_THIRD_PARTY_TARGETS
151
152 # $(1) is the target triple
153
154 ifeq ($$(CFG_WINDOWSY_$(1)), 1)
155   LIBUV_OSTYPE_$(1) := win
156 else ifeq ($(OSTYPE_$(1)), apple-darwin)
157   LIBUV_OSTYPE_$(1) := mac
158 else ifeq ($(OSTYPE_$(1)), unknown-freebsd)
159   LIBUV_OSTYPE_$(1) := freebsd
160 else ifeq ($(OSTYPE_$(1)), linux-androideabi)
161   LIBUV_OSTYPE_$(1) := android
162   LIBUV_ARGS_$(1) := PLATFORM=android host=android OS=linux
163 else
164   LIBUV_OSTYPE_$(1) := linux
165 endif
166
167 LIBUV_NAME_$(1) := $$(call CFG_STATIC_LIB_NAME_$(1),uv)
168 LIBUV_DIR_$(1) := $$(RT_OUTPUT_DIR_$(1))/libuv
169 LIBUV_LIB_$(1) := $$(RT_OUTPUT_DIR_$(1))/$$(LIBUV_NAME_$(1))
170
171 LIBUV_MAKEFILE_$(1) := $$(CFG_BUILD_DIR)$$(RT_OUTPUT_DIR_$(1))/libuv/Makefile
172
173 LIBUV_STAMP_$(1) = $$(LIBUV_DIR_$(1))/libuv-auto-clean-stamp
174
175 $$(LIBUV_STAMP_$(1)): $(S)src/rt/libuv-auto-clean-trigger
176         $$(Q)rm -rf $$(LIBUV_DIR_$(1))
177         $$(Q)mkdir -p $$(@D)
178         touch $$@
179
180 # libuv triggers a few warnings on some platforms
181 LIBUV_CFLAGS_$(1) := $(subst -Werror,,$(CFG_GCCISH_CFLAGS_$(1)))
182
183 $$(LIBUV_MAKEFILE_$(1)): $$(LIBUV_DEPS) $$(MKFILE_DEPS) $$(LIBUV_STAMP_$(1))
184         (cd $(S)src/libuv/ && \
185          $$(CFG_PYTHON) ./gyp_uv.py -f make -Dtarget_arch=$$(LIBUV_ARCH_$(1)) \
186            -D ninja \
187            -DOS=$$(LIBUV_OSTYPE_$(1)) \
188            -Goutput_dir=$$(@D) --generator-output $$(@D))
189         touch $$@
190
191 # Windows has a completely different build system for libuv because of mingw. In
192 # theory when we support msvc then we should be using gyp's msvc output instead
193 # of mingw's makefile for windows
194 ifdef CFG_WINDOWSY_$(1)
195 $$(LIBUV_LIB_$(1)): $$(LIBUV_DEPS) $$(MKFILE_DEPS)
196         $$(Q)$$(MAKE) -C $$(S)src/libuv -f Makefile.mingw \
197                 LDFLAGS="$$(CFG_GCCISH_LINK_FLAGS_$(1))" \
198                 CC="$$(CC_$(1)) $$(LIBUV_CFLAGS_$(1)) $$(SNAP_DEFINES)" \
199                 CXX="$$(CXX_$(1))" \
200                 AR="$$(AR_$(1))" \
201                 V=$$(VERBOSE)
202         $$(Q)cp $$(S)src/libuv/libuv.a $$@
203 else
204 $$(LIBUV_LIB_$(1)): $$(LIBUV_DIR_$(1))/Release/libuv.a $$(MKFILE_DEPS)
205         $$(Q)cp $$< $$@
206 $$(LIBUV_DIR_$(1))/Release/libuv.a: $$(LIBUV_DEPS) $$(LIBUV_MAKEFILE_$(1)) \
207                                     $$(MKFILE_DEPS)
208         $$(Q)$$(MAKE) -C $$(LIBUV_DIR_$(1)) \
209                 CFLAGS="$$(LIBUV_CFLAGS_$(1)) $$(SNAP_DEFINES)" \
210                 LDFLAGS="$$(CFG_GCCISH_LINK_FLAGS_$(1))" \
211                 CC="$$(CC_$(1))" \
212                 CXX="$$(CXX_$(1))" \
213                 AR="$$(AR_$(1))" \
214                 $$(LIBUV_ARGS_$(1)) \
215                 BUILDTYPE=Release \
216                 NO_LOAD="$$(LIBUV_NO_LOAD)" \
217                 V=$$(VERBOSE)
218         $$(Q)touch $$@
219
220 endif
221
222 ################################################################################
223 # compiler-rt
224 ################################################################################
225
226 ifdef CFG_ENABLE_FAST_MAKE
227 COMPRT_DEPS := $(S)/.gitmodules
228 else
229 COMPRT_DEPS := $(wildcard \
230               $(S)src/compiler-rt/* \
231               $(S)src/compiler-rt/*/* \
232               $(S)src/compiler-rt/*/*/* \
233               $(S)src/compiler-rt/*/*/*/*)
234 endif
235
236 COMPRT_NAME_$(1) := $$(call CFG_STATIC_LIB_NAME_$(1),compiler-rt)
237 COMPRT_LIB_$(1) := $$(RT_OUTPUT_DIR_$(1))/$$(COMPRT_NAME_$(1))
238 COMPRT_BUILD_DIR_$(1) := $$(RT_OUTPUT_DIR_$(1))/compiler-rt
239
240 $$(COMPRT_LIB_$(1)): $$(COMPRT_DEPS) $$(MKFILE_DEPS)
241         @$$(call E, make: compiler-rt)
242         $$(Q)$$(MAKE) -C "$(S)src/compiler-rt" \
243                 ProjSrcRoot="$(S)src/compiler-rt" \
244                 ProjObjRoot="$$(abspath $$(COMPRT_BUILD_DIR_$(1)))" \
245                 CC="$$(CC_$(1))" \
246                 AR="$$(AR_$(1))" \
247                 RANLIB="$$(AR_$(1)) s" \
248                 CFLAGS="$$(CFG_GCCISH_CFLAGS_$(1))" \
249                 TargetTriple=$(1) \
250                 triple-builtins
251         $$(Q)cp $$(COMPRT_BUILD_DIR_$(1))/triple/builtins/libcompiler_rt.a $$(COMPRT_LIB_$(1))
252
253 ################################################################################
254 # libbacktrace
255 #
256 # We use libbacktrace on linux to get symbols in backtraces, but only on linux.
257 # Elsewhere we use other system utilities, so this library is only built on
258 # linux.
259 ################################################################################
260
261 BACKTRACE_NAME_$(1) := $$(call CFG_STATIC_LIB_NAME_$(1),backtrace)
262 BACKTRACE_LIB_$(1) := $$(RT_OUTPUT_DIR_$(1))/$$(BACKTRACE_NAME_$(1))
263 BACKTRACE_BUILD_DIR_$(1) := $$(RT_OUTPUT_DIR_$(1))/libbacktrace
264
265 ifeq ($$(findstring darwin,$$(OSTYPE_$(1))),darwin)
266
267 # We don't use this on platforms that aren't linux-based, so just make the file
268 # available, the compilation of libstd won't actually build it.
269 $$(BACKTRACE_LIB_$(1)):
270         touch $$@
271
272 else
273 ifeq ($$(CFG_WINDOWSY_$(1)),1)
274 $$(BACKTRACE_LIB_$(1)):
275         touch $$@
276 else
277
278 ifdef CFG_ENABLE_FAST_MAKE
279 BACKTRACE_DEPS := $(S)/.gitmodules
280 else
281 BACKTRACE_DEPS := $(wildcard $(S)src/libbacktrace/*)
282 endif
283
284 # We need to export CFLAGS because otherwise it doesn't pick up cross compile
285 # builds. If libbacktrace doesn't realize this, it will attempt to read 64-bit
286 # elf headers when compiled for a 32-bit system, yielding blank backtraces.
287 #
288 # This also removes the -Werror flag specifically to prevent errors during
289 # configuration.
290 #
291 # Down below you'll also see echos into the config.h generated by the
292 # ./configure script. This is done to force libbacktrace to *not* use the
293 # atomic/sync functionality because it pulls in unnecessary dependencies and we
294 # never use it anyway.
295 $$(BACKTRACE_BUILD_DIR_$(1))/Makefile: \
296                 export CFLAGS:=$$(CFG_GCCISH_CFLAGS_$(1):-Werror=) \
297                                 -fno-stack-protector
298 $$(BACKTRACE_BUILD_DIR_$(1))/Makefile: export CC:=$$(CC_$(1))
299 $$(BACKTRACE_BUILD_DIR_$(1))/Makefile: export AR:=$$(AR_$(1))
300 $$(BACKTRACE_BUILD_DIR_$(1))/Makefile: export RANLIB:=$$(AR_$(1)) s
301 $$(BACKTRACE_BUILD_DIR_$(1))/Makefile: $$(BACKTRACE_DEPS) $$(MKFILE_DEPS)
302         $$(Q)rm -rf $$(BACKTRACE_BUILD_DIR_$(1))
303         $$(Q)mkdir -p $$(BACKTRACE_BUILD_DIR_$(1))
304         $$(Q)(cd $$(BACKTRACE_BUILD_DIR_$(1)) && \
305               $(S)src/libbacktrace/configure --target=$(1) --host=$(CFG_BUILD))
306         $$(Q)echo '#undef HAVE_ATOMIC_FUNCTIONS' >> \
307               $$(BACKTRACE_BUILD_DIR_$(1))/config.h
308         $$(Q)echo '#undef HAVE_SYNC_FUNCTIONS' >> \
309               $$(BACKTRACE_BUILD_DIR_$(1))/config.h
310
311 $$(BACKTRACE_LIB_$(1)): $$(BACKTRACE_BUILD_DIR_$(1))/Makefile $$(MKFILE_DEPS)
312         @$$(call E, make: libbacktrace)
313         $$(Q)$$(MAKE) -C $$(BACKTRACE_BUILD_DIR_$(1)) \
314                 INCDIR=$(S)src/libbacktrace
315         $$(Q)cp $$(BACKTRACE_BUILD_DIR_$(1))/.libs/libbacktrace.a $$@
316
317 endif # endif for windowsy
318 endif # endif for darwin
319
320 endef
321
322 # Instantiate template for all stages/targets
323 $(foreach target,$(CFG_TARGET), \
324      $(eval $(call DEF_THIRD_PARTY_TARGETS,$(target))))