Skip to content

Commit

Permalink
add linux cross build scripts -> libc (gnu/musl)
Browse files Browse the repository at this point in the history
  • Loading branch information
valord577 committed Sep 6, 2024
1 parent ec98753 commit 5007714
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 18 deletions.
18 changes: 14 additions & 4 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@ prefix="${triplet_values[0]}_${triplet_values[1]}_"
TARGET_ARCH="${triplet#${prefix}}"
if [[ "${triplet_values[0]}" =~ ^cross.*$ ]]; then
export CROSS_BUILD_ENABLED="1"

TARGET_LIBC="${triplet_values[2]}"
prefix="${triplet_values[0]}_${triplet_values[1]}_${triplet_values[2]}_"
TARGET_ARCH="${triplet#${prefix}}"
fi

case ${TARGET_PLATFORM} in
"linux")
if [ "${CROSS_BUILD_ENABLED}" == "1" ]; then
source "${PROJ_ROOT}/env-linux-cross.sh" ${TARGET_ARCH}
source "${PROJ_ROOT}/env-linux-cross.sh" ${TARGET_ARCH} ${TARGET_LIBC}
else
source "${PROJ_ROOT}/env-linux.sh"
fi
Expand All @@ -45,9 +49,15 @@ function compile() {
export PKG_TYPE="${2}"
export PKG_PLATFORM="${3}"
export PKG_ARCH="${4}"
export PKG_LIBC="${5}"

export PKG_ARCH_LIBC="${PKG_ARCH}"
if [ -n "${PKG_LIBC}" ]; then
export PKG_ARCH_LIBC="${PKG_ARCH}-${PKG_LIBC}"
fi

export PKG_BULD_DIR="${PROJ_ROOT}/tmp/${PKG_NAME}/${PKG_PLATFORM}/${PKG_ARCH}"
export PKG_INST_DIR="${PROJ_ROOT}/out/${PKG_NAME}/${PKG_PLATFORM}/${PKG_ARCH}"
export PKG_BULD_DIR="${PROJ_ROOT}/tmp/${PKG_NAME}/${PKG_PLATFORM}/${PKG_ARCH_LIBC}"
export PKG_INST_DIR="${PROJ_ROOT}/out/${PKG_NAME}/${PKG_PLATFORM}/${PKG_ARCH_LIBC}"
if [ "${GITHUB_ACTIONS}" == "true" ]; then
if [ -n "${BULD_DIR}" ]; then { export PKG_BULD_DIR="${BULD_DIR}"; } fi
if [ -n "${INST_DIR}" ]; then { export PKG_INST_DIR="${INST_DIR}"; } fi
Expand Down Expand Up @@ -77,5 +87,5 @@ if [ "${GITHUB_ACTIONS}" != "true" ]; then
printf "\e[1m\e[31m%s\e[0m\n" "Please declare the module to be compiled."
exit 1
fi
compile ${1} ${2:-"static"} ${TARGET_PLATFORM} ${TARGET_ARCH}
compile ${1} ${2:-"static"} ${TARGET_PLATFORM} ${TARGET_ARCH} ${TARGET_LIBC}
fi
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions crossbuild_linux_musl_amd64.sh
1 change: 1 addition & 0 deletions crossbuild_linux_musl_arm64.sh
7 changes: 4 additions & 3 deletions env-linux-cross.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,23 @@
set -e

TARGET_ARCH=${1}
TARGET_LIBC=${2}

case ${TARGET_ARCH} in
"arm64")
__TARGET_ARCH__="aarch64"
__TARGET_TRIPLE__="aarch64-unknown-linux-gnu"
__TARGET_TRIPLE__="aarch64-unknown-linux-${TARGET_LIBC}"
;;
"amd64")
__TARGET_ARCH__="x86_64"
__TARGET_TRIPLE__="x86_64-pc-linux-gnu"
__TARGET_TRIPLE__="x86_64-pc-linux-${TARGET_LIBC}"
;;
*)
printf "\e[1m\e[31m%s\e[0m\n" "Unsupported TARGET ARCH: '${TARGET_ARCH}'."
exit 1
;;
esac
BUILTIN_CROSS_TOOLCHAIN_FILE="${PROJ_ROOT}/cross/toolchain-cmake-template.${TARGET_ARCH}"
BUILTIN_CROSS_TOOLCHAIN_FILE="${PROJ_ROOT}/cross/toolchain-cmake-template.${__TARGET_TRIPLE__}"
cat ${PROJ_ROOT}/cross/toolchain-cmake-template \
| sed "s@__TARGET_ARCH__@${__TARGET_ARCH__}@g" \
| sed "s@__TARGET_TRIPLE__@${__TARGET_TRIPLE__}@g" \
Expand Down
20 changes: 9 additions & 11 deletions pkg-conf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,20 @@ function dl_pkgc() {
pushd -- "${PKG_DEPS_PATH}"
{
if [ "${GITHUB_ACTIONS}" == "true" ]; then
{
dl_filename="${pkg_name}_${PKG_PLATFORM}_${PKG_ARCH}_${pkg_version}_${pkg_type}.zip"
if [ -n "${pkg_extra}" ]; then
dl_filename="${pkg_name}_${PKG_PLATFORM}_${PKG_ARCH}_${pkg_version}_${pkg_type}_${pkg_extra}.zip"
fi
printf "\e[1m\e[36m%s\e[0m\n" "dl_filename='${dl_filename}'"
(
dl_filename="${pkg_name}_${PKG_PLATFORM}_${PKG_ARCH_LIBC}_${pkg_version}_${pkg_type}"
if [ -n "${pkg_extra}" ]; then { dl_filename="${dl_filename}_${pkg_extra}"; } fi
printf "\e[1m\e[36m%s\e[0m\n" "dl_filename='${dl_filename}.zip'"

${PROJ_ROOT}/.github/oss_v4.py pull "${pkg_name}/${pkg_version}/${dl_filename}" "${pkg_name}.zip"
${PROJ_ROOT}/.github/oss_v4.py pull "${pkg_name}/${pkg_version}/${dl_filename}.zip" "${pkg_name}.zip"
unzip -q "${pkg_name}.zip"
}
)
else
{
(
set -x
ln -sfn ../out/${pkg_name}/${PKG_PLATFORM}/${PKG_ARCH} ${pkg_name}
ln -sfn ../out/${pkg_name}/${PKG_PLATFORM}/${PKG_ARCH_LIBC} ${pkg_name}
set +x
}
)
fi
}
popd
Expand Down

0 comments on commit 5007714

Please sign in to comment.