From d022bc8c3ab51c35d9014c3d669d241c46ead13f Mon Sep 17 00:00:00 2001 From: Matthias Reichl Date: Thu, 1 Dec 2022 14:28:04 +0100 Subject: [PATCH 1/7] config/functions: add local-cc flag for building with local build-host cc This is needed for host packages built in very early stages, before host-cc (which typically uses ccache) is available. Set CC/CXX to LOCAL_CC/CXX in this case. Signed-off-by: Matthias Reichl --- config/functions | 9 +++++++-- packages/readme.md | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/config/functions b/config/functions index 9ddf319095..cc287404eb 100644 --- a/config/functions +++ b/config/functions @@ -492,8 +492,13 @@ setup_toolchain() { host:*|bootstrap:*) export DESTIMAGE="host" export AWK="gawk" - export CC="$TOOLCHAIN/bin/host-gcc" - export CXX="$TOOLCHAIN/bin/host-g++" + if [ "$1" = "host" ] && flag_enabled "local-cc" "no"; then + export CC="${LOCAL_CC}" + export CXX="${LOCAL_CXX}" + else + export CC="$TOOLCHAIN/bin/host-gcc" + export CXX="$TOOLCHAIN/bin/host-g++" + fi export CPP="cpp" export LD="ld" export AS="as" diff --git a/packages/readme.md b/packages/readme.md index 7c4f4984bc..45318ca522 100644 --- a/packages/readme.md +++ b/packages/readme.md @@ -132,6 +132,7 @@ Set the variable `PKG_BUILD_FLAGS` in the `package.mk` to enable/disable the sin | parallel | enabled | all | `make` or `ninja` builds with multiple threads/processes (or not) | | strip | enabled | target | strips executables (or not) | | sysroot | enabled | target | installs the package to the sysroot folder (or not) | +| local-cc | disabled | host | use compiler from buildhost instead of host-gcc/g++ in toolchain | ###### Example ``` From 8eb0080e8c44ea390c36877f0e571680bbdd8318 Mon Sep 17 00:00:00 2001 From: Matthias Reichl Date: Thu, 1 Dec 2022 14:30:40 +0100 Subject: [PATCH 2/7] make: use local-cc flag instead of manually setting CC Signed-off-by: Matthias Reichl --- packages/devel/make/package.mk | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/devel/make/package.mk b/packages/devel/make/package.mk index 18cee105fc..2c1732f621 100644 --- a/packages/devel/make/package.mk +++ b/packages/devel/make/package.mk @@ -10,10 +10,7 @@ PKG_SITE="https://www.gnu.org/software/make/" PKG_URL="http://ftpmirror.gnu.org/make/${PKG_NAME}-${PKG_VERSION}.tar.gz" PKG_DEPENDS_HOST="" PKG_LONGDESC="Utility to maintain groups of programs." - -pre_configure_host() { - export CC=${LOCAL_CC} -} +PKG_BUILD_FLAGS="+local-cc" post_makeinstall_host() { ln -sf make ${TOOLCHAIN}/bin/gmake From 88b3ca8f7ef2bed6701b411a07ccc036c0836dc5 Mon Sep 17 00:00:00 2001 From: Matthias Reichl Date: Thu, 1 Dec 2022 14:31:27 +0100 Subject: [PATCH 3/7] ccache: use local-cc flag instead of manually setting CC Signed-off-by: Matthias Reichl --- packages/devel/ccache/package.mk | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/packages/devel/ccache/package.mk b/packages/devel/ccache/package.mk index 7ed5c185ec..e9a5b32282 100644 --- a/packages/devel/ccache/package.mk +++ b/packages/devel/ccache/package.mk @@ -10,14 +10,10 @@ PKG_SITE="https://ccache.dev/download.html" PKG_URL="https://github.com/ccache/ccache/releases/download/v${PKG_VERSION}/${PKG_NAME}-${PKG_VERSION}.tar.xz" PKG_DEPENDS_HOST="make:host" PKG_LONGDESC="A compiler cache to speed up re-compilation of C/C++ code by caching." +PKG_BUILD_FLAGS="+local-cc" PKG_CONFIGURE_OPTS_HOST="--with-bundled-zlib" -pre_configure_host() { - export CC=${LOCAL_CC} - export CXX=${LOCAL_CXX} -} - post_makeinstall_host() { # setup ccache if [ -z "${CCACHE_DISABLE}" ]; then @@ -26,14 +22,14 @@ post_makeinstall_host() { cat > ${TOOLCHAIN}/bin/host-gcc < ${TOOLCHAIN}/bin/host-g++ < Date: Thu, 1 Dec 2022 15:12:04 +0100 Subject: [PATCH 4/7] config/path: add support for build-host local ccache directory settings Signed-off-by: Matthias Reichl --- config/path | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/config/path b/config/path index 2b0be6cead..28a5bbf88c 100644 --- a/config/path +++ b/config/path @@ -70,6 +70,14 @@ if [ -z "$CCACHE_DIR" ]; then export CCACHE_DIR=$BUILD/.ccache fi +# keep a copy of ccache dir used for toolchain ccache +export BUILD_CCACHE_DIR="${CCACHE_DIR}" + +# local ccache dir in case we build early packages with local ccache +if [ -z "${LOCAL_CCACHE_DIR}" ]; then + export LOCAL_CCACHE_DIR="${BUILD}/.ccache-local" +fi + if [[ -z "$PATH" || ( "$PATH" != "$TOOLCHAIN/bin:$TOOLCHAIN/sbin" && "$PATH" = "${PATH#$TOOLCHAIN/bin:$TOOLCHAIN/sbin:}" ) ]]; then export PATH="$TOOLCHAIN/bin:$TOOLCHAIN/sbin${PATH:+":$PATH"}" fi From eea2b116d57bf326d7d0e5cf89f4fb6fe4bafe6a Mon Sep 17 00:00:00 2001 From: Matthias Reichl Date: Thu, 1 Dec 2022 15:12:56 +0100 Subject: [PATCH 5/7] ccache: explicitly set CCACHE_DIR to the dir we want to use Signed-off-by: Matthias Reichl --- packages/devel/ccache/package.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/devel/ccache/package.mk b/packages/devel/ccache/package.mk index e9a5b32282..aedeed3b1f 100644 --- a/packages/devel/ccache/package.mk +++ b/packages/devel/ccache/package.mk @@ -17,7 +17,7 @@ PKG_CONFIGURE_OPTS_HOST="--with-bundled-zlib" post_makeinstall_host() { # setup ccache if [ -z "${CCACHE_DISABLE}" ]; then - ${TOOLCHAIN}/bin/ccache --max-size=${CCACHE_CACHE_SIZE} + CCACHE_DIR="${BUILD_CCACHE_DIR}" ${TOOLCHAIN}/bin/ccache --max-size=${CCACHE_CACHE_SIZE} fi cat > ${TOOLCHAIN}/bin/host-gcc < Date: Thu, 1 Dec 2022 15:13:57 +0100 Subject: [PATCH 6/7] config/functions: support using local ccache for early builds If LOCAL_CCACHE is set to the full path of ccache on the build host it will be used for early stage host package builds, eg make and ccache at the moment. By default it uses a separate cache dir (.ccache-local) so that it doesn't interfere with our ccache (which is typically a different version). The location can be changed by setting LOCAL_CCACHE_DIR Signed-off-by: Matthias Reichl --- config/functions | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/config/functions b/config/functions index cc287404eb..a03dbb490b 100644 --- a/config/functions +++ b/config/functions @@ -495,6 +495,11 @@ setup_toolchain() { if [ "$1" = "host" ] && flag_enabled "local-cc" "no"; then export CC="${LOCAL_CC}" export CXX="${LOCAL_CXX}" + if [ -n "${LOCAL_CCACHE}" ]; then + export CCACHE_DIR="${LOCAL_CCACHE_DIR}" + export CC="${LOCAL_CCACHE} ${CC}"; + export CXX="${LOCAL_CCACHE} ${CXX}"; + fi else export CC="$TOOLCHAIN/bin/host-gcc" export CXX="$TOOLCHAIN/bin/host-g++" From 8022ec23bfe16a88c60bda780e7e64b7a54b3e35 Mon Sep 17 00:00:00 2001 From: Matthias Reichl Date: Thu, 1 Dec 2022 20:07:12 +0100 Subject: [PATCH 7/7] scripts/build: use wrapper scripts when building with local-cc flag Several packages and buildsystems (most notably cmake) badly trip over CC="ccache gcc" so create local wrapper scripts in the build dir and set CC/CXX to them to work around that - like we do for host-gcc and gcc in toolchain. Signed-off-by: Matthias Reichl fixup scripts/build local-cc wrapper --- scripts/build | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/scripts/build b/scripts/build index 23243a6aca..7c961ee548 100755 --- a/scripts/build +++ b/scripts/build @@ -238,6 +238,23 @@ if [ -f "${PKG_CONFIGURE_SCRIPT}" -o -f "${PKG_CMAKE_SCRIPT}" -o -f "${PKG_MESON MESON_CONF="${PKG_REAL_BUILD}/meson.conf" fi +# create wrapper scripts in build dir and use them for CC/CXX when +# building for host and local-cc build flag is set +if [ "${TARGET}" = "host" ] && flag_enabled "local-cc" "no"; then + cat > libreelec-local-cc << EOF +#!/bin/sh +exec ${CC} "\$@" +EOF + chmod +x libreelec-local-cc + export CC=$(pwd)/libreelec-local-cc + cat > libreelec-local-cxx << EOF +#!/bin/sh +exec ${CXX} "\$@" +EOF + chmod +x libreelec-local-cxx + export CXX=$(pwd)/libreelec-local-cxx +fi + # configure if [ -n "${PKG_DEPENDS_CONFIG}" -a -n "${PKG_INSTALL}" ]; then for pkg in ${PKG_DEPENDS_CONFIG}; do