Skip to content

Commit 223fb15

Browse files
committed
review feedback: use only environment variables
1 parent 9248711 commit 223fb15

File tree

1 file changed

+19
-45
lines changed

1 file changed

+19
-45
lines changed

classes/cargo_bin.bbclass

+19-45
Original file line numberDiff line numberDiff line change
@@ -51,34 +51,6 @@ CARGO_BUILD_FLAGS = "\
5151
${EXTRA_CARGO_FLAGS} \
5252
"
5353

54-
create_cargo_config() {
55-
if [ "${RUST_BUILD}" != "${RUST_TARGET}" ]; then
56-
echo > ${CARGO_HOME}/config
57-
echo "[target.${RUST_BUILD}]" >> ${CARGO_HOME}/config
58-
echo "linker = '${WRAPPER_DIR}/linker-native-wrapper.sh'" >> ${CARGO_HOME}/config
59-
60-
echo >> ${CARGO_HOME}/config
61-
echo "[target.${RUST_TARGET}]" >> ${CARGO_HOME}/config
62-
echo "linker = '${WRAPPER_DIR}/linker-wrapper.sh'" >> ${CARGO_HOME}/config
63-
else
64-
echo > ${CARGO_HOME}/config
65-
echo "[target.${RUST_TARGET}]" >> ${CARGO_HOME}/config
66-
echo "linker = '${WRAPPER_DIR}/linker-wrapper.sh'" >> ${CARGO_HOME}/config
67-
68-
# (Rust unstable) - See do_compile below.
69-
echo "[host]" >> ${CARGO_HOME}/config
70-
echo "linker = '${WRAPPER_DIR}/linker-native-wrapper.sh'" >> ${CARGO_HOME}/config
71-
fi
72-
73-
echo >> ${CARGO_HOME}/config
74-
echo "[build]" >> ${CARGO_HOME}/config
75-
echo "rustflags = ['-C', 'rpath']" >> ${CARGO_HOME}/config
76-
77-
echo >> ${CARGO_HOME}/config
78-
echo "[profile.release]" >> ${CARGO_HOME}/config
79-
echo "debug = true" >> ${CARGO_HOME}/config
80-
}
81-
8254
cargo_bin_do_configure() {
8355
mkdir -p "${B}"
8456
mkdir -p "${CARGO_HOME}"
@@ -110,9 +82,6 @@ cargo_bin_do_configure() {
11082
echo "#!/bin/sh" >"${WRAPPER_DIR}/linker-native-wrapper.sh"
11183
echo "${BUILD_CC} ${BUILD_LDFLAGS} \"\$@\"" >>"${WRAPPER_DIR}/linker-native-wrapper.sh"
11284
chmod +x "${WRAPPER_DIR}/linker-native-wrapper.sh"
113-
114-
# Create our global config in CARGO_HOME
115-
create_cargo_config
11685
}
11786

11887
cargo_bin_do_compile() {
@@ -123,20 +92,25 @@ cargo_bin_do_compile() {
12392
export PKG_CONFIG_ALLOW_CROSS="1"
12493
export LDFLAGS=""
12594
export RUSTFLAGS="${RUSTFLAGS}"
126-
export SSH_AUTH_SOCK="${SSH_AUTH_SOCK}"
127-
# When RUST_BUILD == RUST_TARGET, we need to use an unstable Rust feature
128-
# to specify different build options for the target and the Host.
129-
# The Host configuration is set in do_configure() above.
130-
if [ "${RUST_BUILD}" = "${RUST_TARGET}" ]; then
131-
export __CARGO_TEST_CHANNEL_OVERRIDE_DO_NOT_USE_THIS="nightly"
132-
export CARGO_UNSTABLE_TARGET_APPLIES_TO_HOST="true"
133-
export CARGO_UNSTABLE_HOST_CONFIG="true"
134-
export CARGO_TARGET_APPLIES_TO_HOST="false"
135-
136-
# Make sure the cc crate does not use CFLAGS when building for the host.
137-
export HOST_CFLAGS=""
138-
export HOST_CXXFLAGS=""
139-
fi
95+
96+
# This "DO_NOT_USE_THIS" option of cargo is currently the only way to
97+
# configure a different linker for host and target builds when RUST_BUILD ==
98+
# RUST_TARGET.
99+
export __CARGO_TEST_CHANNEL_OVERRIDE_DO_NOT_USE_THIS="nightly"
100+
export CARGO_UNSTABLE_TARGET_APPLIES_TO_HOST="true"
101+
export CARGO_UNSTABLE_HOST_CONFIG="true"
102+
export CARGO_TARGET_APPLIES_TO_HOST="false"
103+
export CARGO_TARGET_${@rust_target(d, 'BUILD').replace('-','_')}_LINKER="${WRAPPER_DIR}/linker-wrapper.sh"
104+
export CARGO_HOST_LINKER="${WRAPPER_DIR}/linker-native-wrapper.sh"
105+
export CARGO_BUILD_FLAGS="-C rpath"
106+
export CARGO_PROFILE_RELEASE_DEBUG="true"
107+
108+
109+
# The CC crate defaults to using CFLAGS when compiling everything. We can
110+
# give it custom flags for compiling on the host.
111+
export HOST_CXXFLAGS=""
112+
export HOST_CFLAGS=""
113+
140114
bbnote "which rustc:" `which rustc`
141115
bbnote "rustc --version" `rustc --version`
142116
bbnote "which cargo:" `which cargo`

0 commit comments

Comments
 (0)