krata: rework cross-compilation

This commit is contained in:
Alex Zenla
2024-03-21 21:31:10 +00:00
parent 332a1bba26
commit 0191e5b2c1
27 changed files with 321 additions and 131 deletions

View File

@ -3,11 +3,22 @@ set -e
TOOLS_DIR="$(dirname "${0}")"
RUST_TARGET="$("${TOOLS_DIR}/target.sh")"
CROSS_COMPILE="$("${TOOLS_DIR}/cross-compile.sh")"
if [ "${RUST_LIBC}" = "musl" ] && [ -f "/etc/alpine-release" ]
if [ "${TARGET_LIBC}" = "musl" ] && [ -f "/etc/alpine-release" ]
then
export RUSTFLAGS="-Ctarget-feature=-crt-static"
fi
if [ -z "${CARGO}" ]
then
if [ "${CROSS_COMPILE}" = "1" ] && command -v cross > /dev/null
then
CARGO="cross"
else
CARGO="cargo"
fi
fi
export CARGO_BUILD_TARGET="${RUST_TARGET}"
exec cargo "${@}"
exec "${CARGO}" "${@}"

15
hack/build/cross-compile.sh Executable file
View File

@ -0,0 +1,15 @@
#!/bin/sh
set -e
TOOLS_DIR="$(dirname "${0}")"
RUST_TARGET="$("${TOOLS_DIR}/target.sh")"
TARGET_ARCH="$(echo "${RUST_TARGET}" | awk -F '-' '{print $1}')"
HOST_ARCH="$(uname -m)"
if [ "${HOST_ARCH}" != "${TARGET_ARCH}" ]
then
echo "1"
else
echo "0"
fi

View File

@ -1,29 +1,57 @@
#!/bin/sh
set -e
if [ -z "${RUST_LIBC}" ]
if [ -z "${TARGET_LIBC}" ] || [ "${KRATA_TARGET_IGNORE_LIBC}" = "1" ]
then
RUST_LIBC="gnu"
TARGET_LIBC="gnu"
fi
if [ -z "${TARGET_ARCH}" ]
then
TARGET_ARCH="$(uname -m)"
fi
if [ -z "${RUST_TARGET}" ]
then
HOST_ARCH="$(uname -m)"
if [ "${HOST_ARCH}" = "x86_64" ]
if [ "${TARGET_ARCH}" = "x86_64" ]
then
RUST_TARGET="x86_64-unknown-linux-${RUST_LIBC}"
RUST_TARGET="x86_64-unknown-linux-${TARGET_LIBC}"
fi
if [ "${HOST_ARCH}" = "aarch64" ]
if [ "${TARGET_ARCH}" = "aarch64" ]
then
RUST_TARGET="aarch64-unknown-linux-${RUST_LIBC}"
RUST_TARGET="aarch64-unknown-linux-${TARGET_LIBC}"
fi
fi
if [ -z "${RUST_TARGET}" ]
if [ -z "${C_TARGET}" ]
then
echo "ERROR: Unable to determine RUST_TARGET, your architecture may not be supported by krata." > /dev/stderr
exit 1
if [ "${TARGET_ARCH}" = "x86_64" ]
then
C_TARGET="x86_64-linux-${TARGET_LIBC}"
fi
if [ "${TARGET_ARCH}" = "aarch64" ]
then
C_TARGET="aarch64-linux-${TARGET_LIBC}"
fi
fi
echo "${RUST_TARGET}"
if [ "${KRATA_TARGET_C_MODE}" = "1" ]
then
if [ -z "${C_TARGET}" ]
then
echo "ERROR: Unable to determine C_TARGET, your architecture may not be supported by krata." > /dev/stderr
exit 1
fi
echo "${C_TARGET}"
else
if [ -z "${RUST_TARGET}" ]
then
echo "ERROR: Unable to determine RUST_TARGET, your architecture may not be supported by krata." > /dev/stderr
exit 1
fi
echo "${RUST_TARGET}"
fi