summaryrefslogtreecommitdiffstats
path: root/meta/classes
diff options
context:
space:
mode:
authorRandy MacLeod <Randy.MacLeod@windriver.com>2021-08-10 13:52:19 -0400
committerRichard Purdie <richard.purdie@linuxfoundation.org>2021-08-26 22:09:43 +0100
commit61e1570c6a09c1984e919e8c0a82a74c1a08d821 (patch)
treeaccab4b08aa3c62f098c9bb19399efb46906256a /meta/classes
parent705b1d757fa221614f4f72cabf0fac5884cb6bfd (diff)
downloadpoky-61e1570c6a09c1984e919e8c0a82a74c1a08d821.tar.gz
rust: initial merge of most of meta-rust
In the meta-rust repo at commit: 448047c Upgrade to 1.54.0 (#359) Make the required directories: mkdir ../oe-core/meta/recipes-devtools/rust mkdir ../oe-core/meta/recipes-devtools/cargo mkdir ../oe-core/meta/recipes-example and then: cp recipes-devtools/rust/* ../oe-core/meta/recipes-devtools/rust cp recipes-devtools/cargo/* ../oe-core/meta/recipes-devtools/cargo cp lib/crate.py ../oe-core/meta/lib cp recipes-example/* ../oe-core/meta/recipes-example cp conf/distro/include/rust_* ../oe-core/meta/conf/distro/include/ cp classes/* ../oe-core/meta/classes/ cp recipes-core/packagegroups/packagegroup-rust-cross-canadian.bb ../oe-core/meta/recipes-core/packagegroups (From OE-Core rev: 3ed57578cca93ff1ba4e0bf3f25566e10659a2f9) Signed-off-by: Randy MacLeod <Randy.MacLeod@windriver.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/classes')
-rw-r--r--meta/classes/cargo.bbclass89
-rw-r--r--meta/classes/cargo_common.bbclass129
-rw-r--r--meta/classes/crate-fetch.bbclass13
-rw-r--r--meta/classes/rust-bin.bbclass149
-rw-r--r--meta/classes/rust-common.bbclass174
-rw-r--r--meta/classes/rust.bbclass45
6 files changed, 599 insertions, 0 deletions
diff --git a/meta/classes/cargo.bbclass b/meta/classes/cargo.bbclass
new file mode 100644
index 0000000000..0ca38143c0
--- /dev/null
+++ b/meta/classes/cargo.bbclass
@@ -0,0 +1,89 @@
1##
2## Purpose:
3## This class is used by any recipes that are built using
4## Cargo.
5
6inherit cargo_common
7
8# the binary we will use
9CARGO = "cargo"
10
11# We need cargo to compile for the target
12BASEDEPENDS:append = " cargo-native"
13
14# Ensure we get the right rust variant
15DEPENDS:append:class-target = " virtual/${TARGET_PREFIX}rust ${RUSTLIB_DEP}"
16DEPENDS:append:class-native = " rust-native"
17
18# Enable build separation
19B = "${WORKDIR}/build"
20
21# In case something fails in the build process, give a bit more feedback on
22# where the issue occured
23export RUST_BACKTRACE = "1"
24
25# The directory of the Cargo.toml relative to the root directory, per default
26# assume there's a Cargo.toml directly in the root directory
27CARGO_SRC_DIR ??= ""
28
29# The actual path to the Cargo.toml
30MANIFEST_PATH ??= "${S}/${CARGO_SRC_DIR}/Cargo.toml"
31
32RUSTFLAGS ??= ""
33BUILD_MODE = "${@['--release', ''][d.getVar('DEBUG_BUILD') == '1']}"
34CARGO_BUILD_FLAGS = "-v --target ${HOST_SYS} ${BUILD_MODE} --manifest-path=${MANIFEST_PATH}"
35
36# This is based on the content of CARGO_BUILD_FLAGS and generally will need to
37# change if CARGO_BUILD_FLAGS changes.
38BUILD_DIR = "${@['release', 'debug'][d.getVar('DEBUG_BUILD') == '1']}"
39CARGO_TARGET_SUBDIR="${HOST_SYS}/${BUILD_DIR}"
40oe_cargo_build () {
41 export RUSTFLAGS="${RUSTFLAGS}"
42 export RUST_TARGET_PATH="${RUST_TARGET_PATH}"
43 bbnote "cargo = $(which ${CARGO})"
44 bbnote "rustc = $(which ${RUSTC})"
45 bbnote "${CARGO} build ${CARGO_BUILD_FLAGS} $@"
46 "${CARGO}" build ${CARGO_BUILD_FLAGS} "$@"
47}
48
49do_compile[progress] = "outof:\s+(\d+)/(\d+)"
50cargo_do_compile () {
51 oe_cargo_fix_env
52 oe_cargo_build
53}
54
55cargo_do_install () {
56 local have_installed=false
57 for tgt in "${B}/target/${CARGO_TARGET_SUBDIR}/"*; do
58 case $tgt in
59 *.so|*.rlib)
60 install -d "${D}${rustlibdir}"
61 install -m755 "$tgt" "${D}${rustlibdir}"
62 have_installed=true
63 ;;
64 *examples)
65 if [ -d "$tgt" ]; then
66 for example in "$tgt/"*; do
67 if [ -f "$example" ] && [ -x "$example" ]; then
68 install -d "${D}${bindir}"
69 install -m755 "$example" "${D}${bindir}"
70 have_installed=true
71 fi
72 done
73 fi
74 ;;
75 *)
76 if [ -f "$tgt" ] && [ -x "$tgt" ]; then
77 install -d "${D}${bindir}"
78 install -m755 "$tgt" "${D}${bindir}"
79 have_installed=true
80 fi
81 ;;
82 esac
83 done
84 if ! $have_installed; then
85 die "Did not find anything to install"
86 fi
87}
88
89EXPORT_FUNCTIONS do_compile do_install
diff --git a/meta/classes/cargo_common.bbclass b/meta/classes/cargo_common.bbclass
new file mode 100644
index 0000000000..b0b039a22e
--- /dev/null
+++ b/meta/classes/cargo_common.bbclass
@@ -0,0 +1,129 @@
1##
2## Purpose:
3## This class is to support building with cargo. It
4## must be different than cargo.bbclass because Rust
5## now builds with Cargo but cannot use cargo.bbclass
6## due to dependencies and assumptions in cargo.bbclass
7## that Rust & Cargo are already installed. So this
8## is used by cargo.bbclass and Rust
9##
10
11# add crate fetch support
12inherit crate-fetch
13inherit rust-common
14
15# Where we download our registry and dependencies to
16export CARGO_HOME = "${WORKDIR}/cargo_home"
17
18# The pkg-config-rs library used by cargo build scripts disables itself when
19# cross compiling unless this is defined. We set up pkg-config appropriately
20# for cross compilation, so tell it we know better than it.
21export PKG_CONFIG_ALLOW_CROSS = "1"
22
23# Don't instruct cargo to use crates downloaded by bitbake. Some rust packages,
24# for example the rust compiler itself, come with their own vendored sources.
25# Specifying two [source.crates-io] will not work.
26CARGO_DISABLE_BITBAKE_VENDORING ?= "0"
27
28# Used by libstd-rs to point to the vendor dir included in rustc src
29CARGO_VENDORING_DIRECTORY ?= "${CARGO_HOME}/bitbake"
30
31CARGO_RUST_TARGET_CCLD ?= "${RUST_TARGET_CCLD}"
32cargo_common_do_configure () {
33 mkdir -p ${CARGO_HOME}/bitbake
34
35 cat <<- EOF > ${CARGO_HOME}/config
36 # EXTRA_OECARGO_PATHS
37 paths = [
38 $(for p in ${EXTRA_OECARGO_PATHS}; do echo \"$p\",; done)
39 ]
40 EOF
41
42 cat <<- EOF >> ${CARGO_HOME}/config
43
44 # Local mirror vendored by bitbake
45 [source.bitbake]
46 directory = "${CARGO_VENDORING_DIRECTORY}"
47 EOF
48
49 if [ -z "${EXTERNALSRC}" ] && [ ${CARGO_DISABLE_BITBAKE_VENDORING} = "0" ]; then
50 cat <<- EOF >> ${CARGO_HOME}/config
51
52 [source.crates-io]
53 replace-with = "bitbake"
54 local-registry = "/nonexistant"
55 EOF
56 fi
57
58 cat <<- EOF >> ${CARGO_HOME}/config
59
60 [http]
61 # Multiplexing can't be enabled because http2 can't be enabled
62 # in curl-native without dependency loops
63 multiplexing = false
64
65 # Ignore the hard coded and incorrect path to certificates
66 cainfo = "${STAGING_ETCDIR_NATIVE}/ssl/certs/ca-certificates.crt"
67
68 EOF
69
70 if [ -n "${http_proxy}" ]; then
71 echo "proxy = \"${http_proxy}\"" >> ${CARGO_HOME}/config
72 fi
73
74 cat <<- EOF >> ${CARGO_HOME}/config
75
76 # HOST_SYS
77 [target.${HOST_SYS}]
78 linker = "${CARGO_RUST_TARGET_CCLD}"
79 EOF
80
81 if [ "${HOST_SYS}" != "${BUILD_SYS}" ]; then
82 cat <<- EOF >> ${CARGO_HOME}/config
83
84 # BUILD_SYS
85 [target.${BUILD_SYS}]
86 linker = "${RUST_BUILD_CCLD}"
87 EOF
88 fi
89
90 # Put build output in build directory preferred by bitbake instead of
91 # inside source directory unless they are the same
92 if [ "${B}" != "${S}" ]; then
93 cat <<- EOF >> ${CARGO_HOME}/config
94
95 [build]
96 # Use out of tree build destination to avoid poluting the source tree
97 target-dir = "${B}/target"
98 EOF
99 fi
100
101 cat <<- EOF >> ${CARGO_HOME}/config
102
103 [term]
104 progress.when = 'always'
105 progress.width = 80
106 EOF
107}
108
109oe_cargo_fix_env () {
110 export CC="${RUST_TARGET_CC}"
111 export CXX="${RUST_TARGET_CXX}"
112 export CFLAGS="${CFLAGS}"
113 export CXXFLAGS="${CXXFLAGS}"
114 export AR="${AR}"
115 export TARGET_CC="${RUST_TARGET_CC}"
116 export TARGET_CXX="${RUST_TARGET_CXX}"
117 export TARGET_CFLAGS="${CFLAGS}"
118 export TARGET_CXXFLAGS="${CXXFLAGS}"
119 export TARGET_AR="${AR}"
120 export HOST_CC="${RUST_BUILD_CC}"
121 export HOST_CXX="${RUST_BUILD_CXX}"
122 export HOST_CFLAGS="${BUILD_CFLAGS}"
123 export HOST_CXXFLAGS="${BUILD_CXXFLAGS}"
124 export HOST_AR="${BUILD_AR}"
125}
126
127EXTRA_OECARGO_PATHS ??= ""
128
129EXPORT_FUNCTIONS do_configure
diff --git a/meta/classes/crate-fetch.bbclass b/meta/classes/crate-fetch.bbclass
new file mode 100644
index 0000000000..c0ed434a96
--- /dev/null
+++ b/meta/classes/crate-fetch.bbclass
@@ -0,0 +1,13 @@
1#
2# crate-fetch class
3#
4# Registers 'crate' method for Bitbake fetch2.
5#
6# Adds support for following format in recipe SRC_URI:
7# crate://<packagename>/<version>
8#
9
10python () {
11 import crate
12 bb.fetch2.methods.append( crate.Crate() )
13}
diff --git a/meta/classes/rust-bin.bbclass b/meta/classes/rust-bin.bbclass
new file mode 100644
index 0000000000..c87343b3cf
--- /dev/null
+++ b/meta/classes/rust-bin.bbclass
@@ -0,0 +1,149 @@
1inherit rust
2
3RDEPENDS:${PN}:append:class-target = " ${RUSTLIB_DEP}"
4
5RUSTC_ARCHFLAGS += "-C opt-level=3 -g -L ${STAGING_DIR_HOST}/${rustlibdir} -C linker=${RUST_TARGET_CCLD}"
6EXTRA_OEMAKE += 'RUSTC_ARCHFLAGS="${RUSTC_ARCHFLAGS}"'
7
8# Some libraries alias with the standard library but libstd is configured to
9# make it difficult or imposisble to use its version. Unfortunately libstd
10# must be explicitly overridden using extern.
11OVERLAP_LIBS = "\
12 libc \
13 log \
14 getopts \
15 rand \
16"
17def get_overlap_deps(d):
18 deps = d.getVar("DEPENDS").split()
19 overlap_deps = []
20 for o in d.getVar("OVERLAP_LIBS").split():
21 l = len([o for dep in deps if (o + '-rs' in dep)])
22 if l > 0:
23 overlap_deps.append(o)
24 return " ".join(overlap_deps)
25OVERLAP_DEPS = "${@get_overlap_deps(d)}"
26
27# Prevents multiple static copies of standard library modules
28# See https://github.com/rust-lang/rust/issues/19680
29RUSTC_PREFER_DYNAMIC = "-C prefer-dynamic"
30RUSTC_FLAGS += "${RUSTC_PREFER_DYNAMIC}"
31
32CRATE_NAME ?= "${@d.getVar('BPN').replace('-rs', '').replace('-', '_')}"
33BINNAME ?= "${BPN}"
34LIBNAME ?= "lib${CRATE_NAME}-rs"
35CRATE_TYPE ?= "dylib"
36BIN_SRC ?= "${S}/src/main.rs"
37LIB_SRC ?= "${S}/src/lib.rs"
38
39rustbindest ?= "${bindir}"
40rustlibdest ?= "${rustlibdir}"
41RUST_RPATH_ABS ?= "${rustlibdir}:${rustlib}"
42
43def relative_rpaths(paths, base):
44 relpaths = set()
45 for p in paths.split(':'):
46 if p == base:
47 relpaths.add('$ORIGIN')
48 continue
49 relpaths.add(os.path.join('$ORIGIN', os.path.relpath(p, base)))
50 return '-rpath=' + ':'.join(relpaths) if len(relpaths) else ''
51
52RUST_LIB_RPATH_FLAGS ?= "${@relative_rpaths(d.getVar('RUST_RPATH_ABS', True), d.getVar('rustlibdest', True))}"
53RUST_BIN_RPATH_FLAGS ?= "${@relative_rpaths(d.getVar('RUST_RPATH_ABS', True), d.getVar('rustbindest', True))}"
54
55def libfilename(d):
56 if d.getVar('CRATE_TYPE', True) == 'dylib':
57 return d.getVar('LIBNAME', True) + '.so'
58 else:
59 return d.getVar('LIBNAME', True) + '.rlib'
60
61def link_args(d, bin):
62 linkargs = []
63 if bin:
64 rpaths = d.getVar('RUST_BIN_RPATH_FLAGS', False)
65 else:
66 rpaths = d.getVar('RUST_LIB_RPATH_FLAGS', False)
67 if d.getVar('CRATE_TYPE', True) == 'dylib':
68 linkargs.append('-soname')
69 linkargs.append(libfilename(d))
70 if len(rpaths):
71 linkargs.append(rpaths)
72 if len(linkargs):
73 return ' '.join(['-Wl,' + arg for arg in linkargs])
74 else:
75 return ''
76
77get_overlap_externs () {
78 externs=
79 for dep in ${OVERLAP_DEPS}; do
80 extern=$(ls ${STAGING_DIR_HOST}/${rustlibdir}/lib$dep-rs.{so,rlib} 2>/dev/null \
81 | awk '{print $1}');
82 if [ -n "$extern" ]; then
83 externs="$externs --extern $dep=$extern"
84 else
85 echo "$dep in depends but no such library found in ${rustlibdir}!" >&2
86 exit 1
87 fi
88 done
89 echo "$externs"
90}
91
92do_configure () {
93}
94
95oe_runrustc () {
96 export RUST_TARGET_PATH="${RUST_TARGET_PATH}"
97 bbnote ${RUSTC} ${RUSTC_ARCHFLAGS} ${RUSTC_FLAGS} "$@"
98 "${RUSTC}" ${RUSTC_ARCHFLAGS} ${RUSTC_FLAGS} "$@"
99}
100
101oe_compile_rust_lib () {
102 rm -rf ${LIBNAME}.{rlib,so}
103 local -a link_args
104 if [ -n '${@link_args(d, False)}' ]; then
105 link_args[0]='-C'
106 link_args[1]='link-args=${@link_args(d, False)}'
107 fi
108 oe_runrustc $(get_overlap_externs) \
109 "${link_args[@]}" \
110 ${LIB_SRC} \
111 -o ${@libfilename(d)} \
112 --crate-name=${CRATE_NAME} --crate-type=${CRATE_TYPE} \
113 "$@"
114}
115oe_compile_rust_lib[vardeps] += "get_overlap_externs"
116
117oe_compile_rust_bin () {
118 rm -rf ${BINNAME}
119 local -a link_args
120 if [ -n '${@link_args(d, True)}' ]; then
121 link_args[0]='-C'
122 link_args[1]='link-args=${@link_args(d, True)}'
123 fi
124 oe_runrustc $(get_overlap_externs) \
125 "${link_args[@]}" \
126 ${BIN_SRC} -o ${BINNAME} "$@"
127}
128oe_compile_rust_bin[vardeps] += "get_overlap_externs"
129
130oe_install_rust_lib () {
131 for lib in $(ls ${LIBNAME}.{so,rlib} 2>/dev/null); do
132 echo Installing $lib
133 install -D -m 755 $lib ${D}/${rustlibdest}/$lib
134 done
135}
136
137oe_install_rust_bin () {
138 echo Installing ${BINNAME}
139 install -D -m 755 ${BINNAME} ${D}/${rustbindest}/${BINNAME}
140}
141
142do_rust_bin_fixups() {
143 for f in `find ${PKGD} -name '*.so*'`; do
144 echo "Strip rust note: $f"
145 ${OBJCOPY} -R .note.rustc $f $f
146 done
147}
148PACKAGE_PREPROCESS_FUNCS += "do_rust_bin_fixups"
149
diff --git a/meta/classes/rust-common.bbclass b/meta/classes/rust-common.bbclass
new file mode 100644
index 0000000000..2093654ac6
--- /dev/null
+++ b/meta/classes/rust-common.bbclass
@@ -0,0 +1,174 @@
1# Common variables used by all Rust builds
2export rustlibdir = "${libdir}/rust"
3FILES:${PN} += "${rustlibdir}/*.so"
4FILES:${PN}-dev += "${rustlibdir}/*.rlib ${rustlibdir}/*.rmeta"
5FILES:${PN}-dbg += "${rustlibdir}/.debug"
6
7RUSTLIB = "-L ${STAGING_LIBDIR}/rust"
8RUST_DEBUG_REMAP = "--remap-path-prefix=${WORKDIR}=/usr/src/debug/${PN}/${EXTENDPE}${PV}-${PR}"
9RUSTFLAGS += "${RUSTLIB} ${RUST_DEBUG_REMAP}"
10RUSTLIB_DEP ?= "libstd-rs"
11RUST_TARGET_PATH = "${STAGING_LIBDIR_NATIVE}/rustlib"
12RUST_PANIC_STRATEGY ?= "unwind"
13
14# Native builds are not effected by TCLIBC. Without this, rust-native
15# thinks it's "target" (i.e. x86_64-linux) is a musl target.
16RUST_LIBC = "${TCLIBC}"
17RUST_LIBC:class-native = "glibc"
18
19def determine_libc(d, thing):
20 '''Determine which libc something should target'''
21
22 # BUILD is never musl, TARGET may be musl or glibc,
23 # HOST could be musl, but only if a compiler is built to be run on
24 # target in which case HOST_SYS != BUILD_SYS.
25 if thing == 'TARGET':
26 libc = d.getVar('RUST_LIBC')
27 elif thing == 'BUILD' and (d.getVar('HOST_SYS') != d.getVar('BUILD_SYS')):
28 libc = d.getVar('RUST_LIBC')
29 else:
30 libc = d.getVar('RUST_LIBC:class-native')
31
32 return libc
33
34def target_is_armv7(d):
35 '''Determine if target is armv7'''
36 # TUNE_FEATURES may include arm* even if the target is not arm
37 # in the case of *-native packages
38 if d.getVar('TARGET_ARCH') != 'arm':
39 return False
40
41 feat = d.getVar('TUNE_FEATURES')
42 feat = frozenset(feat.split())
43 mach_overrides = d.getVar('MACHINEOVERRIDES')
44 mach_overrides = frozenset(mach_overrides.split(':'))
45
46 v7=frozenset(['armv7a', 'armv7r', 'armv7m', 'armv7ve'])
47 if mach_overrides.isdisjoint(v7) and feat.isdisjoint(v7):
48 return False
49 else:
50 return True
51
52# Responsible for taking Yocto triples and converting it to Rust triples
53def rust_base_triple(d, thing):
54 '''
55 Mangle bitbake's *_SYS into something that rust might support (see
56 rust/mk/cfg/* for a list)
57
58 Note that os is assumed to be some linux form
59 '''
60
61 # The llvm-target for armv7 is armv7-unknown-linux-gnueabihf
62 if thing == "TARGET" and target_is_armv7(d):
63 arch = "armv7"
64 else:
65 arch = d.getVar('{}_ARCH'.format(thing))
66
67 # All the Yocto targets are Linux and are 'unknown'
68 vendor = "-unknown"
69 os = d.getVar('{}_OS'.format(thing))
70 libc = determine_libc(d, thing)
71
72 # Prefix with a dash and convert glibc -> gnu
73 if libc == "glibc":
74 libc = "-gnu"
75 elif libc == "musl":
76 libc = "-musl"
77
78 # Don't double up musl (only appears to be the case on aarch64)
79 if os == "linux-musl":
80 if libc != "-musl":
81 bb.fatal("{}_OS was '{}' but TCLIBC was not 'musl'".format(thing, os))
82 os = "linux"
83
84 # This catches ARM targets and appends the necessary hard float bits
85 if os == "linux-gnueabi" or os == "linux-musleabi":
86 libc = bb.utils.contains('TUNE_FEATURES', 'callconvention-hard', 'hf', '', d)
87 return arch + vendor + '-' + os + libc
88
89# Naming explanation
90# Yocto
91# - BUILD_SYS - Yocto triple of the build environment
92# - HOST_SYS - What we're building for in Yocto
93# - TARGET_SYS - What we're building for in Yocto
94#
95# So when building '-native' packages BUILD_SYS == HOST_SYS == TARGET_SYS
96# When building packages for the image HOST_SYS == TARGET_SYS
97# This is a gross over simplification as there are other modes but
98# currently this is all that's supported.
99#
100# Rust
101# - TARGET - the system where the binary will run
102# - HOST - the system where the binary is being built
103#
104# Rust additionally will use two additional cases:
105# - undecorated (e.g. CC) - equivalent to TARGET
106# - triple suffix (e.g. CC:x86_64_unknown_linux_gnu) - both
107# see: https://github.com/alexcrichton/gcc-rs
108# The way that Rust's internal triples and Yocto triples are mapped together
109# its likely best to not use the triple suffix due to potential confusion.
110
111RUST_BUILD_SYS = "${@rust_base_triple(d, 'BUILD')}"
112RUST_HOST_SYS = "${@rust_base_triple(d, 'HOST')}"
113RUST_TARGET_SYS = "${@rust_base_triple(d, 'TARGET')}"
114
115# wrappers to get around the fact that Rust needs a single
116# binary but Yocto's compiler and linker commands have
117# arguments. Technically the archiver is always one command but
118# this is necessary for builds that determine the prefix and then
119# use those commands based on the prefix.
120WRAPPER_DIR = "${WORKDIR}/wrapper"
121RUST_BUILD_CC = "${WRAPPER_DIR}/build-rust-cc"
122RUST_BUILD_CXX = "${WRAPPER_DIR}/build-rust-cxx"
123RUST_BUILD_CCLD = "${WRAPPER_DIR}/build-rust-ccld"
124RUST_BUILD_AR = "${WRAPPER_DIR}/build-rust-ar"
125RUST_TARGET_CC = "${WRAPPER_DIR}/target-rust-cc"
126RUST_TARGET_CXX = "${WRAPPER_DIR}/target-rust-cxx"
127RUST_TARGET_CCLD = "${WRAPPER_DIR}/target-rust-ccld"
128RUST_TARGET_AR = "${WRAPPER_DIR}/target-rust-ar"
129
130create_wrapper () {
131 file="$1"
132 shift
133
134 cat <<- EOF > "${file}"
135 #!/bin/sh
136 exec $@ "\$@"
137 EOF
138 chmod +x "${file}"
139}
140
141export WRAPPER_TARGET_CC = "${CC}"
142export WRAPPER_TARGET_CXX = "${CXX}"
143export WRAPPER_TARGET_CCLD = "${CCLD}"
144export WRAPPER_TARGET_LDFLAGS = "${LDFLAGS}"
145export WRAPPER_TARGET_AR = "${AR}"
146
147# compiler is used by gcc-rs
148# linker is used by rustc/cargo
149# archiver is used by the build of libstd-rs
150do_rust_create_wrappers () {
151 mkdir -p "${WRAPPER_DIR}"
152
153 # Yocto Build / Rust Host C compiler
154 create_wrapper "${RUST_BUILD_CC}" "${BUILD_CC}"
155 # Yocto Build / Rust Host C++ compiler
156 create_wrapper "${RUST_BUILD_CXX}" "${BUILD_CXX}"
157 # Yocto Build / Rust Host linker
158 create_wrapper "${RUST_BUILD_CCLD}" "${BUILD_CCLD}" "${BUILD_LDFLAGS}"
159 # Yocto Build / Rust Host archiver
160 create_wrapper "${RUST_BUILD_AR}" "${BUILD_AR}"
161
162 # Yocto Target / Rust Target C compiler
163 create_wrapper "${RUST_TARGET_CC}" "${WRAPPER_TARGET_CC}"
164 # Yocto Target / Rust Target C++ compiler
165 create_wrapper "${RUST_TARGET_CXX}" "${WRAPPER_TARGET_CXX}"
166 # Yocto Target / Rust Target linker
167 create_wrapper "${RUST_TARGET_CCLD}" "${WRAPPER_TARGET_CCLD}" "${WRAPPER_TARGET_LDFLAGS}"
168 # Yocto Target / Rust Target archiver
169 create_wrapper "${RUST_TARGET_AR}" "${WRAPPER_TARGET_AR}"
170
171}
172
173addtask rust_create_wrappers before do_configure after do_patch
174do_rust_create_wrappers[dirs] += "${WRAPPER_DIR}"
diff --git a/meta/classes/rust.bbclass b/meta/classes/rust.bbclass
new file mode 100644
index 0000000000..5c8938d09f
--- /dev/null
+++ b/meta/classes/rust.bbclass
@@ -0,0 +1,45 @@
1inherit rust-common
2
3RUSTC = "rustc"
4
5RUSTC_ARCHFLAGS += "--target=${HOST_SYS} ${RUSTFLAGS}"
6
7def rust_base_dep(d):
8 # Taken from meta/classes/base.bbclass `base_dep_prepend` and modified to
9 # use rust instead of gcc
10 deps = ""
11 if not d.getVar('INHIBIT_DEFAULT_RUST_DEPS'):
12 if (d.getVar('HOST_SYS') != d.getVar('BUILD_SYS')):
13 deps += " virtual/${TARGET_PREFIX}rust ${RUSTLIB_DEP}"
14 else:
15 deps += " rust-native"
16 return deps
17
18DEPENDS:append = " ${@rust_base_dep(d)}"
19
20# BUILD_LDFLAGS
21# ${STAGING_LIBDIR_NATIVE}
22# ${STAGING_BASE_LIBDIR_NATIVE}
23# BUILDSDK_LDFLAGS
24# ${STAGING_LIBDIR}
25# #{STAGING_DIR_HOST}
26# TARGET_LDFLAGS ?????
27#RUSTC_BUILD_LDFLAGS = "\
28# --sysroot ${STAGING_DIR_NATIVE} \
29# -L${STAGING_LIBDIR_NATIVE} \
30# -L${STAGING_BASE_LIBDIR_NATIVE} \
31#"
32
33# XXX: for some reason bitbake sets BUILD_* & TARGET_* but uses the bare
34# variables for HOST. Alias things to make it easier for us.
35HOST_LDFLAGS ?= "${LDFLAGS}"
36HOST_CFLAGS ?= "${CFLAGS}"
37HOST_CXXFLAGS ?= "${CXXFLAGS}"
38HOST_CPPFLAGS ?= "${CPPFLAGS}"
39
40rustlib_suffix="${TUNE_ARCH}${TARGET_VENDOR}-${TARGET_OS}/rustlib/${HOST_SYS}/lib"
41# Native sysroot standard library path
42rustlib_src="${prefix}/lib/${rustlib_suffix}"
43# Host sysroot standard library path
44rustlib="${libdir}/${rustlib_suffix}"
45rustlib:class-native="${libdir}/rustlib/${BUILD_SYS}/lib"