summaryrefslogtreecommitdiffstats
path: root/meta/classes/cargo_common.bbclass
diff options
context:
space:
mode:
authorRandy MacLeod <Randy.MacLeod@windriver.com>2021-08-10 17:52:19 (GMT)
committerRichard Purdie <richard.purdie@linuxfoundation.org>2021-08-26 21:09:43 (GMT)
commit61e1570c6a09c1984e919e8c0a82a74c1a08d821 (patch)
treeaccab4b08aa3c62f098c9bb19399efb46906256a /meta/classes/cargo_common.bbclass
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/cargo_common.bbclass')
-rw-r--r--meta/classes/cargo_common.bbclass129
1 files changed, 129 insertions, 0 deletions
diff --git a/meta/classes/cargo_common.bbclass b/meta/classes/cargo_common.bbclass
new file mode 100644
index 0000000..b0b039a
--- /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