blob: bee7c9f12f3c4b266103d849a844efc1c632d571 [file] [log] [blame]
Andrew Geisslerd159c7f2021-09-02 21:05:58 -05001require rust.inc
2inherit cross
3
4python do_rust_gen_targets () {
5 wd = d.getVar('WORKDIR') + '/targets/'
6 # It is important 'TARGET' is last here so that it overrides our less
7 # informed choices for BUILD & HOST if TARGET happens to be the same as
8 # either of them.
9 for thing in ['BUILD', 'HOST', 'TARGET']:
10 bb.debug(1, "rust_gen_target for " + thing)
11 features = ""
12 cpu = "generic"
13 arch = d.getVar('{}_ARCH'.format(thing))
14 if thing is "TARGET":
15 # arm and armv7 have different targets in llvm
16 if arch == "arm" and target_is_armv7(d):
17 arch = 'armv7'
18 features = d.getVar('TARGET_LLVM_FEATURES') or ""
19 cpu = d.getVar('TARGET_LLVM_CPU')
20 rust_gen_target(d, thing, wd, features, cpu, arch)
21}
22
23# Otherwise we'll depend on what we provide
24INHIBIT_DEFAULT_RUST_DEPS = "1"
25
26# Unlike native (which nicely maps it's DEPENDS) cross wipes them out completely.
27# Generally, we (and cross in general) need the same things that native needs,
28# so it might make sense to take it's mapping. For now, though, we just mention
29# the bits we need explicitly.
30DEPENDS += "rust-llvm-native"
31DEPENDS += "virtual/${TARGET_PREFIX}gcc virtual/${TARGET_PREFIX}compilerlibs virtual/libc"
32DEPENDS += "rust-native"
33
34PROVIDES = "virtual/${TARGET_PREFIX}rust"
35PN = "rust-cross-${TARGET_ARCH}"
36
37# In the cross compilation case, rustc doesn't seem to get the rpath quite
38# right. It manages to include '../../lib/${TARGET_PREFIX}', but doesn't
39# include the '../../lib' (ie: relative path from cross_bindir to normal
40# libdir. As a result, we end up not being able to properly reference files in normal ${libdir}.
41# Most of the time this happens to work fine as the systems libraries are
42# subsituted, but sometimes a host system will lack a library, or the right
43# version of a library (libtinfo was how I noticed this).
44#
45# FIXME: this should really be fixed in rust itself.
46# FIXME: using hard-coded relative paths is wrong, we should ask bitbake for
47# the relative path between 2 of it's vars.
48HOST_POST_LINK_ARGS:append = " -Wl,-rpath=../../lib"
49BUILD_POST_LINK_ARGS:append = " -Wl,-rpath=../../lib"
50
51# We need the same thing for the calls to the compiler when building the runtime crap
52TARGET_CC_ARCH:append = " --sysroot=${STAGING_DIR_TARGET}"
53
54do_rust_setup_snapshot () {
55}
56
57do_configure () {
58}
59
60do_compile () {
61}
62
63do_install () {
64 mkdir -p ${D}${prefix}/${base_libdir_native}/rustlib
65 cp ${WORKDIR}/targets/${TARGET_SYS}.json ${D}${prefix}/${base_libdir_native}/rustlib
66}
67
68rust_cross_sysroot_preprocess() {
69 sysroot_stage_dir ${D}${prefix}/${base_libdir_native}/rustlib ${SYSROOT_DESTDIR}${prefix}/${base_libdir_native}/rustlib
70}
71SYSROOT_PREPROCESS_FUNCS += "rust_cross_sysroot_preprocess"