Skip to content

Commit

Permalink
review feedback: use only environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
sarfata committed Oct 9, 2023
1 parent 9248711 commit 223fb15
Showing 1 changed file with 19 additions and 45 deletions.
64 changes: 19 additions & 45 deletions classes/cargo_bin.bbclass
Original file line number Diff line number Diff line change
Expand Up @@ -51,34 +51,6 @@ CARGO_BUILD_FLAGS = "\
${EXTRA_CARGO_FLAGS} \
"

create_cargo_config() {
if [ "${RUST_BUILD}" != "${RUST_TARGET}" ]; then
echo > ${CARGO_HOME}/config
echo "[target.${RUST_BUILD}]" >> ${CARGO_HOME}/config
echo "linker = '${WRAPPER_DIR}/linker-native-wrapper.sh'" >> ${CARGO_HOME}/config

echo >> ${CARGO_HOME}/config
echo "[target.${RUST_TARGET}]" >> ${CARGO_HOME}/config
echo "linker = '${WRAPPER_DIR}/linker-wrapper.sh'" >> ${CARGO_HOME}/config
else
echo > ${CARGO_HOME}/config
echo "[target.${RUST_TARGET}]" >> ${CARGO_HOME}/config
echo "linker = '${WRAPPER_DIR}/linker-wrapper.sh'" >> ${CARGO_HOME}/config

# (Rust unstable) - See do_compile below.
echo "[host]" >> ${CARGO_HOME}/config
echo "linker = '${WRAPPER_DIR}/linker-native-wrapper.sh'" >> ${CARGO_HOME}/config
fi

echo >> ${CARGO_HOME}/config
echo "[build]" >> ${CARGO_HOME}/config
echo "rustflags = ['-C', 'rpath']" >> ${CARGO_HOME}/config

echo >> ${CARGO_HOME}/config
echo "[profile.release]" >> ${CARGO_HOME}/config
echo "debug = true" >> ${CARGO_HOME}/config
}

cargo_bin_do_configure() {
mkdir -p "${B}"
mkdir -p "${CARGO_HOME}"
Expand Down Expand Up @@ -110,9 +82,6 @@ cargo_bin_do_configure() {
echo "#!/bin/sh" >"${WRAPPER_DIR}/linker-native-wrapper.sh"
echo "${BUILD_CC} ${BUILD_LDFLAGS} \"\$@\"" >>"${WRAPPER_DIR}/linker-native-wrapper.sh"
chmod +x "${WRAPPER_DIR}/linker-native-wrapper.sh"

# Create our global config in CARGO_HOME
create_cargo_config
}

cargo_bin_do_compile() {
Expand All @@ -123,20 +92,25 @@ cargo_bin_do_compile() {
export PKG_CONFIG_ALLOW_CROSS="1"
export LDFLAGS=""
export RUSTFLAGS="${RUSTFLAGS}"
export SSH_AUTH_SOCK="${SSH_AUTH_SOCK}"
# When RUST_BUILD == RUST_TARGET, we need to use an unstable Rust feature
# to specify different build options for the target and the Host.
# The Host configuration is set in do_configure() above.
if [ "${RUST_BUILD}" = "${RUST_TARGET}" ]; then
export __CARGO_TEST_CHANNEL_OVERRIDE_DO_NOT_USE_THIS="nightly"
export CARGO_UNSTABLE_TARGET_APPLIES_TO_HOST="true"
export CARGO_UNSTABLE_HOST_CONFIG="true"
export CARGO_TARGET_APPLIES_TO_HOST="false"

# Make sure the cc crate does not use CFLAGS when building for the host.
export HOST_CFLAGS=""
export HOST_CXXFLAGS=""
fi

# This "DO_NOT_USE_THIS" option of cargo is currently the only way to
# configure a different linker for host and target builds when RUST_BUILD ==
# RUST_TARGET.
export __CARGO_TEST_CHANNEL_OVERRIDE_DO_NOT_USE_THIS="nightly"
export CARGO_UNSTABLE_TARGET_APPLIES_TO_HOST="true"
export CARGO_UNSTABLE_HOST_CONFIG="true"
export CARGO_TARGET_APPLIES_TO_HOST="false"
export CARGO_TARGET_${@rust_target(d, 'BUILD').replace('-','_')}_LINKER="${WRAPPER_DIR}/linker-wrapper.sh"
export CARGO_HOST_LINKER="${WRAPPER_DIR}/linker-native-wrapper.sh"
export CARGO_BUILD_FLAGS="-C rpath"
export CARGO_PROFILE_RELEASE_DEBUG="true"


# The CC crate defaults to using CFLAGS when compiling everything. We can
# give it custom flags for compiling on the host.
export HOST_CXXFLAGS=""
export HOST_CFLAGS=""

bbnote "which rustc:" `which rustc`
bbnote "rustc --version" `rustc --version`
bbnote "which cargo:" `which cargo`
Expand Down

0 comments on commit 223fb15

Please sign in to comment.