Skip to content

Commit

Permalink
update linux cross build
Browse files Browse the repository at this point in the history
  • Loading branch information
valord577 committed Oct 15, 2024
1 parent ea8fc1b commit ff6dbe9
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 137 deletions.
8 changes: 4 additions & 4 deletions .github/matrix_container.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,27 @@
"arch": "amd64",
"pkg_type": "static",
"lib_impl": "gnu",
"image": "valord577/linux310-cross:578bca67789f3845680ae9e192e26c85affa3292"
"image": "valord577/linux-cross:6a5d9b8db8c21b39d1655aa536d7566f5512e967"
},
{
"platform": "linux",
"arch": "arm64",
"pkg_type": "static",
"lib_impl": "gnu",
"image": "valord577/linux310-cross:578bca67789f3845680ae9e192e26c85affa3292"
"image": "valord577/linux-cross:6a5d9b8db8c21b39d1655aa536d7566f5512e967"
},
{
"platform": "linux",
"arch": "amd64",
"pkg_type": "static",
"lib_impl": "musl",
"image": "valord577/linux310-cross:578bca67789f3845680ae9e192e26c85affa3292"
"image": "valord577/linux-cross:6a5d9b8db8c21b39d1655aa536d7566f5512e967"
},
{
"platform": "linux",
"arch": "arm64",
"pkg_type": "static",
"lib_impl": "musl",
"image": "valord577/linux310-cross:578bca67789f3845680ae9e192e26c85affa3292"
"image": "valord577/linux-cross:6a5d9b8db8c21b39d1655aa536d7566f5512e967"
}
]
2 changes: 0 additions & 2 deletions cross/linux/.gitignore

This file was deleted.

19 changes: 0 additions & 19 deletions cross/linux/pkgconf-wrapper

This file was deleted.

22 changes: 0 additions & 22 deletions cross/linux/toolchain-cmake-template

This file was deleted.

2 changes: 0 additions & 2 deletions cross/mingw/.gitignore

This file was deleted.

15 changes: 0 additions & 15 deletions cross/mingw/pkgconf-wrapper

This file was deleted.

19 changes: 0 additions & 19 deletions cross/mingw/toolchain-cmake-template

This file was deleted.

76 changes: 40 additions & 36 deletions env-linux-cross.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,57 +4,61 @@ set -e
TARGET_ARCH=${1}
TARGET_LIBC=${2}

export PARALLEL_JOBS="$(nproc)"

if command -v ccache >/dev/null 2>&1 ; then
export CCACHE_SRC="$(command -v ccache)"

export CMAKE_EXTRA="${CMAKE_EXTRA} -D CMAKE_C_COMPILER_LAUNCHER=ccache"
export CMAKE_EXTRA="${CMAKE_EXTRA} -D CMAKE_CXX_COMPILER_LAUNCHER=ccache"
fi

case ${TARGET_ARCH} in
"amd64")
export TARGET_TRIPLE="x86_64-pc-linux-${TARGET_LIBC}"
;;
"arm64")
__TARGET_ARCH__="aarch64"
__TARGET_TRIPLE__="aarch64-unknown-linux-${TARGET_LIBC}"
export TARGET_TRIPLE="aarch64-unknown-linux-${TARGET_LIBC}"
;;
"amd64")
__TARGET_ARCH__="x86_64"
__TARGET_TRIPLE__="x86_64-pc-linux-${TARGET_LIBC}"
"armv7")
export TARGET_TRIPLE="arm-unknown-linux-${TARGET_LIBC}"
;;
*)
printf "\e[1m\e[31m%s\e[0m\n" "Unsupported TARGET ARCH: '${TARGET_ARCH}'."
exit 1
;;
esac
BUILTIN_CROSS_TOOLCHAIN_FILE_CMAKE="${PROJ_ROOT}/cross/linux/toolchain-cmake-template.${__TARGET_TRIPLE__}"
cat ${PROJ_ROOT}/cross/linux/toolchain-cmake-template \
| sed "s@__TARGET_ARCH__@${__TARGET_ARCH__}@g" \
| sed "s@__TARGET_TRIPLE__@${__TARGET_TRIPLE__}@g" \
> ${BUILTIN_CROSS_TOOLCHAIN_FILE_CMAKE}
if [ -n "${CROSS_TOOLCHAIN_FILE_PREFIX_CMAKE}" ]; then
CROSS_TOOLCHAIN_FILE_CMAKE="${CROSS_TOOLCHAIN_FILE_PREFIX_CMAKE}.${__TARGET_TRIPLE__}"
else
CROSS_TOOLCHAIN_FILE_CMAKE="${BUILTIN_CROSS_TOOLCHAIN_FILE_CMAKE}"
fi

pushd ${PROJ_ROOT}/cross/linux; { ln -sfn "pkgconf-wrapper" "pkgconf-wrapper.${__TARGET_TRIPLE__}"; }; popd
BUILTIN_CROSS_TOOLCHAIN_PKGCONF="${PROJ_ROOT}/cross/linux/pkgconf-wrapper.${__TARGET_TRIPLE__}"
if [ -n "${CROSS_TOOLCHAIN_PKGCONF_PREFIX}" ]; then
export CROSS_TOOLCHAIN_PKGCONF="${CROSS_TOOLCHAIN_PKGCONF_PREFIX}.${__TARGET_TRIPLE__}"
else
export CROSS_TOOLCHAIN_PKGCONF="${BUILTIN_CROSS_TOOLCHAIN_PKGCONF}"
fi

CROSS_TOOLCHAIN_ROOT=${CROSS_TOOLCHAIN_ROOT:-""}
if [ -z "${CROSS_TOOLCHAIN_ROOT}" ]; then
printf "\e[1m\e[31m%s\e[0m\n" "Blank CROSS_TOOLCHAIN_ROOT: '${CROSS_TOOLCHAIN_ROOT}'."
exit 1
fi
export SYSROOT="${CROSS_TOOLCHAIN_ROOT}/${__TARGET_TRIPLE__}/sysroot"
export SYSROOT="${CROSS_TOOLCHAIN_ROOT}/${TARGET_TRIPLE}/sysroot"

export PARALLEL_JOBS="$(nproc)"
export CMAKE_EXTRA_ARGS="${CMAKE_EXTRA_ARGS} -D CMAKE_TOOLCHAIN_FILE=${CROSS_TOOLCHAIN_FILE_CMAKE}"
# cmake toolchain file
if [ -z "${CROSS_TOOLCHAIN_FILE_PREFIX_CMAKE}" ]; then
CROSS_TOOLCHAIN_FILE_PREFIX_CMAKE="${CROSS_TOOLCHAIN_ROOT}/toolchain-cmake-template"
fi
CROSS_TOOLCHAIN_FILE_CMAKE="${CROSS_TOOLCHAIN_FILE_PREFIX_CMAKE}.${TARGET_TRIPLE}"
export CMAKE_EXTRA="${CMAKE_EXTRA} -D CMAKE_TOOLCHAIN_FILE=${CROSS_TOOLCHAIN_FILE_CMAKE}"
# pkgconf bin
if [ -z "${CROSS_TOOLCHAIN_PKGCONF_PREFIX}" ]; then
CROSS_TOOLCHAIN_PKGCONF_PREFIX="${CROSS_TOOLCHAIN_ROOT}/pkgconf-wrapper"
fi
export CROSS_TOOLCHAIN_PKGCONF="${CROSS_TOOLCHAIN_PKGCONF_PREFIX}.${TARGET_TRIPLE}"

# for cross-compiling, cmake sets compiler vars by toolchain file, so keep CC/CXX.
export CROSS_FLAGS="--target=${__TARGET_TRIPLE__} --gcc-toolchain=${CROSS_TOOLCHAIN_ROOT}"
export CC="/usr/bin/clang ${CROSS_FLAGS}"; export CXX="/usr/bin/clang++ ${CROSS_FLAGS}"; export HOSTCC="/usr/bin/clang"
export LD="/usr/bin/ld.lld"; export NM="/usr/bin/llvm-nm"; export AR="/usr/bin/llvm-ar"; export AS="/usr/bin/llvm-as";
export RANLIB="/usr/bin/llvm-ranlib"; export STRIP="/usr/bin/llvm-strip";
if command -v ccache >/dev/null 2>&1 ; then
export CCACHE_SRC="$(command -v ccache)"
# for cross-compiling, cmake sets compiler vars by toolchain file, so keep CC/CXX here.
export HOSTCC="$(command -v clang)"
export HOSTCXX="$(command -v clang++)"
export LD="$(command -v ld.lld)";
export NM="$(command -v llvm-nm)";
export AR="$(command -v llvm-ar)";
export AS="$(command -v llvm-as)";
export RANLIB="$(command -v llvm-ranlib)";
export STRIP="$(command -v llvm-strip)";

export CMAKE_EXTRA_ARGS="${CMAKE_EXTRA_ARGS} -D CMAKE_C_COMPILER_LAUNCHER=ccache"
export CMAKE_EXTRA_ARGS="${CMAKE_EXTRA_ARGS} -D CMAKE_CXX_COMPILER_LAUNCHER=ccache"
fi
export CROSS_FLAGS="--target=${TARGET_TRIPLE} --gcc-toolchain=${CROSS_TOOLCHAIN_ROOT} -Wno-unused-command-line-argument -fuse-ld=${LD} --sysroot=${SYSROOT}"
export CC="$(command -v clang) ${CROSS_FLAGS}";
export CXX="$(command -v clang++) ${CROSS_FLAGS}";
export CPP="$(command -v clang-cpp) ${CROSS_FLAGS}";
11 changes: 1 addition & 10 deletions pkg-conf.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
#!/usr/bin/env bash
set -e

export PKG_CONFIG_EXEC="pkg-config"
if command -v pkgconf >/dev/null 2>&1 ; then
export PKG_CONFIG_EXEC="pkgconf"
fi
if [ -n "${CROSS_TOOLCHAIN_PKGCONF}" ]; then
export PKG_CONFIG_EXEC="${CROSS_TOOLCHAIN_PKGCONF}"
fi
Expand All @@ -16,12 +12,7 @@ dep_libs_dir="${PROJ_ROOT}/lib"
if [ ! -e "${dep_libs_dir}" ]; then { mkdir -p "${dep_libs_dir}"; } fi

function dl_pkgc() {
need_update="0"
for pkg_name in ${UPDATE_DL_PKG:-""}; do
if [ "${pkg_name}" == "${1}" ]; then { need_update="1"; break; } fi
done

if [ ! -e "${dep_libs_dir}/${1}" ] || [ "${need_update}" != "0" ]; then
if [ ! -e "${dep_libs_dir}/${1}" ]; then
(
pkg_name="${1}"
pkg_version="${2}"
Expand Down
9 changes: 6 additions & 3 deletions scripts/ffmpeg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ ${SUBPROJ_SRC}/configure \
${PKG_TYPE_FLAG} \
${PKG_BULD_TYPE} \
${PKG_INST_STRIP} \
--pkg-config='${PKG_CONFIG_EXEC}' \
--enable-gpl \
--enable-version3 \
--fatal-warnings \
Expand All @@ -68,6 +67,10 @@ ${SUBPROJ_SRC}/configure \
${PKG_DEPS_ARGS}
EOF
)
if [ -n "${PKG_CONFIG_EXEC}" ]; then
CONFIGURE_COMMAND="${CONFIGURE_COMMAND} --pkg-config='${PKG_CONFIG_EXEC}'"
fi

case ${PKG_PLATFORM} in
"macosx" | "iphoneos" | "iphonesimulator")
CONFIGURE_COMMAND="${CONFIGURE_COMMAND} \
Expand All @@ -78,8 +81,8 @@ case ${PKG_PLATFORM} in
"linux")
if [ "${CROSS_BUILD_ENABLED}" == "1" ]; then
CONFIGURE_COMMAND="${CONFIGURE_COMMAND} \
--enable-cross-compile --sysroot='${SYSROOT}' --target-os=linux --arch=${PKG_ARCH} --host-cc='${HOSTCC}' \
--extra-ldflags='-fuse-ld=${LD}' --nm='${NM}' --ar='${AR}' --ranlib='${RANLIB}' --strip='${STRIP}'"
--enable-cross-compile --target-os=linux --arch=${PKG_ARCH} \
--host-cc='${HOSTCC}' --nm='${NM}' --ar='${AR}' --ranlib='${RANLIB}' --strip='${STRIP}'"
fi
;;
"win-mingw")
Expand Down
16 changes: 11 additions & 5 deletions scripts/mbedtls.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ python3 ${SUBPROJ_SRC}/scripts/config.py set MBEDTLS_HAVE_SSE2
python3 ${SUBPROJ_SRC}/scripts/config.py set MBEDTLS_DEPRECATED_WARNING
python3 ${SUBPROJ_SRC}/scripts/config.py set MBEDTLS_DEPRECATED_REMOVED

python3 ${SUBPROJ_SRC}/scripts/config.py set MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT
python3 ${SUBPROJ_SRC}/scripts/config.py set MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
python3 ${SUBPROJ_SRC}/scripts/config.py set MBEDTLS_PSA_P256M_DRIVER_ENABLED
python3 ${SUBPROJ_SRC}/scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED

Expand All @@ -30,16 +32,20 @@ python3 ${SUBPROJ_SRC}/scripts/config.py unset MBEDTLS_SELF_TEST
python3 ${SUBPROJ_SRC}/scripts/config.py unset MBEDTLS_SSL_SRV_C
python3 ${SUBPROJ_SRC}/scripts/config.py unset MBEDTLS_SSL_RENEGOTIATION


case ${PKG_PLATFORM} in
"win-mingw")
if [ "${PKG_ARCH}" == "x86_64" ]; then
python3 ${SUBPROJ_SRC}/scripts/config.py set MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT
python3 ${SUBPROJ_SRC}/scripts/config.py set MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
if [ "${PKG_ARCH}" == "aarch64" ]; then
python3 ${SUBPROJ_SRC}/scripts/config.py unset MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT
python3 ${SUBPROJ_SRC}/scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
fi
;;
"linux")
if [ "${PKG_ARCH}" == "armv7" ]; then
python3 ${SUBPROJ_SRC}/scripts/config.py unset MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
fi
;;
*)
python3 ${SUBPROJ_SRC}/scripts/config.py set MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT
python3 ${SUBPROJ_SRC}/scripts/config.py set MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
;;
esac
# ----------------------------
Expand Down

0 comments on commit ff6dbe9

Please sign in to comment.