Skip to content

Commit

Permalink
Merge pull request #146 from sarfata/sarfata/fix-build-when-target_ar…
Browse files Browse the repository at this point in the history
…ch==build_arch

fix: build when target_arch==build_arch
  • Loading branch information
posborne authored Oct 10, 2023
2 parents 7ac87ec + 8fb174f commit 2089ae6
Showing 1 changed file with 18 additions and 29 deletions.
47 changes: 18 additions & 29 deletions classes/cargo_bin.bbclass
Original file line number Diff line number Diff line change
Expand Up @@ -51,30 +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
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 @@ -106,22 +82,35 @@ 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() {
export TARGET_CC="${WRAPPER_DIR}/cc-wrapper.sh"
export TARGET_CXX="${WRAPPER_DIR}/cxx-wrapper.sh"
export CC="${WRAPPER_DIR}/cc-native-wrapper.sh"
export CXX="${WRAPPER_DIR}/cxx-native-wrapper.sh"
export TARGET_LD="${WRAPPER_DIR}/ld-wrapper.sh"
export LD="${WRAPPER_DIR}/ld-native-wrapper.sh"
export PKG_CONFIG_ALLOW_CROSS="1"
export LDFLAGS=""
export RUSTFLAGS="${RUSTFLAGS}"
export SSH_AUTH_SOCK="${SSH_AUTH_SOCK}"

# 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 2089ae6

Please sign in to comment.