blob: 39f32829fd44b9653581f90aaa923c06ed97614e [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
Andrew Geisslerd159c7f2021-09-02 21:05:58 -050012inherit rust-common
13
14# Where we download our registry and dependencies to
15export CARGO_HOME = "${WORKDIR}/cargo_home"
16
17# The pkg-config-rs library used by cargo build scripts disables itself when
18# cross compiling unless this is defined. We set up pkg-config appropriately
19# for cross compilation, so tell it we know better than it.
20export PKG_CONFIG_ALLOW_CROSS = "1"
21
22# Don't instruct cargo to use crates downloaded by bitbake. Some rust packages,
23# for example the rust compiler itself, come with their own vendored sources.
24# Specifying two [source.crates-io] will not work.
25CARGO_DISABLE_BITBAKE_VENDORING ?= "0"
26
27# Used by libstd-rs to point to the vendor dir included in rustc src
28CARGO_VENDORING_DIRECTORY ?= "${CARGO_HOME}/bitbake"
29
30CARGO_RUST_TARGET_CCLD ?= "${RUST_TARGET_CCLD}"
31cargo_common_do_configure () {
32 mkdir -p ${CARGO_HOME}/bitbake
33
34 cat <<- EOF > ${CARGO_HOME}/config
35 # EXTRA_OECARGO_PATHS
36 paths = [
37 $(for p in ${EXTRA_OECARGO_PATHS}; do echo \"$p\",; done)
38 ]
39 EOF
40
41 cat <<- EOF >> ${CARGO_HOME}/config
42
43 # Local mirror vendored by bitbake
44 [source.bitbake]
45 directory = "${CARGO_VENDORING_DIRECTORY}"
46 EOF
47
Andrew Geisslerd5838332022-05-27 11:33:10 -050048 if [ ${CARGO_DISABLE_BITBAKE_VENDORING} = "0" ]; then
Andrew Geisslerd159c7f2021-09-02 21:05:58 -050049 cat <<- EOF >> ${CARGO_HOME}/config
50
51 [source.crates-io]
52 replace-with = "bitbake"
53 local-registry = "/nonexistant"
54 EOF
55 fi
56
57 cat <<- EOF >> ${CARGO_HOME}/config
58
59 [http]
60 # Multiplexing can't be enabled because http2 can't be enabled
61 # in curl-native without dependency loops
62 multiplexing = false
63
64 # Ignore the hard coded and incorrect path to certificates
65 cainfo = "${STAGING_ETCDIR_NATIVE}/ssl/certs/ca-certificates.crt"
66
67 EOF
68
69 cat <<- EOF >> ${CARGO_HOME}/config
70
71 # HOST_SYS
72 [target.${HOST_SYS}]
73 linker = "${CARGO_RUST_TARGET_CCLD}"
74 EOF
75
76 if [ "${HOST_SYS}" != "${BUILD_SYS}" ]; then
77 cat <<- EOF >> ${CARGO_HOME}/config
78
79 # BUILD_SYS
80 [target.${BUILD_SYS}]
81 linker = "${RUST_BUILD_CCLD}"
82 EOF
83 fi
84
85 # Put build output in build directory preferred by bitbake instead of
86 # inside source directory unless they are the same
87 if [ "${B}" != "${S}" ]; then
88 cat <<- EOF >> ${CARGO_HOME}/config
89
90 [build]
91 # Use out of tree build destination to avoid poluting the source tree
92 target-dir = "${B}/target"
93 EOF
94 fi
95
96 cat <<- EOF >> ${CARGO_HOME}/config
97
98 [term]
99 progress.when = 'always'
100 progress.width = 80
101 EOF
102}
103
104oe_cargo_fix_env () {
105 export CC="${RUST_TARGET_CC}"
106 export CXX="${RUST_TARGET_CXX}"
107 export CFLAGS="${CFLAGS}"
108 export CXXFLAGS="${CXXFLAGS}"
109 export AR="${AR}"
110 export TARGET_CC="${RUST_TARGET_CC}"
111 export TARGET_CXX="${RUST_TARGET_CXX}"
112 export TARGET_CFLAGS="${CFLAGS}"
113 export TARGET_CXXFLAGS="${CXXFLAGS}"
114 export TARGET_AR="${AR}"
115 export HOST_CC="${RUST_BUILD_CC}"
116 export HOST_CXX="${RUST_BUILD_CXX}"
117 export HOST_CFLAGS="${BUILD_CFLAGS}"
118 export HOST_CXXFLAGS="${BUILD_CXXFLAGS}"
119 export HOST_AR="${BUILD_AR}"
120}
121
122EXTRA_OECARGO_PATHS ??= ""
123
124EXPORT_FUNCTIONS do_configure