Merge pull request #119 from cardoe/continued-build-updates
Continued build updates
This commit is contained in:
+13
-33
@@ -30,9 +30,6 @@ export PKG_CONFIG_ALLOW_CROSS = "1"
|
|||||||
|
|
||||||
cargo_do_configure () {
|
cargo_do_configure () {
|
||||||
mkdir -p ${CARGO_HOME}
|
mkdir -p ${CARGO_HOME}
|
||||||
# NOTE: we cannot pass more flags via this interface, the 'linker' is
|
|
||||||
# assumed to be a path to a binary. If flags are needed, a wrapper must
|
|
||||||
# be used.
|
|
||||||
echo "paths = [" > ${CARGO_HOME}/config
|
echo "paths = [" > ${CARGO_HOME}/config
|
||||||
|
|
||||||
for p in ${EXTRA_OECARGO_PATHS}; do
|
for p in ${EXTRA_OECARGO_PATHS}; do
|
||||||
@@ -49,39 +46,22 @@ replace-with = "local"
|
|||||||
registry = "https://github.com/rust-lang/crates.io-index"
|
registry = "https://github.com/rust-lang/crates.io-index"
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
# We need to use the real Yocto linker and get the linker
|
echo "[target.${HOST_SYS}]" >> ${CARGO_HOME}/config
|
||||||
# flags to it. Yocto has the concept of BUILD and TARGET
|
echo "linker = '${RUST_TARGET_CCLD}'" >> ${CARGO_HOME}/config
|
||||||
# and uses HOST to be the currently selected one. However
|
if [ "${HOST_SYS}" != "${BUILD_SYS}" ]; then
|
||||||
# LDFLAGS and TOOLCHAIN_OPTIONS are not prefixed with HOST
|
echo "[target.${BUILD_SYS}]" >> ${CARGO_HOME}/config
|
||||||
echo "[build]" >> ${CARGO_HOME}/config
|
echo "linker = '${RUST_BUILD_CCLD}'" >> ${CARGO_HOME}/config
|
||||||
echo "rustflags = [" >> ${CARGO_HOME}/config
|
fi
|
||||||
echo "'-C'," >> ${CARGO_HOME}/config
|
|
||||||
echo "'link-args=${LDFLAGS}${HOST_CC_ARCH}${TOOLCHAIN_OPTIONS}'," >> ${CARGO_HOME}/config
|
|
||||||
for p in ${RUSTFLAGS}; do
|
|
||||||
printf "'%s'\n" "$p"
|
|
||||||
done | sed -e 's/$/,/' >> ${CARGO_HOME}/config
|
|
||||||
echo "]" >> ${CARGO_HOME}/config
|
|
||||||
echo "[target.${RUST_HOST_SYS}]" >> ${CARGO_HOME}/config
|
|
||||||
echo "linker = '${HOST_PREFIX}gcc'" >> ${CARGO_HOME}/config
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# All the rust & cargo ecosystem assume that CC, LD, etc are a path to a single
|
RUSTFLAGS ??= ""
|
||||||
# command. Fixup the ones we give it so that is the case.
|
|
||||||
# XXX: this is hard coded based on meta/conf/bitbake.conf
|
|
||||||
# TODO: we do quite a bit very similar to this in rust.inc, see if it can be
|
|
||||||
# generalized.
|
|
||||||
export RUST_CC = "${CCACHE}${HOST_PREFIX}gcc"
|
|
||||||
export RUST_CFLAGS = "${HOST_CC_ARCH}${TOOLCHAIN_OPTIONS} ${CFLAGS}"
|
|
||||||
export RUST_BUILD_CC = "${CCACHE}${BUILD_PREFIX}gcc"
|
|
||||||
export RUST_BUILD_CFLAGS = "${BUILD_CC_ARCH} ${BUILD_CFLAGS}"
|
|
||||||
|
|
||||||
CARGO_BUILD_FLAGS = "-v --target ${HOST_SYS} --release"
|
CARGO_BUILD_FLAGS = "-v --target ${HOST_SYS} --release"
|
||||||
|
|
||||||
# This is based on the content of CARGO_BUILD_FLAGS and generally will need to
|
# This is based on the content of CARGO_BUILD_FLAGS and generally will need to
|
||||||
# change if CARGO_BUILD_FLAGS changes.
|
# change if CARGO_BUILD_FLAGS changes.
|
||||||
CARGO_TARGET_SUBDIR="${HOST_SYS}/release"
|
CARGO_TARGET_SUBDIR="${HOST_SYS}/release"
|
||||||
oe_cargo_build () {
|
oe_cargo_build () {
|
||||||
unset RUSTFLAGS
|
export RUSTFLAGS="${RUSTFLAGS}"
|
||||||
bbnote "cargo = $(which cargo)"
|
bbnote "cargo = $(which cargo)"
|
||||||
bbnote "rustc = $(which rustc)"
|
bbnote "rustc = $(which rustc)"
|
||||||
bbnote "${CARGO} build ${CARGO_BUILD_FLAGS} $@"
|
bbnote "${CARGO} build ${CARGO_BUILD_FLAGS} $@"
|
||||||
@@ -89,14 +69,14 @@ oe_cargo_build () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
oe_cargo_fix_env () {
|
oe_cargo_fix_env () {
|
||||||
export CC="${RUST_CC}"
|
export CC="${RUST_TARGET_CC}"
|
||||||
export CFLAGS="${RUST_CFLAGS}"
|
export CFLAGS="${CFLAGS}"
|
||||||
export AR="${AR}"
|
export AR="${AR}"
|
||||||
export TARGET_CC="${RUST_CC}"
|
export TARGET_CC="${RUST_TARGET_CC}"
|
||||||
export TARGET_CFLAGS="${RUST_CFLAGS}"
|
export TARGET_CFLAGS="${CFLAGS}"
|
||||||
export TARGET_AR="${AR}"
|
export TARGET_AR="${AR}"
|
||||||
export HOST_CC="${RUST_BUILD_CC}"
|
export HOST_CC="${RUST_BUILD_CC}"
|
||||||
export HOST_CFLAGS="${RUST_BUILD_CFLAGS}"
|
export HOST_CFLAGS="${BUILD_CFLAGS}"
|
||||||
export HOST_AR="${BUILD_AR}"
|
export HOST_AR="${BUILD_AR}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,76 @@ def rust_base_triple(d, thing):
|
|||||||
libc = bb.utils.contains('TUNE_FEATURES', 'callconvention-hard', 'hf', '', d)
|
libc = bb.utils.contains('TUNE_FEATURES', 'callconvention-hard', 'hf', '', d)
|
||||||
return arch + vendor + '-' + os + libc
|
return arch + vendor + '-' + os + libc
|
||||||
|
|
||||||
|
# Naming explanation
|
||||||
|
# Yocto
|
||||||
|
# - BUILD_SYS - Yocto triple of the build environment
|
||||||
|
# - HOST_SYS - What we're building for in Yocto
|
||||||
|
# - TARGET_SYS - What we're building for in Yocto
|
||||||
|
#
|
||||||
|
# So when building '-native' packages BUILD_SYS == HOST_SYS == TARGET_SYS
|
||||||
|
# When building packages for the image HOST_SYS == TARGET_SYS
|
||||||
|
# This is a gross over simplification as there are other modes but
|
||||||
|
# currently this is all that's supported.
|
||||||
|
#
|
||||||
|
# Rust
|
||||||
|
# - TARGET - the system where the binary will run
|
||||||
|
# - HOST - the system where the binary is being built
|
||||||
|
#
|
||||||
|
# Rust additionally will use two additional cases:
|
||||||
|
# - undecorated (e.g. CC) - equivalent to TARGET
|
||||||
|
# - triple suffix (e.g. CC_x86_64_unknown_linux_gnu) - both
|
||||||
|
# see: https://github.com/alexcrichton/gcc-rs
|
||||||
|
# The way that Rust's internal triples and Yocto triples are mapped together
|
||||||
|
# its likely best to not use the triple suffix due to potential confusion.
|
||||||
|
|
||||||
RUST_BUILD_SYS = "${@rust_base_triple(d, 'BUILD')}"
|
RUST_BUILD_SYS = "${@rust_base_triple(d, 'BUILD')}"
|
||||||
RUST_HOST_SYS = "${@rust_base_triple(d, 'HOST')}"
|
RUST_HOST_SYS = "${@rust_base_triple(d, 'HOST')}"
|
||||||
RUST_TARGET_SYS = "${@rust_base_triple(d, 'TARGET')}"
|
RUST_TARGET_SYS = "${@rust_base_triple(d, 'TARGET')}"
|
||||||
|
|
||||||
|
# wrappers to get around the fact that Rust needs a single
|
||||||
|
# binary but Yocto's compiler and linker commands have
|
||||||
|
# arguments. Technically the archiver is always one command but
|
||||||
|
# this is necessary for builds that determine the prefix and then
|
||||||
|
# use those commands based on the prefix.
|
||||||
|
WRAPPER_DIR = "${WORKDIR}/wrapper"
|
||||||
|
RUST_BUILD_CC = "${WRAPPER_DIR}/build-rust-cc"
|
||||||
|
RUST_BUILD_CCLD = "${WRAPPER_DIR}/build-rust-ccld"
|
||||||
|
RUST_BUILD_AR = "${WRAPPER_DIR}/build-rust-ar"
|
||||||
|
RUST_TARGET_CC = "${WRAPPER_DIR}/target-rust-cc"
|
||||||
|
RUST_TARGET_CCLD = "${WRAPPER_DIR}/target-rust-ccld"
|
||||||
|
RUST_TARGET_AR = "${WRAPPER_DIR}/target-rust-ar"
|
||||||
|
|
||||||
|
create_wrapper () {
|
||||||
|
file="$1"
|
||||||
|
shift
|
||||||
|
|
||||||
|
cat <<- EOF > "${file}"
|
||||||
|
#!/bin/sh
|
||||||
|
$@ "\$@"
|
||||||
|
EOF
|
||||||
|
chmod +x "${file}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# compiler is used by gcc-rs
|
||||||
|
# linker is used by rustc/cargo
|
||||||
|
# archiver is used by the build of libstd-rs
|
||||||
|
do_rust_create_wrappers () {
|
||||||
|
mkdir -p "${WRAPPER_DIR}"
|
||||||
|
|
||||||
|
# Yocto Build / Rust Host compiler
|
||||||
|
create_wrapper "${RUST_BUILD_CC}" "${BUILD_CC}"
|
||||||
|
# Yocto Build / Rust Host linker
|
||||||
|
create_wrapper "${RUST_BUILD_CCLD}" "${BUILD_CCLD}" "${BUILD_LDFLAGS}"
|
||||||
|
# Yocto Build / Rust Host archiver
|
||||||
|
create_wrapper "${RUST_BUILD_AR}" "${BUILD_AR}"
|
||||||
|
|
||||||
|
# Yocto Target / Rust Target compiler
|
||||||
|
create_wrapper "${RUST_TARGET_CC}" "${CC}"
|
||||||
|
# Yocto Target / Rust Target linker
|
||||||
|
create_wrapper "${RUST_TARGET_CCLD}" "${CCLD}" "${LDFLAGS}"
|
||||||
|
# Yocto Target / Rust Target archiver
|
||||||
|
create_wrapper "${RUST_TARGET_AR}" "${AR}"
|
||||||
|
}
|
||||||
|
|
||||||
|
addtask rust_create_wrappers before do_configure after do_patch
|
||||||
|
do_rust_create_wrappers[dirs] += "${WRAPPER_DIR}"
|
||||||
|
|||||||
@@ -67,10 +67,6 @@ SRC_URI = "\
|
|||||||
|
|
||||||
B = "${S}"
|
B = "${S}"
|
||||||
|
|
||||||
# Can't use the default from rust-vars as it cause a compiler crash
|
|
||||||
# the crate_hash option will cause the compiler to crash
|
|
||||||
RUSTFLAGS = "-C rpath ${RUSTLIB}"
|
|
||||||
|
|
||||||
# Used in libgit2-sys's build.rs, needed for pkg-config to be used
|
# Used in libgit2-sys's build.rs, needed for pkg-config to be used
|
||||||
export LIBGIT2_SYS_USE_PKG_CONFIG = "1"
|
export LIBGIT2_SYS_USE_PKG_CONFIG = "1"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user