summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2022-07-23 13:41:38 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2022-07-28 11:07:33 +0100
commit1e04c8aafbe562d2c87ca9de53fbb27703b0c51a (patch)
tree999d6eea83251701fecb3f993e63651f2b5749f7 /meta/recipes-devtools
parenta02bb3b794fe97cbd64d6740db494de00c17134b (diff)
downloadpoky-1e04c8aafbe562d2c87ca9de53fbb27703b0c51a.tar.gz
rust-target-config: Create new class to contain target json config generation
Currently most of the rust recipes use this code but it is all piecemeal. Turn the code into a class where things can start to be rationalised. Ultimately some of the data and python code should be moved to a python library but one step at a time. No functionality changes. (From OE-Core rev: 3795285cbf362e13b8151bfdbe1bce999ac28641) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/recipes-devtools')
-rw-r--r--meta/recipes-devtools/cargo/cargo-cross-canadian.inc2
-rw-r--r--meta/recipes-devtools/rust/rust-common.inc369
-rw-r--r--meta/recipes-devtools/rust/rust.inc2
3 files changed, 2 insertions, 371 deletions
diff --git a/meta/recipes-devtools/cargo/cargo-cross-canadian.inc b/meta/recipes-devtools/cargo/cargo-cross-canadian.inc
index d12267db3d..e83b6a67b3 100644
--- a/meta/recipes-devtools/cargo/cargo-cross-canadian.inc
+++ b/meta/recipes-devtools/cargo/cargo-cross-canadian.inc
@@ -5,7 +5,7 @@ RUST_ALTERNATE_EXE_PATH = "${STAGING_LIBDIR_NATIVE}/llvm-rust/bin/llvm-config"
5HOST_SYS = "${HOST_ARCH}-unknown-linux-gnu" 5HOST_SYS = "${HOST_ARCH}-unknown-linux-gnu"
6CARGO_RUST_TARGET_CCLD = "${RUST_BUILD_CCLD}" 6CARGO_RUST_TARGET_CCLD = "${RUST_BUILD_CCLD}"
7 7
8require recipes-devtools/rust/rust-common.inc 8inherit rust-target-config
9require cargo.inc 9require cargo.inc
10 10
11CARGO = "${WORKDIR}/${CARGO_SNAPSHOT}/bin/cargo" 11CARGO = "${WORKDIR}/${CARGO_SNAPSHOT}/bin/cargo"
diff --git a/meta/recipes-devtools/rust/rust-common.inc b/meta/recipes-devtools/rust/rust-common.inc
deleted file mode 100644
index 2edc71e0d3..0000000000
--- a/meta/recipes-devtools/rust/rust-common.inc
+++ /dev/null
@@ -1,369 +0,0 @@
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
73llvm_features_from_tune[vardepvalue] = "${@llvm_features_from_tune(d)}"
74
75# TARGET_CC_ARCH changes from build/cross/target so it'll do the right thing
76# this should go away when https://github.com/rust-lang/rust/pull/31709 is
77# stable (1.9.0?)
78def llvm_features_from_cc_arch(d):
79 f = []
80 feat = d.getVar('TARGET_CC_ARCH')
81 if not feat:
82 return []
83 feat = frozenset(feat.split())
84
85 if '-mmmx' in feat:
86 f.append("+mmx")
87 if '-msse' in feat:
88 f.append("+sse")
89 if '-msse2' in feat:
90 f.append("+sse2")
91 if '-msse3' in feat:
92 f.append("+sse3")
93 if '-mssse3' in feat:
94 f.append("+ssse3")
95 if '-msse4.1' in feat:
96 f.append("+sse4.1")
97 if '-msse4.2' in feat:
98 f.append("+sse4.2")
99 if '-msse4a' in feat:
100 f.append("+sse4a")
101 if '-mavx' in feat:
102 f.append("+avx")
103 if '-mavx2' in feat:
104 f.append("+avx2")
105
106 return f
107
108def llvm_features_from_target_fpu(d):
109 # TARGET_FPU can be hard or soft. +soft-float tell llvm to use soft float
110 # ABI. There is no option for hard.
111
112 fpu = d.getVar('TARGET_FPU', True)
113 return ["+soft-float"] if fpu == "soft" else []
114
115def llvm_features(d):
116 return ','.join(llvm_features_from_tune(d) +
117 llvm_features_from_cc_arch(d) +
118 llvm_features_from_target_fpu(d))
119
120llvm_features[vardepvalue] = "${@llvm_features(d)}"
121
122## arm-unknown-linux-gnueabihf
123DATA_LAYOUT[arm-eabi] = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64"
124TARGET_ENDIAN[arm-eabi] = "little"
125TARGET_POINTER_WIDTH[arm-eabi] = "32"
126TARGET_C_INT_WIDTH[arm-eabi] = "32"
127MAX_ATOMIC_WIDTH[arm-eabi] = "64"
128FEATURES[arm-eabi] = "+v6,+vfp2"
129
130## armv7-unknown-linux-gnueabihf
131DATA_LAYOUT[armv7-eabi] = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64"
132TARGET_ENDIAN[armv7-eabi] = "little"
133TARGET_POINTER_WIDTH[armv7-eabi] = "32"
134TARGET_C_INT_WIDTH[armv7-eabi] = "32"
135MAX_ATOMIC_WIDTH[armv7-eabi] = "64"
136FEATURES[armv7-eabi] = "+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"
140TARGET_ENDIAN[aarch64] = "little"
141TARGET_POINTER_WIDTH[aarch64] = "64"
142TARGET_C_INT_WIDTH[aarch64] = "32"
143MAX_ATOMIC_WIDTH[aarch64] = "128"
144
145## x86_64-unknown-linux-{gnu, musl}
146DATA_LAYOUT[x86_64] = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
147TARGET_ENDIAN[x86_64] = "little"
148TARGET_POINTER_WIDTH[x86_64] = "64"
149TARGET_C_INT_WIDTH[x86_64] = "32"
150MAX_ATOMIC_WIDTH[x86_64] = "64"
151
152## x86_64-unknown-linux-gnux32
153DATA_LAYOUT[x86_64-x32] = "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
154TARGET_ENDIAN[x86_64-x32] = "little"
155TARGET_POINTER_WIDTH[x86_64-x32] = "32"
156TARGET_C_INT_WIDTH[x86_64-x32] = "32"
157MAX_ATOMIC_WIDTH[x86_64-x32] = "64"
158
159## i686-unknown-linux-{gnu, musl}
160DATA_LAYOUT[i686] = "e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128"
161TARGET_ENDIAN[i686] = "little"
162TARGET_POINTER_WIDTH[i686] = "32"
163TARGET_C_INT_WIDTH[i686] = "32"
164MAX_ATOMIC_WIDTH[i686] = "64"
165
166## XXX: a bit of a hack so qemux86 builds, clone of i686-unknown-linux-{gnu, musl} above
167DATA_LAYOUT[i586] = "e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128"
168TARGET_ENDIAN[i586] = "little"
169TARGET_POINTER_WIDTH[i586] = "32"
170TARGET_C_INT_WIDTH[i586] = "32"
171MAX_ATOMIC_WIDTH[i586] = "64"
172
173## mips-unknown-linux-{gnu, musl}
174DATA_LAYOUT[mips] = "E-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64"
175TARGET_ENDIAN[mips] = "big"
176TARGET_POINTER_WIDTH[mips] = "32"
177TARGET_C_INT_WIDTH[mips] = "32"
178MAX_ATOMIC_WIDTH[mips] = "32"
179
180## mipsel-unknown-linux-{gnu, musl}
181DATA_LAYOUT[mipsel] = "e-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64"
182TARGET_ENDIAN[mipsel] = "little"
183TARGET_POINTER_WIDTH[mipsel] = "32"
184TARGET_C_INT_WIDTH[mipsel] = "32"
185MAX_ATOMIC_WIDTH[mipsel] = "32"
186
187## mips64-unknown-linux-{gnu, musl}
188DATA_LAYOUT[mips64] = "E-m:e-i8:8:32-i16:16:32-i64:64-n32:64-S128"
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"
196TARGET_ENDIAN[mips64el] = "little"
197TARGET_POINTER_WIDTH[mips64el] = "64"
198TARGET_C_INT_WIDTH[mips64el] = "64"
199MAX_ATOMIC_WIDTH[mips64el] = "64"
200
201## powerpc-unknown-linux-{gnu, musl}
202DATA_LAYOUT[powerpc] = "E-m:e-p:32:32-i64:64-n32"
203TARGET_ENDIAN[powerpc] = "big"
204TARGET_POINTER_WIDTH[powerpc] = "32"
205TARGET_C_INT_WIDTH[powerpc] = "32"
206MAX_ATOMIC_WIDTH[powerpc] = "32"
207
208## powerpc64-unknown-linux-{gnu, musl}
209DATA_LAYOUT[powerpc64] = "E-m:e-i64:64-n32:64-S128-v256:256:256-v512:512:512"
210TARGET_ENDIAN[powerpc64] = "big"
211TARGET_POINTER_WIDTH[powerpc64] = "64"
212TARGET_C_INT_WIDTH[powerpc64] = "64"
213MAX_ATOMIC_WIDTH[powerpc64] = "64"
214
215## powerpc64le-unknown-linux-{gnu, musl}
216DATA_LAYOUT[powerpc64le] = "e-m:e-i64:64-n32:64-v256:256:256-v512:512:512"
217TARGET_ENDIAN[powerpc64le] = "little"
218TARGET_POINTER_WIDTH[powerpc64le] = "64"
219TARGET_C_INT_WIDTH[powerpc64le] = "64"
220MAX_ATOMIC_WIDTH[powerpc64le] = "64"
221
222## riscv32-unknown-linux-{gnu, musl}
223DATA_LAYOUT[riscv32] = "e-m:e-p:32:32-i64:64-n32-S128"
224TARGET_ENDIAN[riscv32] = "little"
225TARGET_POINTER_WIDTH[riscv32] = "32"
226TARGET_C_INT_WIDTH[riscv32] = "32"
227MAX_ATOMIC_WIDTH[riscv32] = "32"
228
229## riscv64-unknown-linux-{gnu, musl}
230DATA_LAYOUT[riscv64] = "e-m:e-p:64:64-i64:64-i128:128-n64-S128"
231TARGET_ENDIAN[riscv64] = "little"
232TARGET_POINTER_WIDTH[riscv64] = "64"
233TARGET_C_INT_WIDTH[riscv64] = "64"
234MAX_ATOMIC_WIDTH[riscv64] = "64"
235
236# Convert a normal arch (HOST_ARCH, TARGET_ARCH, BUILD_ARCH, etc) to something
237# rust's internals won't choke on.
238def arch_to_rust_target_arch(arch):
239 if arch == "i586" or arch == "i686":
240 return "x86"
241 elif arch == "mipsel":
242 return "mips"
243 elif arch == "mip64sel":
244 return "mips64"
245 elif arch == "armv7":
246 return "arm"
247 elif arch == "powerpc64le":
248 return "powerpc64"
249 else:
250 return arch
251
252# generates our target CPU value
253def llvm_cpu(d):
254 cpu = d.getVar('PACKAGE_ARCH')
255 target = d.getVar('TRANSLATED_TARGET_ARCH')
256
257 trans = {}
258 trans['corei7-64'] = "corei7"
259 trans['core2-32'] = "core2"
260 trans['x86-64'] = "x86-64"
261 trans['i686'] = "i686"
262 trans['i586'] = "i586"
263 trans['powerpc'] = "powerpc"
264 trans['mips64'] = "mips64"
265 trans['mips64el'] = "mips64"
266 trans['riscv64'] = "generic-rv64"
267 trans['riscv32'] = "generic-rv32"
268
269 if target in ["mips", "mipsel"]:
270 feat = frozenset(d.getVar('TUNE_FEATURES').split())
271 if "mips32r2" in feat:
272 trans['mipsel'] = "mips32r2"
273 trans['mips'] = "mips32r2"
274 elif "mips32" in feat:
275 trans['mipsel'] = "mips32"
276 trans['mips'] = "mips32"
277
278 try:
279 return trans[cpu]
280 except:
281 return trans.get(target, "generic")
282
283llvm_cpu[vardepvalue] = "${@llvm_cpu(d)}"
284
285def rust_gen_target(d, thing, wd, arch):
286 import json
287 sys = d.getVar('{}_SYS'.format(thing))
288 prefix = d.getVar('{}_PREFIX'.format(thing))
289
290 abi = None
291 cpu = "generic"
292 features = ""
293
294 if thing == "TARGET":
295 abi = d.getVar('ABIEXTENSION')
296 cpu = llvm_cpu(d)
297 if bb.data.inherits_class('native', d):
298 features = ','.join(llvm_features_from_cc_arch(d))
299 else:
300 features = llvm_features(d) or ""
301 # arm and armv7 have different targets in llvm
302 if arch == "arm" and target_is_armv7(d):
303 arch = 'armv7'
304
305 rust_arch = oe.rust.arch_to_rust_arch(arch)
306
307 if abi:
308 arch_abi = "{}-{}".format(rust_arch, abi)
309 else:
310 arch_abi = rust_arch
311
312 features = features or d.getVarFlag('FEATURES', arch_abi) or ""
313 features = features.strip()
314
315 llvm_target = d.getVar('RUST_TARGET_SYS')
316 if thing == "BUILD":
317 llvm_target = d.getVar('RUST_HOST_SYS')
318
319 # build tspec
320 tspec = {}
321 tspec['llvm-target'] = llvm_target
322 tspec['data-layout'] = d.getVarFlag('DATA_LAYOUT', arch_abi)
323 tspec['max-atomic-width'] = int(d.getVarFlag('MAX_ATOMIC_WIDTH', arch_abi))
324 tspec['target-pointer-width'] = d.getVarFlag('TARGET_POINTER_WIDTH', arch_abi)
325 tspec['target-c-int-width'] = d.getVarFlag('TARGET_C_INT_WIDTH', arch_abi)
326 tspec['target-endian'] = d.getVarFlag('TARGET_ENDIAN', arch_abi)
327 tspec['arch'] = arch_to_rust_target_arch(rust_arch)
328 tspec['os'] = "linux"
329 if "musl" in tspec['llvm-target']:
330 tspec['env'] = "musl"
331 else:
332 tspec['env'] = "gnu"
333 if "riscv64" in tspec['llvm-target']:
334 tspec['llvm-abiname'] = "lp64d"
335 if "riscv32" in tspec['llvm-target']:
336 tspec['llvm-abiname'] = "ilp32d"
337 tspec['vendor'] = "unknown"
338 tspec['target-family'] = "unix"
339 tspec['linker'] = "{}{}gcc".format(d.getVar('CCACHE'), prefix)
340 tspec['cpu'] = cpu
341 if features != "":
342 tspec['features'] = features
343 tspec['dynamic-linking'] = True
344 tspec['executables'] = True
345 tspec['linker-is-gnu'] = True
346 tspec['linker-flavor'] = "gcc"
347 tspec['has-rpath'] = True
348 tspec['has-elf-tls'] = True
349 tspec['position-independent-executables'] = True
350 tspec['panic-strategy'] = d.getVar("RUST_PANIC_STRATEGY")
351
352 # write out the target spec json file
353 with open(wd + sys + '.json', 'w') as f:
354 json.dump(tspec, f, indent=4)
355
356# These are accounted for in tmpdir path names so don't need to be in the task sig
357rust_gen_target[vardepsexclude] += "RUST_HOST_SYS RUST_TARGET_SYS ABIEXTENSION llvm_cpu"
358
359do_rust_gen_targets[vardeps] += "DATA_LAYOUT TARGET_ENDIAN TARGET_POINTER_WIDTH TARGET_C_INT_WIDTH MAX_ATOMIC_WIDTH FEATURES"
360
361python do_rust_gen_targets () {
362 wd = d.getVar('WORKDIR') + '/targets/'
363 build_arch = d.getVar('BUILD_ARCH')
364 rust_gen_target(d, 'BUILD', wd, build_arch)
365}
366
367addtask rust_gen_targets after do_patch before do_compile
368do_rust_gen_targets[dirs] += "${WORKDIR}/targets"
369
diff --git a/meta/recipes-devtools/rust/rust.inc b/meta/recipes-devtools/rust/rust.inc
index ea716d31f2..ecb057ad3b 100644
--- a/meta/recipes-devtools/rust/rust.inc
+++ b/meta/recipes-devtools/rust/rust.inc
@@ -39,7 +39,7 @@ setup_cargo_environment () {
39 printf "linker = '%s'\n" "${RUST_BUILD_CCLD}" >> ${CARGO_HOME}/config 39 printf "linker = '%s'\n" "${RUST_BUILD_CCLD}" >> ${CARGO_HOME}/config
40} 40}
41 41
42include rust-common.inc 42inherit rust-target-config
43 43
44do_rust_setup_snapshot () { 44do_rust_setup_snapshot () {
45 for installer in "${WORKDIR}/rust-snapshot-components/"*"/install.sh"; do 45 for installer in "${WORKDIR}/rust-snapshot-components/"*"/install.sh"; do