From 578678e0510b6b5f422dc16975a07ad7b15274a4 Mon Sep 17 00:00:00 2001 From: Jakob Naucke Date: Tue, 15 Feb 2022 19:12:41 +0100 Subject: [PATCH] packaging: Enable cross-building agent Requires setting ARCH and CC. - Add CC linker option for building agent. - Set host for building libseccomp. Fixes: #3681 Signed-off-by: Jakob Naucke --- ci/install_libseccomp.sh | 8 +++++--- utils.mk | 11 ++++++++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/ci/install_libseccomp.sh b/ci/install_libseccomp.sh index 8933438860..5cbf8f0798 100755 --- a/ci/install_libseccomp.sh +++ b/ci/install_libseccomp.sh @@ -19,7 +19,7 @@ source "${tests_repo_dir}/.ci/lib.sh" # fail. So let's ensure they are unset here. unset PREFIX DESTDIR -arch=$(uname -m) +arch=${ARCH:-$(uname -m)} workdir="$(mktemp -d --tmpdir build-libseccomp.XXXXX)" # Variables for libseccomp @@ -70,7 +70,9 @@ build_and_install_gperf() { curl -sLO "${gperf_tarball_url}" tar -xf "${gperf_tarball}" pushd "gperf-${gperf_version}" - ./configure --prefix="${gperf_install_dir}" + # gperf is a build time dependency of libseccomp and not to be used in the target. + # Unset $CC since that might point to a cross compiler. + CC= ./configure --prefix="${gperf_install_dir}" make make install export PATH=$PATH:"${gperf_install_dir}"/bin @@ -84,7 +86,7 @@ build_and_install_libseccomp() { curl -sLO "${libseccomp_tarball_url}" tar -xf "${libseccomp_tarball}" pushd "libseccomp-${libseccomp_version}" - ./configure --prefix="${libseccomp_install_dir}" CFLAGS="${cflags}" --enable-static + ./configure --prefix="${libseccomp_install_dir}" CFLAGS="${cflags}" --enable-static --host="${arch}" make make install popd diff --git a/utils.mk b/utils.mk index e833b40d7a..3816fac2a1 100644 --- a/utils.mk +++ b/utils.mk @@ -112,8 +112,9 @@ endef ##VAR BUILD_TYPE=release|debug type of rust build BUILD_TYPE = release +HOST_ARCH = $(shell uname -m) ##VAR ARCH=arch target to build (format: uname -m) -ARCH = $(shell uname -m) +ARCH ?= $(HOST_ARCH) ##VAR LIBC=musl|gnu LIBC ?= musl ifneq ($(LIBC),musl) @@ -142,6 +143,14 @@ ifeq ($(ARCH), aarch64) $(warning "WARNING: aarch64-musl needs extra symbols from libgcc") endif +ifneq ($(HOST_ARCH),$(ARCH)) + ifeq ($(CC),) + CC = gcc + $(warning "WARNING: A foreign ARCH was passed, but no CC alternative. Using $(CC).") + endif + override EXTRA_RUSTFLAGS += -C linker=$(CC) +endif + TRIPLE = $(ARCH)-unknown-linux-$(LIBC) CWD := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))