Cross-compiling cpython for raspberry pi

I’m working on setting up GTSAM using Python on the Raspberry Pi, and as part of that, I’m trying to set up a nightly CI build on Github.

I have it mostly working using qemu, but it’s really slow, so i thought that Docker might work better, and I noticed that WPILib has some arm64 cross-compiling Docker images. I’ve seen @Thad_House and @virtuald in there.

Is there some sort of recipe for setting up something similar? I don’t actually want to use the WPILib image, I need to make a vanilla bookworm one, and use it in my GTSAM build, I think similarly to how robotpy’s dist.yml job works.

Any tips before I try to figure it out?

The wpilib ones are a cross compiler built from the same sources and settings raspberry pi actually use. They’re going to be the closest you’ll get to the fully correct compilers. Raspberry themselves don’t provide cross compilers.

Best of luck! I had to fork gtsam and include cassert a bunch of places, and also make sure my Eigen version matched wpilib

Yeah, thanks. I’m discovering a lot about cmake and python build tooling. There is a whole lot of unintentional complexity there, man. On the plus side, the gtsam folk themselves are super nice.

Once you have a working cross-compiler, I’ve found that crossenv is the most reliable mechanism to cross-compile python code – which the wpilib docker images do, and you should be able to copy/paste most of it without too much modification. I think people who care about this problem really want crossenv to go away and not be necessary, but realistically I think that’s still years away for most projects.

Once you have a working docker image and crossenv environment, I’d recommend looking at roborio-wheels/.github/workflows/wheels.yml at 2025 · robotpy/roborio-wheels · GitHub instead, it’s a lot simpler and only does the cross-compilation step, and builds wheels using standard python tooling (well… using pip but you probably could switch it for build too).

1 Like