Most applications that rely on the Meson build system have decent
support for cross compilation, ie. compiling 32-bit binaries on a
64-bit system. It can be as easy as setting the CC
, CXX
, and PKG_CONFIG_PATH
variables before using the
meson setup ..
command to compile 32-bit binaries on a 64-bit system. However,
some projects are more complicated for many different reasons,
leading to the necessity of Meson toolchain files. They specify
compilers, options that should be invoked, the pkg-conf binary (or
rather symlink that uses a certain personality file) to use,
llvm-config to use,
etc. This is required for many Meson projects, especially if you
have followed BLFS before this book. Therefore, this section should
be considered a requirement.
There are two Meson files: the cross toolchain file and the native toolchain file. There are different situations for using either.
Create the cross toolchain file by running the following commands
as the root
user:
mkdir -pv /usr/share/meson/cross &&
cat > /usr/share/meson/cross/lib32 << "EOF"
[binaries]
c = ['gcc', '-m32']
cpp = ['g++', '-m32']
rust = ['rustc', '--target', 'i686-unknown-linux-gnu']
pkg-config = 'i686-pc-linux-gnu-pkg-config'
ar = '/usr/bin/ar'
strip = '/usr/bin/strip'
cups-config = 'cups-config'
llvm-config = 'llvm-config'
exe_wrapper = ''
[properties]
sizeof_void* = 4
sizeof_long = 4
[host_machine]
system = 'linux'
subsystem = 'linux'
kernel = 'linux'
cpu_family = 'x86'
cpu = 'i686'
endian = 'little'
EOF
Create the native toolchain file by running the following commands
as the root
user:
mkdir -pv /usr/share/meson/native &&
cat > /usr/share/meson/native/x86 << "EOF"
[binaries]
c = ['gcc', '-m32']
cpp = ['g++', '-m32']
rust = ['rustc', '--target', 'i686-unknown-linux-gnu']
pkg-config = 'i686-pc-linux-gnu-pkg-config'
ar = '/usr/bin/ar'
strip = '/usr/bin/strip'
cups-config = 'cups-config'
llvm-config = 'llvm-config'
exe_wrapper = ''
[properties]
sizeof_void* = 4
sizeof_long = 4
[host_machine]
system = 'linux'
subsystem = 'linux'
kernel = 'linux'
cpu_family = 'x86'
cpu = 'i686'
endian = 'little'
EOF
Instead of setting environment variables before invoking
meson setup ..
, you
can simply do:
meson setup .. --cross-file=lib32 <other-options>
Or...
meson setup .. --native-file=x86 <other-options>