blob: 23d82aa6ab25300a5d1182740d7a7636adf3aa18 [file] [log] [blame]
Andrew Geisslerd159c7f2021-09-02 21:05:58 -05001##
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 cat <<- EOF >> ${CARGO_HOME}/config
71
72 # HOST_SYS
73 [target.${HOST_SYS}]
74 linker = "${CARGO_RUST_TARGET_CCLD}"
75 EOF
76
77 if [ "${HOST_SYS}" != "${BUILD_SYS}" ]; then
78 cat <<- EOF >> ${CARGO_HOME}/config
79
80 # BUILD_SYS
81 [target.${BUILD_SYS}]
82 linker = "${RUST_BUILD_CCLD}"
83 EOF
84 fi
85
86 # Put build output in build directory preferred by bitbake instead of
87 # inside source directory unless they are the same
88 if [ "${B}" != "${S}" ]; then
89 cat <<- EOF >> ${CARGO_HOME}/config
90
91 [build]
92 # Use out of tree build destination to avoid poluting the source tree
93 target-dir = "${B}/target"
94 EOF
95 fi
96
97 cat <<- EOF >> ${CARGO_HOME}/config
98
99 [term]
100 progress.when = 'always'
101 progress.width = 80
102 EOF
103}
104
105oe_cargo_fix_env () {
106 export CC="${RUST_TARGET_CC}"
107 export CXX="${RUST_TARGET_CXX}"
108 export CFLAGS="${CFLAGS}"
109 export CXXFLAGS="${CXXFLAGS}"
110 export AR="${AR}"
111 export TARGET_CC="${RUST_TARGET_CC}"
112 export TARGET_CXX="${RUST_TARGET_CXX}"
113 export TARGET_CFLAGS="${CFLAGS}"
114 export TARGET_CXXFLAGS="${CXXFLAGS}"
115 export TARGET_AR="${AR}"
116 export HOST_CC="${RUST_BUILD_CC}"
117 export HOST_CXX="${RUST_BUILD_CXX}"
118 export HOST_CFLAGS="${BUILD_CFLAGS}"
119 export HOST_CXXFLAGS="${BUILD_CXXFLAGS}"
120 export HOST_AR="${BUILD_AR}"
121}
122
123EXTRA_OECARGO_PATHS ??= ""
124
125EXPORT_FUNCTIONS do_configure