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