]> git.lizzy.rs Git - rust.git/blob - src/libcompiler_builtins/build.rs
More methods for str boxes.
[rust.git] / src / libcompiler_builtins / build.rs
1 // Copyright 2016 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 //! Compiles the `compiler-rt` library, or at least the builtins part of it.
12 //!
13 //! Note that while compiler-rt has a build system associated with it, we
14 //! specifically don't use it here. The compiler-rt build system, written in
15 //! CMake, is actually *very* difficult to work with in terms of getting it to
16 //! compile on all the relevant platforms we want it to compile on. In the end
17 //! it became so much pain to work with local patches, work around the oddities
18 //! of the build system, etc, that we're just building everything by hand now.
19 //!
20 //! In general compiler-rt is just a bunch of intrinsics that are in practice
21 //! *very* stable. We just need to make sure that all the relevant functions and
22 //! such are compiled somewhere and placed in an object file somewhere.
23 //! Eventually, these should all be written in Rust!
24 //!
25 //! So below you'll find a listing of every single file in the compiler-rt repo
26 //! that we're compiling. We just reach in and compile with the `gcc` crate
27 //! which should have all the relevant flags and such already configured.
28 //!
29 //! The risk here is that if we update compiler-rt we may need to compile some
30 //! new intrinsics, but to be honest we surely don't use all of the intrinsics
31 //! listed below today so the likelihood of us actually needing a new intrinsic
32 //! is quite low. The failure case is also just that someone reports a link
33 //! error (if any) and then we just add it to the list. Overall, that cost is
34 //! far far less than working with compiler-rt's build system over time.
35
36 extern crate build_helper;
37 extern crate gcc;
38
39 use std::collections::BTreeMap;
40 use std::env;
41 use std::path::Path;
42 use build_helper::native_lib_boilerplate;
43
44 struct Sources {
45     // SYMBOL -> PATH TO SOURCE
46     map: BTreeMap<&'static str, &'static str>,
47 }
48
49 impl Sources {
50     fn new() -> Sources {
51         Sources { map: BTreeMap::new() }
52     }
53
54     fn extend(&mut self, sources: &[&'static str]) {
55         // NOTE Some intrinsics have both a generic implementation (e.g.
56         // `floatdidf.c`) and an arch optimized implementation
57         // (`x86_64/floatdidf.c`). In those cases, we keep the arch optimized
58         // implementation and discard the generic implementation. If we don't
59         // and keep both implementations, the linker will yell at us about
60         // duplicate symbols!
61         for &src in sources {
62             let symbol = Path::new(src).file_stem().unwrap().to_str().unwrap();
63             if src.contains("/") {
64                 // Arch-optimized implementation (preferred)
65                 self.map.insert(symbol, src);
66             } else {
67                 // Generic implementation
68                 if !self.map.contains_key(symbol) {
69                     self.map.insert(symbol, src);
70                 }
71             }
72         }
73     }
74 }
75
76 fn main() {
77     let target = env::var("TARGET").expect("TARGET was not set");
78
79     // Emscripten's runtime includes all the builtins
80     if target.contains("emscripten") {
81         return;
82     }
83
84     // Can't reuse `sources` list for the freshness check becuse it doesn't contain header files.
85     let native = match native_lib_boilerplate("compiler-rt", "compiler-rt", "compiler-rt", ".") {
86         Ok(native) => native,
87         _ => return,
88     };
89
90     let cfg = &mut gcc::Config::new();
91     cfg.out_dir(&native.out_dir);
92
93     if target.contains("msvc") {
94         // Don't pull in extra libraries on MSVC
95         cfg.flag("/Zl");
96
97         // Emulate C99 and C++11's __func__ for MSVC prior to 2013 CTP
98         cfg.define("__func__", Some("__FUNCTION__"));
99     } else {
100         // Turn off various features of gcc and such, mostly copying
101         // compiler-rt's build system already
102         cfg.flag("-fno-builtin");
103         cfg.flag("-fvisibility=hidden");
104         // Accepted practice on Solaris is to never omit frame pointer so that
105         // system observability tools work as expected.  In addition, at least
106         // on Solaris, -fomit-frame-pointer on sparcv9 appears to generate
107         // references to data outside of the current stack frame.  A search of
108         // the gcc bug database provides a variety of issues surrounding
109         // -fomit-frame-pointer on non-x86 platforms.
110         if !target.contains("solaris") && !target.contains("sparc") {
111             cfg.flag("-fomit-frame-pointer");
112         }
113         cfg.flag("-ffreestanding");
114         cfg.define("VISIBILITY_HIDDEN", None);
115     }
116
117     let mut sources = Sources::new();
118     sources.extend(&["absvdi2.c",
119                      "absvsi2.c",
120                      "adddf3.c",
121                      "addsf3.c",
122                      "addvdi3.c",
123                      "addvsi3.c",
124                      "apple_versioning.c",
125                      "ashldi3.c",
126                      "ashrdi3.c",
127                      "clzdi2.c",
128                      "clzsi2.c",
129                      "cmpdi2.c",
130                      "comparedf2.c",
131                      "comparesf2.c",
132                      "ctzdi2.c",
133                      "ctzsi2.c",
134                      "divdc3.c",
135                      "divdf3.c",
136                      "divdi3.c",
137                      "divmoddi4.c",
138                      "divmodsi4.c",
139                      "divsc3.c",
140                      "divsf3.c",
141                      "divsi3.c",
142                      "divxc3.c",
143                      "extendsfdf2.c",
144                      "extendhfsf2.c",
145                      "ffsdi2.c",
146                      "fixdfdi.c",
147                      "fixdfsi.c",
148                      "fixsfdi.c",
149                      "fixsfsi.c",
150                      "fixunsdfdi.c",
151                      "fixunsdfsi.c",
152                      "fixunssfdi.c",
153                      "fixunssfsi.c",
154                      "fixunsxfdi.c",
155                      "fixunsxfsi.c",
156                      "fixxfdi.c",
157                      "floatdidf.c",
158                      "floatdisf.c",
159                      "floatdixf.c",
160                      "floatsidf.c",
161                      "floatsisf.c",
162                      "floatundidf.c",
163                      "floatundisf.c",
164                      "floatundixf.c",
165                      "floatunsidf.c",
166                      "floatunsisf.c",
167                      "int_util.c",
168                      "lshrdi3.c",
169                      "moddi3.c",
170                      "modsi3.c",
171                      "muldc3.c",
172                      "muldf3.c",
173                      "muldi3.c",
174                      "mulodi4.c",
175                      "mulosi4.c",
176                      "muloti4.c",
177                      "mulsc3.c",
178                      "mulsf3.c",
179                      "mulvdi3.c",
180                      "mulvsi3.c",
181                      "mulxc3.c",
182                      "negdf2.c",
183                      "negdi2.c",
184                      "negsf2.c",
185                      "negvdi2.c",
186                      "negvsi2.c",
187                      "paritydi2.c",
188                      "paritysi2.c",
189                      "popcountdi2.c",
190                      "popcountsi2.c",
191                      "powidf2.c",
192                      "powisf2.c",
193                      "powixf2.c",
194                      "subdf3.c",
195                      "subsf3.c",
196                      "subvdi3.c",
197                      "subvsi3.c",
198                      "truncdfhf2.c",
199                      "truncdfsf2.c",
200                      "truncsfhf2.c",
201                      "ucmpdi2.c",
202                      "udivdi3.c",
203                      "udivmoddi4.c",
204                      "udivmodsi4.c",
205                      "udivsi3.c",
206                      "umoddi3.c",
207                      "umodsi3.c"]);
208
209     if !target.contains("ios") {
210         sources.extend(&["absvti2.c",
211                          "addvti3.c",
212                          "ashlti3.c",
213                          "ashrti3.c",
214                          "clzti2.c",
215                          "cmpti2.c",
216                          "ctzti2.c",
217                          "divti3.c",
218                          "ffsti2.c",
219                          "fixdfti.c",
220                          "fixsfti.c",
221                          "fixunsdfti.c",
222                          "fixunssfti.c",
223                          "fixunsxfti.c",
224                          "fixxfti.c",
225                          "floattidf.c",
226                          "floattisf.c",
227                          "floattixf.c",
228                          "floatuntidf.c",
229                          "floatuntisf.c",
230                          "floatuntixf.c",
231                          "lshrti3.c",
232                          "modti3.c",
233                          "multi3.c",
234                          "mulvti3.c",
235                          "negti2.c",
236                          "negvti2.c",
237                          "parityti2.c",
238                          "popcountti2.c",
239                          "subvti3.c",
240                          "ucmpti2.c",
241                          "udivmodti4.c",
242                          "udivti3.c",
243                          "umodti3.c"]);
244     }
245
246     if target.contains("apple") {
247         sources.extend(&["atomic_flag_clear.c",
248                          "atomic_flag_clear_explicit.c",
249                          "atomic_flag_test_and_set.c",
250                          "atomic_flag_test_and_set_explicit.c",
251                          "atomic_signal_fence.c",
252                          "atomic_thread_fence.c"]);
253     }
254
255     if target.contains("msvc") {
256         if target.contains("x86_64") {
257             sources.extend(&["x86_64/floatdidf.c", "x86_64/floatdisf.c", "x86_64/floatdixf.c"]);
258         }
259     } else {
260         if !target.contains("freebsd") && !target.contains("netbsd") {
261             sources.extend(&["gcc_personality_v0.c"]);
262         }
263
264         if target.contains("x86_64") {
265             sources.extend(&["x86_64/chkstk.S",
266                              "x86_64/chkstk2.S",
267                              "x86_64/floatdidf.c",
268                              "x86_64/floatdisf.c",
269                              "x86_64/floatdixf.c",
270                              "x86_64/floatundidf.S",
271                              "x86_64/floatundisf.S",
272                              "x86_64/floatundixf.S"]);
273         }
274
275         if target.contains("i386") || target.contains("i586") || target.contains("i686") {
276             sources.extend(&["i386/ashldi3.S",
277                              "i386/ashrdi3.S",
278                              "i386/chkstk.S",
279                              "i386/chkstk2.S",
280                              "i386/divdi3.S",
281                              "i386/floatdidf.S",
282                              "i386/floatdisf.S",
283                              "i386/floatdixf.S",
284                              "i386/floatundidf.S",
285                              "i386/floatundisf.S",
286                              "i386/floatundixf.S",
287                              "i386/lshrdi3.S",
288                              "i386/moddi3.S",
289                              "i386/muldi3.S",
290                              "i386/udivdi3.S",
291                              "i386/umoddi3.S"]);
292         }
293     }
294
295     if target.contains("arm") && !target.contains("ios") {
296         sources.extend(&["arm/aeabi_cdcmp.S",
297                          "arm/aeabi_cdcmpeq_check_nan.c",
298                          "arm/aeabi_cfcmp.S",
299                          "arm/aeabi_cfcmpeq_check_nan.c",
300                          "arm/aeabi_dcmp.S",
301                          "arm/aeabi_div0.c",
302                          "arm/aeabi_drsub.c",
303                          "arm/aeabi_fcmp.S",
304                          "arm/aeabi_frsub.c",
305                          "arm/aeabi_idivmod.S",
306                          "arm/aeabi_ldivmod.S",
307                          "arm/aeabi_memcmp.S",
308                          "arm/aeabi_memcpy.S",
309                          "arm/aeabi_memmove.S",
310                          "arm/aeabi_memset.S",
311                          "arm/aeabi_uidivmod.S",
312                          "arm/aeabi_uldivmod.S",
313                          "arm/bswapdi2.S",
314                          "arm/bswapsi2.S",
315                          "arm/clzdi2.S",
316                          "arm/clzsi2.S",
317                          "arm/comparesf2.S",
318                          "arm/divmodsi4.S",
319                          "arm/divsi3.S",
320                          "arm/modsi3.S",
321                          "arm/switch16.S",
322                          "arm/switch32.S",
323                          "arm/switch8.S",
324                          "arm/switchu8.S",
325                          "arm/sync_synchronize.S",
326                          "arm/udivmodsi4.S",
327                          "arm/udivsi3.S",
328                          "arm/umodsi3.S"]);
329     }
330
331     if target.contains("armv7") {
332         sources.extend(&["arm/sync_fetch_and_add_4.S",
333                          "arm/sync_fetch_and_add_8.S",
334                          "arm/sync_fetch_and_and_4.S",
335                          "arm/sync_fetch_and_and_8.S",
336                          "arm/sync_fetch_and_max_4.S",
337                          "arm/sync_fetch_and_max_8.S",
338                          "arm/sync_fetch_and_min_4.S",
339                          "arm/sync_fetch_and_min_8.S",
340                          "arm/sync_fetch_and_nand_4.S",
341                          "arm/sync_fetch_and_nand_8.S",
342                          "arm/sync_fetch_and_or_4.S",
343                          "arm/sync_fetch_and_or_8.S",
344                          "arm/sync_fetch_and_sub_4.S",
345                          "arm/sync_fetch_and_sub_8.S",
346                          "arm/sync_fetch_and_umax_4.S",
347                          "arm/sync_fetch_and_umax_8.S",
348                          "arm/sync_fetch_and_umin_4.S",
349                          "arm/sync_fetch_and_umin_8.S",
350                          "arm/sync_fetch_and_xor_4.S",
351                          "arm/sync_fetch_and_xor_8.S"]);
352     }
353
354     if target.contains("eabihf") {
355         sources.extend(&["arm/adddf3vfp.S",
356                          "arm/addsf3vfp.S",
357                          "arm/divdf3vfp.S",
358                          "arm/divsf3vfp.S",
359                          "arm/eqdf2vfp.S",
360                          "arm/eqsf2vfp.S",
361                          "arm/extendsfdf2vfp.S",
362                          "arm/fixdfsivfp.S",
363                          "arm/fixsfsivfp.S",
364                          "arm/fixunsdfsivfp.S",
365                          "arm/fixunssfsivfp.S",
366                          "arm/floatsidfvfp.S",
367                          "arm/floatsisfvfp.S",
368                          "arm/floatunssidfvfp.S",
369                          "arm/floatunssisfvfp.S",
370                          "arm/gedf2vfp.S",
371                          "arm/gesf2vfp.S",
372                          "arm/gtdf2vfp.S",
373                          "arm/gtsf2vfp.S",
374                          "arm/ledf2vfp.S",
375                          "arm/lesf2vfp.S",
376                          "arm/ltdf2vfp.S",
377                          "arm/ltsf2vfp.S",
378                          "arm/muldf3vfp.S",
379                          "arm/mulsf3vfp.S",
380                          "arm/negdf2vfp.S",
381                          "arm/negsf2vfp.S",
382                          "arm/nedf2vfp.S",
383                          "arm/nesf2vfp.S",
384                          "arm/restore_vfp_d8_d15_regs.S",
385                          "arm/save_vfp_d8_d15_regs.S",
386                          "arm/subdf3vfp.S",
387                          "arm/subsf3vfp.S",
388                          "arm/truncdfsf2vfp.S",
389                          "arm/unorddf2vfp.S",
390                          "arm/unordsf2vfp.S"]);
391     }
392
393     if target.contains("aarch64") {
394         sources.extend(&["comparetf2.c",
395                          "extenddftf2.c",
396                          "extendsftf2.c",
397                          "fixtfdi.c",
398                          "fixtfsi.c",
399                          "fixtfti.c",
400                          "fixunstfdi.c",
401                          "fixunstfsi.c",
402                          "fixunstfti.c",
403                          "floatditf.c",
404                          "floatsitf.c",
405                          "floatunditf.c",
406                          "floatunsitf.c",
407                          "multc3.c",
408                          "trunctfdf2.c",
409                          "trunctfsf2.c"]);
410     }
411
412     for src in sources.map.values() {
413         cfg.file(Path::new("../compiler-rt/lib/builtins").join(src));
414     }
415
416     cfg.compile("libcompiler-rt.a");
417 }