canteen's blog

Cross-compiling

Am I just bad?

I have tried cross-compiling approximately a billion times, and I could never get it to work (read: chroot is up, but for some reason I can’t figure out how to use qemu-user-static to get it virtualised).

Everyone says this works, so I’m probably bad. Today I tried compiling antimicrox for an i386 architecture because someone on IRC asked me to.

The journey

I found out there’s two fairly simple tools that help with this:

When I defined a proper schroot config:

[jammy_i386]
description=Ubuntu 22.04 jammy for i386
directory=/home/user/.schroot/jammy_i386
#personality=linux32
type=directory
users=user
root-users=user

I could create the dir, tell debootstrap to

sudo debootstrap --variant=buildd \
 --arch=i386 --foreign \
 --include=fakeroot,build-essential \
 jammy ~/.schroot/jammy_i386 \
 http://archive.ubuntu.com/ubuntu

to create the chroot. I then copied in the qemu binary I needed:

 sudo cp /usr/bin/qemu-i386-static ~/.schroot/jammy_i386/usr/bin/

and I could chroot into the dir and run the second stage

chroot ~/.schroot/jammy_i386
./debootstrap/debootstrap --second-stage

Ok, that was easy

It was a lot easier than expected. After running the second stage I could basically start compiling:

apt install extra-cmake-modules libsdl2-dev \
 libxi-dev libxtst-dev libx11-dev itstool \
 qttools5-dev qttools5-dev-tools

Or so I thought. Turns out I had to add a bunch of sources to my sources.list or it wouldn’t work at all. Genuinely, I have no idea which ones were the ones I needed. I suspect it was one of these:

deb http://archive.ubuntu.com/ubuntu/ jammy universe

deb-src http://archive.ubuntu.com/ubuntu/ jammy universe

deb http://archive.ubuntu.com/ubuntu/ jammy-updates universe

deb-src http://archive.ubuntu.com/ubuntu/ jammy-updates universe

deb http://archive.ubuntu.com/ubuntu/ jammy-backports main restricted universe multiverse

deb-src http://archive.ubuntu.com/ubuntu/ jammy-backports main restricted universe multiverse

After that I could re-run the install command and follow the build instructions in the antimicrox repository. This resulted in a binary that I could run (after setting DISPLAY in my qemu env), which I wanted.

Did it work?

I forwarded it to the person that wanted it! Here’s to hoping it worked for them.

#code #compute