Line 0
Link Here
|
|
|
1 |
upstream version as of 20190907 (mainly for this patch https://bugzilla.mozilla.org/show_bug.cgi?id=1560700) |
2 |
|
3 |
|
4 |
--- build/moz.configure/rust.configure 2019-08-27 03:31:51.000000000 +0200 |
5 |
+++ build/moz.configure/rust.configure 2019-09-07 17:17:45.964128000 +0200 |
6 |
@@ -41,7 +41,6 @@ def unwrap_rustup(prog, name): |
7 |
# "+stable" file. We'll examine the error output to try and distinguish |
8 |
# between failing rustup and failing rustc. |
9 |
@depends(prog, dependable(name)) |
10 |
- @imports('subprocess') |
11 |
@imports(_from='__builtin__', _import='open') |
12 |
@imports('os') |
13 |
def unwrap(prog, name): |
14 |
@@ -96,6 +95,7 @@ def rustc_info(rustc): |
15 |
version=Version(info.get('release', '0')), |
16 |
commit=info.get('commit-hash', 'unknown'), |
17 |
host=info['host'], |
18 |
+ llvm_version=Version(info.get('LLVM version', '0')), |
19 |
) |
20 |
|
21 |
set_config('RUSTC_VERSION', depends(rustc_info)(lambda info: str(info.version))) |
22 |
@@ -138,11 +138,10 @@ def rust_compiler(rustc_info, cargo_info, build_projec |
23 |
or by directly running the installer from https://rustup.rs/ |
24 |
''')) |
25 |
if build_project == 'tools/crashreporter': |
26 |
- rustc_min_version = Version('1.22.0') |
27 |
- cargo_min_version = Version('0.23.0') |
28 |
+ rustc_min_version = Version('1.31.0') |
29 |
else: |
30 |
rustc_min_version = Version('1.35.0') |
31 |
- cargo_min_version = rustc_min_version |
32 |
+ cargo_min_version = rustc_min_version |
33 |
|
34 |
version = rustc_info.version |
35 |
if version < rustc_min_version: |
36 |
@@ -185,41 +184,34 @@ def rust_compiler(rustc_info, cargo_info, build_projec |
37 |
|
38 |
|
39 |
@depends(rustc, when=rust_compiler) |
40 |
+@imports(_from='__builtin__', _import='ValueError') |
41 |
def rust_supported_targets(rustc): |
42 |
out = check_cmd_output(rustc, '--print', 'target-list').splitlines() |
43 |
- # The os in the triplets used by rust may match the same OSes, in which |
44 |
- # case we need to check the raw_os instead. |
45 |
- per_os = {} |
46 |
- ambiguous = set() |
47 |
- per_raw_os = {} |
48 |
+ data = {} |
49 |
for t in out: |
50 |
- t = split_triplet(t, allow_unknown=True) |
51 |
- endianness = t.endianness |
52 |
- if t.cpu.startswith('thumb') and endianness not in ('big', 'little'): |
53 |
- endianness = 'little' |
54 |
- key = (t.cpu, endianness, t.os) |
55 |
- if key in per_os: |
56 |
- previous = per_os[key] |
57 |
- per_raw_os[(previous.cpu, previous.endianness, |
58 |
- previous.raw_os)] = previous |
59 |
- del per_os[key] |
60 |
- ambiguous.add(key) |
61 |
- if key in ambiguous: |
62 |
- raw_os = t.raw_os |
63 |
- # split_triplet will return a raw_os of 'androideabi' for |
64 |
- # rust targets in the form cpu-linux-androideabi, but what |
65 |
- # we get from the build system is linux-androideabi, so |
66 |
- # normalize. |
67 |
- if raw_os == 'androideabi': |
68 |
- raw_os = 'linux-androideabi' |
69 |
- per_raw_os[(t.cpu, endianness, raw_os)] = t |
70 |
- else: |
71 |
- per_os[key] = t |
72 |
- return namespace(per_os=per_os, per_raw_os=per_raw_os) |
73 |
+ try: |
74 |
+ info = split_triplet(t) |
75 |
+ except ValueError: |
76 |
+ if t.startswith('thumb'): |
77 |
+ cpu, rest = t.split('-', 1) |
78 |
+ retry = '-'.join(('arm', rest)) |
79 |
+ elif t.endswith('-windows-msvc'): |
80 |
+ retry = t[:-len('windows-msvc')] + 'mingw32' |
81 |
+ elif t.endswith('-windows-gnu'): |
82 |
+ retry = t[:-len('windows-gnu')] + 'mingw32' |
83 |
+ else: |
84 |
+ continue |
85 |
+ try: |
86 |
+ info = split_triplet(retry) |
87 |
+ except ValueError: |
88 |
+ continue |
89 |
+ key = (info.cpu, info.endianness, info.os) |
90 |
+ data.setdefault(key, []).append(namespace(rust_target=t, target=info)) |
91 |
+ return data |
92 |
|
93 |
|
94 |
@template |
95 |
-def rust_triple_alias(host_or_target): |
96 |
+def rust_triple_alias(host_or_target, host_or_target_c_compiler): |
97 |
"""Template defining the alias used for rustc's --target flag. |
98 |
`host_or_target` is either `host` or `target` (the @depends functions |
99 |
from init.configure). |
100 |
@@ -228,11 +220,10 @@ def rust_triple_alias(host_or_target): |
101 |
|
102 |
host_or_target_str = {host: 'host', target: 'target'}[host_or_target] |
103 |
|
104 |
- @depends(rustc, host_or_target, c_compiler, rust_supported_targets, |
105 |
- arm_target, when=rust_compiler) |
106 |
+ @depends(rustc, host_or_target, host_or_target_c_compiler, |
107 |
+ rust_supported_targets, arm_target, when=rust_compiler) |
108 |
@checking('for rust %s triplet' % host_or_target_str) |
109 |
@imports('os') |
110 |
- @imports('subprocess') |
111 |
@imports(_from='mozbuild.configure.util', _import='LineIO') |
112 |
@imports(_from='mozbuild.shellutil', _import='quote') |
113 |
@imports(_from='tempfile', _import='mkstemp') |
114 |
@@ -248,41 +239,104 @@ def rust_triple_alias(host_or_target): |
115 |
# munging to get the correct option to rustc. |
116 |
# We correlate the autoconf-derived targets with the list of targets |
117 |
# rustc gives us with --print target-list. |
118 |
- if host_or_target.kernel == 'WINNT': |
119 |
- if compiler_info.type in ('gcc', 'clang'): |
120 |
- host_or_target_os = 'windows-gnu' |
121 |
- else: |
122 |
- host_or_target_os = 'windows-msvc' |
123 |
- host_or_target_raw_os = host_or_target_os |
124 |
- else: |
125 |
- host_or_target_os = host_or_target.os |
126 |
- host_or_target_raw_os = host_or_target.raw_os |
127 |
+ candidates = rust_supported_targets.get( |
128 |
+ (host_or_target.cpu, host_or_target.endianness, host_or_target.os), []) |
129 |
|
130 |
- if host_or_target.cpu == 'arm' and arm_target.arm_arch == 7 and \ |
131 |
- arm_target.fpu == 'neon' and arm_target.thumb2: |
132 |
- host_or_target_cpus = ('thumbv7neon', host_or_target.cpu) |
133 |
- else: |
134 |
- host_or_target_cpus = (host_or_target.cpu,) |
135 |
+ def find_candidate(candidates): |
136 |
+ if len(candidates) == 1: |
137 |
+ return candidates[0].rust_target |
138 |
+ elif not candidates: |
139 |
+ return None |
140 |
|
141 |
- for host_or_target_cpu in host_or_target_cpus: |
142 |
- rustc_target = rust_supported_targets.per_os.get( |
143 |
- (host_or_target_cpu, host_or_target.endianness, host_or_target_os)) |
144 |
- if rustc_target: |
145 |
- break |
146 |
+ # We have multiple candidates. There are two cases where we can try to |
147 |
+ # narrow further down using extra information from the build system. |
148 |
+ # - For windows targets, correlate with the C compiler type |
149 |
+ if host_or_target.kernel == 'WINNT': |
150 |
+ if compiler_info.type in ('gcc', 'clang'): |
151 |
+ suffix = 'windows-gnu' |
152 |
+ else: |
153 |
+ suffix = 'windows-msvc' |
154 |
+ narrowed = [c for c in candidates if c.rust_target.endswith('-{}'.format(suffix))] |
155 |
+ if len(narrowed) == 1: |
156 |
+ return narrowed[0].rust_target |
157 |
+ elif narrowed: |
158 |
+ candidates = narrowed |
159 |
|
160 |
- rustc_target = rust_supported_targets.per_raw_os.get( |
161 |
- (host_or_target_cpu, host_or_target.endianness, |
162 |
- host_or_target_raw_os)) |
163 |
- if rustc_target: |
164 |
- break |
165 |
+ # - For arm targets, correlate with arm_target |
166 |
+ # we could be more thorough with the supported rust targets, but they |
167 |
+ # don't support OSes that are supported to build Gecko anyways. |
168 |
+ # Also, sadly, the only interface to check the rust target cpu features |
169 |
+ # is --print target-spec-json, and it's unstable, so we have to rely on |
170 |
+ # our own knowledge of what each arm target means. |
171 |
+ if host_or_target.cpu == 'arm' and host_or_target.endianness == 'little': |
172 |
+ prefixes = [] |
173 |
+ if arm_target.arm_arch >= 7: |
174 |
+ if arm_target.thumb2 and arm_target.fpu == 'neon': |
175 |
+ prefixes.append('thumbv7neon') |
176 |
+ if arm_target.thumb2: |
177 |
+ prefixes.append('thumbv7a') |
178 |
+ prefixes.append('armv7') |
179 |
+ if arm_target.arm_arch >= 6: |
180 |
+ prefixes.append('armv6') |
181 |
+ if host_or_target.os != 'Android': |
182 |
+ # arm-* rust targets are armv6... except arm-linux-androideabi |
183 |
+ prefixes.append('arm') |
184 |
+ if arm_target.arm_arch >= 5: |
185 |
+ prefixes.append('armv5te') |
186 |
+ if host_or_target.os == 'Android': |
187 |
+ # arm-* rust targets are armv6... except arm-linux-androideabi |
188 |
+ prefixes.append('arm') |
189 |
+ if arm_target.arm_arch >= 4: |
190 |
+ prefixes.append('armv4t') |
191 |
+ # rust freebsd targets are the only ones that don't have a 'hf' suffix |
192 |
+ # for hard-float. Technically, that means if the float abi ever is not |
193 |
+ # hard-float, this will pick a wrong target, but since rust only |
194 |
+ # supports hard-float, let's assume that means freebsd only support |
195 |
+ # hard-float. |
196 |
+ if arm_target.float_abi == 'hard' and host_or_target.os != 'FreeBSD': |
197 |
+ suffix = 'hf' |
198 |
+ else: |
199 |
+ suffix = '' |
200 |
+ for p in prefixes: |
201 |
+ for c in candidates: |
202 |
+ if c.rust_target.startswith('{}-'.format(p)) and \ |
203 |
+ c.rust_target.endswith(suffix): |
204 |
+ return c.rust_target |
205 |
|
206 |
+ # See if we can narrow down on the exact alias |
207 |
+ narrowed = [c for c in candidates if c.target.alias == host_or_target.alias] |
208 |
+ if len(narrowed) == 1: |
209 |
+ return narrowed[0].rust_target |
210 |
+ elif narrowed: |
211 |
+ candidates = narrowed |
212 |
+ |
213 |
+ # See if we can narrow down with the raw OS |
214 |
+ narrowed = [c for c in candidates if c.target.raw_os == host_or_target.raw_os] |
215 |
+ if len(narrowed) == 1: |
216 |
+ return narrowed[0].rust_target |
217 |
+ elif narrowed: |
218 |
+ candidates = narrowed |
219 |
+ |
220 |
+ # See if we can narrow down with the raw OS and raw CPU |
221 |
+ narrowed = [ |
222 |
+ c for c in candidates |
223 |
+ if c.target.raw_os == host_or_target.raw_os and |
224 |
+ c.target.raw_cpu == host_or_target.raw_cpu |
225 |
+ ] |
226 |
+ if len(narrowed) == 1: |
227 |
+ return narrowed[0].rust_target |
228 |
+ |
229 |
+ return None |
230 |
+ |
231 |
+ rustc_target = find_candidate(candidates) |
232 |
+ |
233 |
if rustc_target is None: |
234 |
die("Don't know how to translate {} for rustc".format( |
235 |
host_or_target.alias)) |
236 |
|
237 |
# Check to see whether our rustc has a reasonably functional stdlib |
238 |
# for our chosen target. |
239 |
- target_arg = '--target=' + rustc_target.alias |
240 |
+ target_arg = '--target=' + rustc_target |
241 |
in_fd, in_path = mkstemp(prefix='conftest', suffix='.rs') |
242 |
out_fd, out_path = mkstemp(prefix='conftest', suffix='.rlib') |
243 |
os.close(out_fd) |
244 |
@@ -310,7 +364,7 @@ def rust_triple_alias(host_or_target): |
245 |
a rust std library for that target installed. Try: |
246 |
|
247 |
rustup target add {} |
248 |
- '''.format(host_or_target.alias, rustc, rustc_target.alias))) |
249 |
+ '''.format(host_or_target.alias, rustc, rustc_target))) |
250 |
check_cmd_output(*cmd, onerror=failed) |
251 |
if not os.path.exists(out_path) or os.path.getsize(out_path) == 0: |
252 |
failed() |
253 |
@@ -319,13 +373,13 @@ def rust_triple_alias(host_or_target): |
254 |
os.remove(out_path) |
255 |
|
256 |
# This target is usable. |
257 |
- return rustc_target.alias |
258 |
+ return rustc_target |
259 |
|
260 |
return rust_target |
261 |
|
262 |
|
263 |
-rust_target_triple = rust_triple_alias(target) |
264 |
-rust_host_triple = rust_triple_alias(host) |
265 |
+rust_target_triple = rust_triple_alias(target, c_compiler) |
266 |
+rust_host_triple = rust_triple_alias(host, host_c_compiler) |
267 |
|
268 |
|
269 |
@depends(host, rust_host_triple, rustc_info.host) |