summaryrefslogtreecommitdiffstats
path: root/meta/classes-recipe/cargo_common.bbclass
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2022-08-10 14:35:29 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2022-08-12 15:27:17 +0100
commitfd1517e2b51a170f2427122c6b95396db251d827 (patch)
treedabfe3e631339c2fc99a9ee7febb0f9c128e325e /meta/classes-recipe/cargo_common.bbclass
parent10317912ee319ccf7f83605d438b5cbf9663f296 (diff)
downloadpoky-fd1517e2b51a170f2427122c6b95396db251d827.tar.gz
classes: Update classes to match new bitbake class scope functionality
Move classes to classes-global or classes-recipe as appropriate to take advantage of new bitbake functionality to check class scope/usage. (From OE-Core rev: f5c128008365e141082c129417eb72d2751e8045) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/classes-recipe/cargo_common.bbclass')
-rw-r--r--meta/classes-recipe/cargo_common.bbclass139
1 files changed, 139 insertions, 0 deletions
diff --git a/meta/classes-recipe/cargo_common.bbclass b/meta/classes-recipe/cargo_common.bbclass
new file mode 100644
index 0000000000..eec7710a4c
--- /dev/null
+++ b/meta/classes-recipe/cargo_common.bbclass
@@ -0,0 +1,139 @@
1#
2# Copyright OpenEmbedded Contributors
3#
4# SPDX-License-Identifier: MIT
5#
6
7##
8## Purpose:
9## This class is to support building with cargo. It
10## must be different than cargo.bbclass because Rust
11## now builds with Cargo but cannot use cargo.bbclass
12## due to dependencies and assumptions in cargo.bbclass
13## that Rust & Cargo are already installed. So this
14## is used by cargo.bbclass and Rust
15##
16
17# add crate fetch support
18inherit rust-common
19
20# Where we download our registry and dependencies to
21export CARGO_HOME = "${WORKDIR}/cargo_home"
22
23# The pkg-config-rs library used by cargo build scripts disables itself when
24# cross compiling unless this is defined. We set up pkg-config appropriately
25# for cross compilation, so tell it we know better than it.
26export PKG_CONFIG_ALLOW_CROSS = "1"
27
28# Don't instruct cargo to use crates downloaded by bitbake. Some rust packages,
29# for example the rust compiler itself, come with their own vendored sources.
30# Specifying two [source.crates-io] will not work.
31CARGO_DISABLE_BITBAKE_VENDORING ?= "0"
32
33# Used by libstd-rs to point to the vendor dir included in rustc src
34CARGO_VENDORING_DIRECTORY ?= "${CARGO_HOME}/bitbake"
35
36CARGO_RUST_TARGET_CCLD ?= "${RUST_TARGET_CCLD}"
37cargo_common_do_configure () {
38 mkdir -p ${CARGO_HOME}/bitbake
39
40 cat <<- EOF > ${CARGO_HOME}/config
41 # EXTRA_OECARGO_PATHS
42 paths = [
43 $(for p in ${EXTRA_OECARGO_PATHS}; do echo \"$p\",; done)
44 ]
45 EOF
46
47 cat <<- EOF >> ${CARGO_HOME}/config
48
49 # Local mirror vendored by bitbake
50 [source.bitbake]
51 directory = "${CARGO_VENDORING_DIRECTORY}"
52 EOF
53
54 if [ ${CARGO_DISABLE_BITBAKE_VENDORING} = "0" ]; then
55 cat <<- EOF >> ${CARGO_HOME}/config
56
57 [source.crates-io]
58 replace-with = "bitbake"
59 local-registry = "/nonexistant"
60 EOF
61 fi
62
63 cat <<- EOF >> ${CARGO_HOME}/config
64
65 [http]
66 # Multiplexing can't be enabled because http2 can't be enabled
67 # in curl-native without dependency loops
68 multiplexing = false
69
70 # Ignore the hard coded and incorrect path to certificates
71 cainfo = "${STAGING_ETCDIR_NATIVE}/ssl/certs/ca-certificates.crt"
72
73 EOF
74
75 cat <<- EOF >> ${CARGO_HOME}/config
76
77 # HOST_SYS
78 [target.${RUST_HOST_SYS}]
79 linker = "${CARGO_RUST_TARGET_CCLD}"
80 EOF
81
82 if [ "${RUST_HOST_SYS}" != "${RUST_BUILD_SYS}" ]; then
83 cat <<- EOF >> ${CARGO_HOME}/config
84
85 # BUILD_SYS
86 [target.${RUST_BUILD_SYS}]
87 linker = "${RUST_BUILD_CCLD}"
88 EOF
89 fi
90
91 if [ "${RUST_TARGET_SYS}" != "${RUST_BUILD_SYS}" -a "${RUST_TARGET_SYS}" != "${RUST_HOST_SYS}"]; then
92 cat <<- EOF >> ${CARGO_HOME}/config
93
94 # TARGET_SYS
95 [target.${RUST_TARGET_SYS}]
96 linker = "${RUST_TARGET_CCLD}"
97 EOF
98 fi
99
100 # Put build output in build directory preferred by bitbake instead of
101 # inside source directory unless they are the same
102 if [ "${B}" != "${S}" ]; then
103 cat <<- EOF >> ${CARGO_HOME}/config
104
105 [build]
106 # Use out of tree build destination to avoid poluting the source tree
107 target-dir = "${B}/target"
108 EOF
109 fi
110
111 cat <<- EOF >> ${CARGO_HOME}/config
112
113 [term]
114 progress.when = 'always'
115 progress.width = 80
116 EOF
117}
118
119oe_cargo_fix_env () {
120 export CC="${RUST_TARGET_CC}"
121 export CXX="${RUST_TARGET_CXX}"
122 export CFLAGS="${CFLAGS}"
123 export CXXFLAGS="${CXXFLAGS}"
124 export AR="${AR}"
125 export TARGET_CC="${RUST_TARGET_CC}"
126 export TARGET_CXX="${RUST_TARGET_CXX}"
127 export TARGET_CFLAGS="${CFLAGS}"
128 export TARGET_CXXFLAGS="${CXXFLAGS}"
129 export TARGET_AR="${AR}"
130 export HOST_CC="${RUST_BUILD_CC}"
131 export HOST_CXX="${RUST_BUILD_CXX}"
132 export HOST_CFLAGS="${BUILD_CFLAGS}"
133 export HOST_CXXFLAGS="${BUILD_CXXFLAGS}"
134 export HOST_AR="${BUILD_AR}"
135}
136
137EXTRA_OECARGO_PATHS ??= ""
138
139EXPORT_FUNCTIONS do_configure