]> git.lizzy.rs Git - rust.git/blob - src/etc/mklldeps.py
Unignore u128 test for stage 0,1
[rust.git] / src / etc / mklldeps.py
1 # Copyright 2013-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 import os
12 import sys
13 import subprocess
14
15 f = open(sys.argv[1], 'wb')
16
17 components = sys.argv[2].split() # splits on whitespace
18 enable_static = sys.argv[3]
19 llvm_config = sys.argv[4]
20 stdcpp_name = sys.argv[5]
21 use_libcpp = sys.argv[6]
22
23 f.write("""// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
24 // file at the top-level directory of this distribution and at
25 // http://rust-lang.org/COPYRIGHT.
26 //
27 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
28 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
29 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
30 // option. This file may not be copied, modified, or distributed
31 // except according to those terms.
32
33 // WARNING: THIS IS A GENERATED FILE, DO NOT MODIFY
34 //          take a look at src/etc/mklldeps.py if you're interested
35 """)
36
37
38 def run(args):
39     proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
40     out, err = proc.communicate()
41
42     if err:
43         print("failed to run llvm_config: args = `{}`".format(args))
44         print(err)
45         sys.exit(1)
46     return out
47
48 def runErr(args):
49     proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
50     out, err = proc.communicate()
51
52     if err:
53         return False, out
54     else:
55         return True, out
56
57 f.write("\n")
58
59 args = [llvm_config, '--shared-mode']
60 args.extend(components)
61 llvm_shared, out = runErr(args)
62 if llvm_shared:
63     llvm_shared = 'shared' in out
64
65 # LLVM libs
66 args = [llvm_config, '--libs', '--system-libs']
67 args.extend(components)
68 out = run(args)
69 for lib in out.strip().replace("\n", ' ').split(' '):
70     if len(lib) == 0:
71         continue
72     # in some cases we get extra spaces in between libs so ignore those
73     if len(lib) == 1 and lib == ' ':
74         continue
75     # not all libs strictly follow -lfoo, on Bitrig, there is -pthread
76     if lib[0:2] == '-l':
77         lib = lib.strip()[2:]
78     elif lib[0] == '-':
79         lib = lib.strip()[1:]
80     # If this actually points at a literal file then we're on MSVC which now
81     # prints full paths, so get just the name of the library and strip off the
82     # trailing ".lib"
83     elif os.path.exists(lib):
84         lib = os.path.basename(lib)[:-4]
85     elif lib[-4:] == '.lib':
86         lib = lib[:-4]
87     f.write("#[link(name = \"" + lib + "\"")
88     if not llvm_shared and 'LLVM' in lib:
89         f.write(", kind = \"static\"")
90     f.write(")]\n")
91
92 # LLVM ldflags
93 out = run([llvm_config, '--ldflags'])
94 for lib in out.strip().split(' '):
95     if lib[:2] == "-l":
96         f.write("#[link(name = \"" + lib[2:] + "\")]\n")
97
98 # C++ runtime library
99 out = run([llvm_config, '--cxxflags'])
100 if enable_static == '1':
101     assert('stdlib=libc++' not in out)
102     f.write("#[link(name = \"" + stdcpp_name + "\", kind = \"static\")]\n")
103 else:
104     # Note that we use `cfg_attr` here because on MSVC the C++ standard library
105     # is not c++ or stdc++, but rather the linker takes care of linking the
106     # right standard library.
107     if use_libcpp != "0" or 'stdlib=libc++' in out:
108         f.write("#[cfg_attr(not(target_env = \"msvc\"), link(name = \"c++\"))]\n")
109     else:
110         f.write("#[cfg_attr(not(target_env = \"msvc\"), link(name = \"" + stdcpp_name + "\"))]\n")
111
112 # Attach everything to an extern block
113 f.write("extern {}\n")