Advanced Build

Advanced Cross Compilation

For cross-compilation, the default behavior is to install all dependencies (BuildRequires) both in the native root and in the target sysroot.

However, some applications may only be available for a single architecture. For this purpose, two macros are available: %TargetBuildRequires and %NativeBuildRequires.

As their names suggest:

  • %TargetBuildRequires installs the dependency only in the target sysroot
  • %NativeBuildRequires installs the dependency only in the native root

A dependency can therefore be changed as follows:

- BuildRequires: foo
+ %TargetBuildRequires foo

Example with libfoo and bar

Let’s consider two applications that are intended to be built for the aarch64 architecture.

  • libfoo provides a shared library: libfoo.so and its headers are in libfoo-devel package
  • bar is an application that depends on libfoo

In the bar spec file, there is a build dependency on the development package:

BuildRequires: libfoo-devel

First case: cross build for both native and target architectures

If the native architecture is enabled, the libfoo package will be built for both native and target architectures. When building bar, the dependency will be installed automatically in both the native root and the target sysroot.

Second case: only the aarch64 architecture is enabled

In this case, there is no native libfoo RPM available. As a result, the build will fail when installing native packages, with an error similar to:

no libfoo-devel available

To fix this issue, replace the BuildRequires directive with:

- BuildRequires: libfoo-devel
+ %TargetBuildRequires libfoo-devel

Third case: switching the build mode

In this case, the spec file does not need to be modified. Instead, you can use a different build mode, such as an emulated build. This mode installs only target architecture packages, avoiding any error during dependency installation.

Advanced Accel

Accel compilation used a qemu static patched, for using it in localbuilder see accel.