Skip to content

add cross-building test

IOhannes zmölnig requested to merge umlaeute/salsa-pipeline:crossbuild into master

this PR adds a new test-job that attempts to cross-compile the package for a different architecture.

Closes: #189 (closed)

for the sake of simplicity, in this document i'm using the terms "target architecture" and "host architecture" interchangeably for the architecture of the produced binary packages.

overview

  • the default-set of pipelines comes with a test-crossbuild-arm64 that crossbuilds the package on the default (amd64) image for the arm64 architecture
  • the target architecture can be set via the HOST_ARCH variable
  • cross-building uses the same script-snippets as ordinary building (to keep it DRY)
  • cross building can be disabled via the usual ways and by setting SALSA_CI_DISABLE_CROSSBUILD_ARM64 to 1.
  • for now, the crossbuild test is "allowed to fail" (to be removed LATER)

how it works

cross-compiling is enabled by setting HOST_ARCH to a non-empty architecture string that is different from BUILD_ARCH (if ${HOST_ARCH} = ${BUILD_ARCH} it is (re)set to the empty string, resulting in a native build).

  • if $[HOST_ARCH} is non-empty, the specified architecture is added (dpkg --add-architecture)
  • and the relevant crossbuild-essential package is installed
  • images/scripts/install-build-deps.sh honors the ${HOST_ARCH} and accordingly creates a build-dependency package for the target architecture.
  • if cross-compiling, dpkg-buildpackage is invoked with the nocheck and cross profiles, as well as adding nocheck to the DEB_BUILD_OPTIONS.

noteworthy details

ARCH -> BUILD_ARCH

after a discussion on the debian-cross mailinglist, I decided to rename the existing ARCH variable to BUILD_ARCH, to match the new HOST_ARCH (see dpkg-architecture(1) for a discussion on the various architectures).

BUILD_ARCH is expanded to ARCH by default (see salsa-ci.yml#L30-31, so any projects using the central pipeline definitions that customized ARCH would continue to work. ideally we would get rid of ARCH altogether, but I have no idea how feasible this is.

ccache

the ccache key includes ${HOST_ARCH} to prevent cache mismatches (in addition to the traditional ${BUILD_ARCH}). since ${HOST_ARCH} is empty except for the crossbuilding job, there shouldn't be any side-effects for existing caches.

variable quoting

i also added a bit of quoting to the scripts i modified. this is strictly unrelated to the task at hand, but i think it's good practice nevertheless...

is it tested?

the changes pass the test-pipeline that comes with the project. since the test-pipeline only includes an arch:all package (for which cross-building doesn't make much sense), i've also tested it with one of my packages, that uses a simple dh-based workflow with makefile/gcc).

Discussion

i'm happy to hear your ideas, comments and suggestions. i'm sure i missed a couple of things.

Edited by IOhannes zmölnig

Merge request reports

Loading