summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/rust/rust-common.inc
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-devtools/rust/rust-common.inc')
-rw-r--r--meta/recipes-devtools/rust/rust-common.inc346
1 files changed, 346 insertions, 0 deletions
diff --git a/meta/recipes-devtools/rust/rust-common.inc b/meta/recipes-devtools/rust/rust-common.inc
new file mode 100644
index 0000000000..350517c723
--- /dev/null
+++ b/meta/recipes-devtools/rust/rust-common.inc
@@ -0,0 +1,346 @@
1
2# Right now this is focused on arm-specific tune features.
3# We get away with this for now as one can only use x86-64 as the build host
4# (not arm).
5# Note that TUNE_FEATURES is _always_ refering to the target, so we really
6# don't want to use this for the host/build.
7def llvm_features_from_tune(d):
8 f = []
9 feat = d.getVar('TUNE_FEATURES')
10 if not feat:
11 return []
12 feat = frozenset(feat.split())
13
14 mach_overrides = d.getVar('MACHINEOVERRIDES')
15 mach_overrides = frozenset(mach_overrides.split(':'))
16
17 if 'vfpv4' in feat:
18 f.append("+vfp4")
19 if 'vfpv3' in feat:
20 f.append("+vfp3")
21 if 'vfpv3d16' in feat:
22 f.append("+d16")
23
24 if 'vfpv2' in feat or 'vfp' in feat:
25 f.append("+vfp2")
26
27 if 'neon' in feat:
28 f.append("+neon")
29
30 if 'mips32' in feat:
31 f.append("+mips32")
32
33 if 'mips32r2' in feat:
34 f.append("+mips32r2")
35
36 if target_is_armv7(d):
37 f.append('+v7')
38
39 if ('armv6' in mach_overrides) or ('armv6' in feat):
40 f.append("+v6")
41 if 'armv5te' in feat:
42 f.append("+strict-align")
43 f.append("+v5te")
44 elif 'armv5' in feat:
45 f.append("+strict-align")
46 f.append("+v5")
47
48 if ('armv4' in mach_overrides) or ('armv4' in feat):
49 f.append("+strict-align")
50
51 if 'dsp' in feat:
52 f.append("+dsp")
53
54 if 'thumb' in feat:
55 if d.getVar('ARM_THUMB_OPT') == "thumb":
56 if target_is_armv7(d):
57 f.append('+thumb2')
58 f.append("+thumb-mode")
59
60 if 'cortexa5' in feat:
61 f.append("+a5")
62 if 'cortexa7' in feat:
63 f.append("+a7")
64 if 'cortexa9' in feat:
65 f.append("+a9")
66 if 'cortexa15' in feat:
67 f.append("+a15")
68 if 'cortexa17' in feat:
69 f.append("+a17")
70 if ('riscv64' in feat) or ('riscv32' in feat):
71 f.append("+a,+c,+d,+f,+m")
72 return f
73
74# TARGET_CC_ARCH changes from build/cross/target so it'll do the right thing
75# this should go away when https://github.com/rust-lang/rust/pull/31709 is
76# stable (1.9.0?)
77def llvm_features_from_cc_arch(d):
78 f = []
79 feat = d.getVar('TARGET_CC_ARCH')
80 if not feat:
81 return []
82 feat = frozenset(feat.split())
83
84 if '-mmmx' in feat:
85 f.append("+mmx")
86 if '-msse' in feat:
87 f.append("+sse")
88 if '-msse2' in feat:
89 f.append("+sse2")
90 if '-msse3' in feat:
91 f.append("+sse3")
92 if '-mssse3' in feat:
93 f.append("+ssse3")
94 if '-msse4.1' in feat:
95 f.append("+sse4.1")
96 if '-msse4.2' in feat:
97 f.append("+sse4.2")
98 if '-msse4a' in feat:
99 f.append("+sse4a")
100 if '-mavx' in feat:
101 f.append("+avx")
102 if '-mavx2' in feat:
103 f.append("+avx2")
104
105 return f
106
107def llvm_features_from_target_fpu(d):
108 # TARGET_FPU can be hard or soft. +soft-float tell llvm to use soft float
109 # ABI. There is no option for hard.
110
111 fpu = d.getVar('TARGET_FPU', True)
112 return ["+soft-float"] if fpu == "soft" else []
113
114def llvm_features(d):
115 return ','.join(llvm_features_from_tune(d) +
116 llvm_features_from_cc_arch(d) +
117 llvm_features_from_target_fpu(d))
118
119
120## arm-unknown-linux-gnueabihf
121DATA_LAYOUT[arm] = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64"
122LLVM_TARGET[arm] = "${RUST_TARGET_SYS}"
123TARGET_ENDIAN[arm] = "little"
124TARGET_POINTER_WIDTH[arm] = "32"
125TARGET_C_INT_WIDTH[arm] = "32"
126MAX_ATOMIC_WIDTH[arm] = "64"
127FEATURES[arm] = "+v6,+vfp2"
128
129## armv7-unknown-linux-gnueabihf
130DATA_LAYOUT[armv7] = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64"
131LLVM_TARGET[armv7] = "${RUST_TARGET_SYS}"
132TARGET_ENDIAN[armv7] = "little"
133TARGET_POINTER_WIDTH[armv7] = "32"
134TARGET_C_INT_WIDTH[armv7] = "32"
135MAX_ATOMIC_WIDTH[armv7] = "64"
136FEATURES[armv7] = "+v7,+vfp2,+thumb2"
137
138## aarch64-unknown-linux-{gnu, musl}
139DATA_LAYOUT[aarch64] = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
140LLVM_TARGET[aarch64] = "${RUST_TARGET_SYS}"
141TARGET_ENDIAN[aarch64] = "little"
142TARGET_POINTER_WIDTH[aarch64] = "64"
143TARGET_C_INT_WIDTH[aarch64] = "32"
144MAX_ATOMIC_WIDTH[aarch64] = "128"
145
146## x86_64-unknown-linux-{gnu, musl}
147DATA_LAYOUT[x86_64] = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
148LLVM_TARGET[x86_64] = "${RUST_TARGET_SYS}"
149TARGET_ENDIAN[x86_64] = "little"
150TARGET_POINTER_WIDTH[x86_64] = "64"
151TARGET_C_INT_WIDTH[x86_64] = "32"
152MAX_ATOMIC_WIDTH[x86_64] = "64"
153
154## i686-unknown-linux-{gnu, musl}
155DATA_LAYOUT[i686] = "e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128"
156LLVM_TARGET[i686] = "${RUST_TARGET_SYS}"
157TARGET_ENDIAN[i686] = "little"
158TARGET_POINTER_WIDTH[i686] = "32"
159TARGET_C_INT_WIDTH[i686] = "32"
160MAX_ATOMIC_WIDTH[i686] = "64"
161
162## XXX: a bit of a hack so qemux86 builds, clone of i686-unknown-linux-{gnu, musl} above
163DATA_LAYOUT[i586] = "e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128"
164LLVM_TARGET[i586] = "${RUST_TARGET_SYS}"
165TARGET_ENDIAN[i586] = "little"
166TARGET_POINTER_WIDTH[i586] = "32"
167TARGET_C_INT_WIDTH[i586] = "32"
168MAX_ATOMIC_WIDTH[i586] = "64"
169
170## mips-unknown-linux-{gnu, musl}
171DATA_LAYOUT[mips] = "E-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64"
172LLVM_TARGET[mips] = "${RUST_TARGET_SYS}"
173TARGET_ENDIAN[mips] = "big"
174TARGET_POINTER_WIDTH[mips] = "32"
175TARGET_C_INT_WIDTH[mips] = "32"
176MAX_ATOMIC_WIDTH[mips] = "32"
177
178## mipsel-unknown-linux-{gnu, musl}
179DATA_LAYOUT[mipsel] = "e-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64"
180LLVM_TARGET[mipsel] = "${RUST_TARGET_SYS}"
181TARGET_ENDIAN[mipsel] = "little"
182TARGET_POINTER_WIDTH[mipsel] = "32"
183TARGET_C_INT_WIDTH[mipsel] = "32"
184MAX_ATOMIC_WIDTH[mipsel] = "32"
185
186## mips64-unknown-linux-{gnu, musl}
187DATA_LAYOUT[mips64] = "E-m:e-i8:8:32-i16:16:32-i64:64-n32:64-S128"
188LLVM_TARGET[mips64] = "${RUST_TARGET_SYS}"
189TARGET_ENDIAN[mips64] = "big"
190TARGET_POINTER_WIDTH[mips64] = "64"
191TARGET_C_INT_WIDTH[mips64] = "64"
192MAX_ATOMIC_WIDTH[mips64] = "64"
193
194## mips64el-unknown-linux-{gnu, musl}
195DATA_LAYOUT[mips64el] = "e-m:e-i8:8:32-i16:16:32-i64:64-n32:64-S128"
196LLVM_TARGET[mips64el] = "${RUST_TARGET_SYS}"
197TARGET_ENDIAN[mips64el] = "little"
198TARGET_POINTER_WIDTH[mips64el] = "64"
199TARGET_C_INT_WIDTH[mips64el] = "64"
200MAX_ATOMIC_WIDTH[mips64el] = "64"
201
202## powerpc-unknown-linux-{gnu, musl}
203DATA_LAYOUT[powerpc] = "E-m:e-p:32:32-i64:64-n32"
204LLVM_TARGET[powerpc] = "${RUST_TARGET_SYS}"
205TARGET_ENDIAN[powerpc] = "big"
206TARGET_POINTER_WIDTH[powerpc] = "32"
207TARGET_C_INT_WIDTH[powerpc] = "32"
208MAX_ATOMIC_WIDTH[powerpc] = "32"
209
210## powerpc64le-unknown-linux-{gnu, musl}
211DATA_LAYOUT[powerpc64le] = "e-m:e-i64:64-n32:64-v256:256:256-v512:512:512"
212LLVM_TARGET[powerpc64le] = "${RUST_TARGET_SYS}"
213TARGET_ENDIAN[powerpc64le] = "little"
214TARGET_POINTER_WIDTH[powerpc64le] = "64"
215TARGET_C_INT_WIDTH[powerpc64le] = "64"
216MAX_ATOMIC_WIDTH[powerpc64le] = "64"
217
218## riscv32-unknown-linux-{gnu, musl}
219DATA_LAYOUT[riscv32] = "e-m:e-p:32:32-i64:64-n32-S128"
220LLVM_TARGET[riscv32] = "${RUST_TARGET_SYS}"
221TARGET_ENDIAN[riscv32] = "little"
222TARGET_POINTER_WIDTH[riscv32] = "32"
223TARGET_C_INT_WIDTH[riscv32] = "32"
224MAX_ATOMIC_WIDTH[riscv32] = "32"
225
226## riscv64-unknown-linux-{gnu, musl}
227DATA_LAYOUT[riscv64] = "e-m:e-p:64:64-i64:64-i128:128-n64-S128"
228LLVM_TARGET[riscv64] = "${RUST_TARGET_SYS}"
229TARGET_ENDIAN[riscv64] = "little"
230TARGET_POINTER_WIDTH[riscv64] = "64"
231TARGET_C_INT_WIDTH[riscv64] = "64"
232MAX_ATOMIC_WIDTH[riscv64] = "64"
233
234def sys_for(d, thing):
235 return d.getVar('{}_SYS'.format(thing))
236
237def prefix_for(d, thing):
238 return d.getVar('{}_PREFIX'.format(thing))
239
240# Convert a normal arch (HOST_ARCH, TARGET_ARCH, BUILD_ARCH, etc) to something
241# rust's internals won't choke on.
242def arch_to_rust_target_arch(arch):
243 if arch == "i586" or arch == "i686":
244 return "x86"
245 elif arch == "mipsel":
246 return "mips"
247 elif arch == "mip64sel":
248 return "mips64"
249 elif arch == "armv7":
250 return "arm"
251 else:
252 return arch
253
254# generates our target CPU value
255def llvm_cpu(d):
256 cpu = d.getVar('PACKAGE_ARCH')
257 target = d.getVar('TRANSLATED_TARGET_ARCH')
258
259 trans = {}
260 trans['corei7-64'] = "corei7"
261 trans['core2-32'] = "core2"
262 trans['x86-64'] = "x86-64"
263 trans['i686'] = "i686"
264 trans['i586'] = "i586"
265 trans['powerpc'] = "powerpc"
266 trans['mips64'] = "mips64"
267 trans['mips64el'] = "mips64"
268 trans['riscv64'] = "generic-rv64"
269 trans['riscv32'] = "generic-rv32"
270
271 if target in ["mips", "mipsel"]:
272 feat = frozenset(d.getVar('TUNE_FEATURES').split())
273 if "mips32r2" in feat:
274 trans['mipsel'] = "mips32r2"
275 trans['mips'] = "mips32r2"
276 elif "mips32" in feat:
277 trans['mipsel'] = "mips32"
278 trans['mips'] = "mips32"
279
280 try:
281 return trans[cpu]
282 except:
283 return trans.get(target, "generic")
284
285TARGET_LLVM_CPU="${@llvm_cpu(d)}"
286TARGET_LLVM_FEATURES = "${@llvm_features(d)}"
287
288# class-native implies TARGET=HOST, and TUNE_FEATURES only describes the real
289# (original) target.
290TARGET_LLVM_FEATURES:class-native = "${@','.join(llvm_features_from_cc_arch(d))}"
291
292def rust_gen_target(d, thing, wd, features, cpu, arch):
293 import json
294 sys = sys_for(d, thing)
295 prefix = prefix_for(d, thing)
296
297 features = features or d.getVarFlag('FEATURES', arch) or ""
298 features = features.strip()
299
300 # build tspec
301 tspec = {}
302 tspec['llvm-target'] = d.getVarFlag('LLVM_TARGET', arch)
303 tspec['data-layout'] = d.getVarFlag('DATA_LAYOUT', arch)
304 tspec['max-atomic-width'] = int(d.getVarFlag('MAX_ATOMIC_WIDTH', arch))
305 tspec['target-pointer-width'] = d.getVarFlag('TARGET_POINTER_WIDTH', arch)
306 tspec['target-c-int-width'] = d.getVarFlag('TARGET_C_INT_WIDTH', arch)
307 tspec['target-endian'] = d.getVarFlag('TARGET_ENDIAN', arch)
308 tspec['arch'] = arch_to_rust_target_arch(arch)
309 tspec['os'] = "linux"
310 if "musl" in tspec['llvm-target']:
311 tspec['env'] = "musl"
312 else:
313 tspec['env'] = "gnu"
314 if "riscv64" in tspec['llvm-target']:
315 tspec['llvm-abiname'] = "lp64d"
316 if "riscv32" in tspec['llvm-target']:
317 tspec['llvm-abiname'] = "ilp32d"
318 tspec['vendor'] = "unknown"
319 tspec['target-family'] = "unix"
320 tspec['linker'] = "{}{}gcc".format(d.getVar('CCACHE'), prefix)
321 tspec['ar'] = "{}ar".format(prefix)
322 tspec['cpu'] = cpu
323 if features != "":
324 tspec['features'] = features
325 tspec['dynamic-linking'] = True
326 tspec['executables'] = True
327 tspec['linker-is-gnu'] = True
328 tspec['linker-flavor'] = "gcc"
329 tspec['has-rpath'] = True
330 tspec['has-elf-tls'] = True
331 tspec['position-independent-executables'] = True
332 tspec['panic-strategy'] = d.getVar("RUST_PANIC_STRATEGY")
333
334 # write out the target spec json file
335 with open(wd + sys + '.json', 'w') as f:
336 json.dump(tspec, f, indent=4)
337
338python do_rust_gen_targets () {
339 wd = d.getVar('WORKDIR') + '/targets/'
340 build_arch = d.getVar('BUILD_ARCH')
341 rust_gen_target(d, 'BUILD', wd, "", "generic", build_arch)
342}
343
344addtask rust_gen_targets after do_patch before do_compile
345do_rust_gen_targets[dirs] += "${WORKDIR}/targets"
346