Skip to content

Commit 4118edb

Browse files
committed
Add cross compilation for Python
1 parent 2a8b0a0 commit 4118edb

File tree

7 files changed

+203
-5
lines changed

7 files changed

+203
-5
lines changed

Makefile

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ OPENSDK_UBUNTU?=20.04
44
DOCKER_USER?=wpilib
55

66
.PHONY: usage update push build \
7-
$(patsubst %,build/%, base cross opensdl)
8-
$(patsubst %,push/%, base cross opensdl)
7+
$(patsubst %,build/%, base cross opensdl cross-python)
8+
$(patsubst %,push/%, base cross opensdl cross-python)
99
usage:
1010
@echo "Run make update, make build, and make push"
1111

1212
update:
1313
docker pull docker.io/ubuntu:${UBUNTU}
1414
docker pull docker.io/ubuntu:${OPENSDK_UBUNTU}
1515

16-
build: build/base build/cross build/opensdk
16+
build: build/base build/cross build/cross-python build/opensdk
1717

1818
build/base:
1919
cd ubuntu-base && \
@@ -28,12 +28,18 @@ build/cross: build/base
2828
docker build -t ${DOCKER_USER}/raspbian-cross-ubuntu:bullseye-${UBUNTU} -f Dockerfile.bullseye --build-arg UBUNTU=${UBUNTU} .
2929
cd aarch64-cross-ubuntu && \
3030
docker build -t ${DOCKER_USER}/aarch64-cross-ubuntu:bullseye-${UBUNTU} -f Dockerfile.bullseye --build-arg UBUNTU=${UBUNTU} .
31-
31+
32+
build/cross-python:
33+
cd roborio-cross-ubuntu-minimal && \
34+
docker build -t ${DOCKER_USER}/roborio-cross-ubuntu-minimal:2024-${UBUNTU} -f Dockerfile.2024 --build-arg UBUNTU=${UBUNTU} .
35+
cd roborio-cross-ubuntu-py && \
36+
docker build -t ${DOCKER_USER}/roborio-cross-ubuntu-py:2024-${UBUNTU} -f Dockerfile.2024 --build-arg UBUNTU=${UBUNTU} .
37+
3238
build/opensdk:
3339
cd opensdk/ubuntu && \
3440
docker build -t ${DOCKER_USER}/opensdk-ubuntu:${OPENSDK_UBUNTU} --build-arg OPENSDK_UBUNTU=${OPENSDK_UBUNTU} .
3541

36-
push: $(patsubst %,push/%, base cross opensdk)
42+
push: $(patsubst %,push/%, base cross cross-python opensdk)
3743

3844
push/base:
3945
docker push ${DOCKER_USER}/ubuntu-base:${UBUNTU}
@@ -44,5 +50,9 @@ push/cross: push/base
4450
docker push ${DOCKER_USER}/raspbian-cross-ubuntu:bullseye-${UBUNTU}
4551
docker push ${DOCKER_USER}/aarch64-cross-ubuntu:bullseye-${UBUNTU}
4652

53+
push/cross-python:
54+
docker push ${DOCKER_USER}/roborio-cross-ubuntu-minimal:2024-${UBUNTU}
55+
docker push ${DOCKER_USER}/roborio-cross-ubuntu-py:2024-${UBUNTU}
56+
4757
push/opensdk:
4858
docker push ${DOCKER_USER}/opensdk-ubuntu:${OPENSDK_UBUNTU}

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@ roborio-cross-ubuntu
1515
- Published as wpilib/roborio-cross-ubuntu:frc season-host ubuntu version
1616
(e.g. 2020-18.04)
1717

18+
roborio-cross-ubuntu-minimal
19+
- Based on official ubuntu repo (host)
20+
- Cross-compiler for roboRIO
21+
- Published as wpilib/roborio-cross-ubuntu:frc season-host ubuntu version
22+
(e.g. 2020-18.04)
23+
24+
roborio-cross-ubuntu-py
25+
- Based on wpilib/roborio-cross-ubuntu-minimal
26+
- crossenv based cross-compilation environment for python
27+
- Published as wpilib/roborio-cross-ubuntu-py:frc season-host ubuntu version
28+
(e.g. 2020-18.04)
29+
1830
raspbian-cross-ubuntu
1931
- Based on wpilib/ubuntu-base
2032
- Cross-compiler for Raspbian
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
ARG UBUNTU=22.04
2+
FROM ubuntu:${UBUNTU}
3+
4+
RUN set -xe; \
5+
apt-get update; \
6+
apt-get install -y tzdata; \
7+
apt-get install -y \
8+
ca-certificates \
9+
curl \
10+
git \
11+
make \
12+
unzip \
13+
wget \
14+
zip; \
15+
rm -rf /var/lib/apt/lists/*
16+
17+
RUN curl -SL https://github.com/wpilibsuite/opensdk/releases/download/v2024-1/cortexa9_vfpv3-roborio-academic-2024-x86_64-linux-gnu-Toolchain-12.1.0.tgz | sh -c 'mkdir -p /usr/local && cd /usr/local && tar xzf - --strip-components=2'
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
From 1325a6365032f2c7dea4f823003f46305724a6a6 Mon Sep 17 00:00:00 2001
2+
From: Dustin Spicuzza <[email protected]>
3+
Date: Sat, 1 Jan 2022 22:44:03 -0500
4+
Subject: [PATCH] Use specified $host_cpu when cross compiling for Linux
5+
6+
Previously arm processors were hardcoded to "arm", which doesn't match
7+
the output of uname -m (used for native compilation)
8+
---
9+
configure | 8 +-------
10+
configure.ac | 8 +-------
11+
2 files changed, 2 insertions(+), 14 deletions(-)
12+
13+
diff --git a/configure b/configure
14+
index 2e7e0b7e0a..d91928fb79 100755
15+
--- a/configure
16+
+++ b/configure
17+
@@ -3383,13 +3383,7 @@ $as_echo "\"$MACHDEP\"" >&6; }
18+
if test "$cross_compiling" = yes; then
19+
case "$host" in
20+
*-*-linux*)
21+
- case "$host_cpu" in
22+
- arm*)
23+
- _host_cpu=arm
24+
- ;;
25+
- *)
26+
- _host_cpu=$host_cpu
27+
- esac
28+
+ _host_cpu=$host_cpu
29+
;;
30+
*-*-cygwin*)
31+
_host_cpu=
32+
diff --git a/configure.ac b/configure.ac
33+
index 0c06914147..897c3a00ef 100644
34+
--- a/configure.ac
35+
+++ b/configure.ac
36+
@@ -438,13 +438,7 @@ AC_SUBST(_PYTHON_HOST_PLATFORM)
37+
if test "$cross_compiling" = yes; then
38+
case "$host" in
39+
*-*-linux*)
40+
- case "$host_cpu" in
41+
- arm*)
42+
- _host_cpu=arm
43+
- ;;
44+
- *)
45+
- _host_cpu=$host_cpu
46+
- esac
47+
+ _host_cpu=$host_cpu
48+
;;
49+
*-*-cygwin*)
50+
_host_cpu=
51+
--
52+
2.31.1
53+
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
2+
ARG UBUNTU=22.04
3+
FROM wpilib/roborio-cross-ubuntu-minimal:2024-${UBUNTU} AS pycompile
4+
5+
ENV TARGET_HOST="arm-frc2024-linux-gnueabi"
6+
ENV AC_TARGET_HOST="armv7l-frc2024-linux-gnueabi"
7+
ENV BUILD_HOST="x86_64"
8+
ENV WORKING_DIRECTORY="/build"
9+
ENV INSTALL_DIRECTORY="/build/crosspy"
10+
ENV PYTHON_VERSION="3.12.0"
11+
ENV PYTHON_FTP_VERSION="3.12.0"
12+
ENV PYTHON_EXE="python3.12"
13+
ENV SOURCE_DIRECTORY="Python-$PYTHON_VERSION"
14+
ENV PYTHON_ARCHIVE="Python-$PYTHON_VERSION.tar.xz"
15+
ENV PREFIX="$INSTALL_DIRECTORY"
16+
17+
#
18+
# Python compilation prereqs
19+
#
20+
21+
RUN set -xe; \
22+
apt-get update; \
23+
apt-get install -y build-essential checkinstall g++ libreadline-dev libncursesw5-dev libssl-dev \
24+
libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev liblzma-dev lzma-dev libffi-dev zlib1g-dev; \
25+
# cleanup
26+
rm -rf /var/lib/apt/lists/*
27+
28+
#
29+
# Python cross-compilation
30+
#
31+
32+
COPY 0001-Use-specified-host_cpu-when-cross-compiling-for-Linu.patch /
33+
34+
RUN set -xe; \
35+
mkdir -p "$PREFIX"; \
36+
# Download
37+
cd $WORKING_DIRECTORY; \
38+
wget -c https://www.python.org/ftp/python/$PYTHON_FTP_VERSION/$PYTHON_ARCHIVE; \
39+
rm -rf $SOURCE_DIRECTORY; \
40+
tar -xf $PYTHON_ARCHIVE; \
41+
cd $SOURCE_DIRECTORY; \
42+
# patch arm cpu hardcoding
43+
patch -p1 < /0001-Use-specified-host_cpu-when-cross-compiling-for-Linu.patch; \
44+
# Build python for host
45+
cd $WORKING_DIRECTORY;cd $SOURCE_DIRECTORY; \
46+
./configure --enable-optimizations --with-ensurepip=install; \
47+
make -j; \
48+
make -j altinstall
49+
50+
RUN set -xe; \
51+
# Remove build dependencies -- compilation uses host for some reason
52+
apt-get remove -y libreadline-dev libncursesw5-dev libssl-dev \
53+
libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev liblzma-dev lzma-dev libffi-dev zlib1g-dev; \
54+
apt-get autoremove -y;
55+
56+
RUN set -xe; \
57+
# cross-compile for frc
58+
cd $WORKING_DIRECTORY;cd $SOURCE_DIRECTORY; make distclean; \
59+
./configure --host=$TARGET_HOST --build=$BUILD_HOST --prefix=$PREFIX \
60+
--with-build-python=$(which $PYTHON_EXE) \
61+
--disable-ipv6 \
62+
ac_cv_host=$AC_TARGET_HOST \
63+
ac_cv_buggy_getaddrinfo=no \
64+
ac_cv_file__dev_ptmx=no ac_cv_file__dev_ptc=no \
65+
ac_cv_have_long_long_format=yes \
66+
ac_cv_pthread_is_default=no ac_cv_pthread=yes ac_cv_cxx_thread=yes; \
67+
make -j; \
68+
# make install here is fine because we include --prefix in the configure statement
69+
make install
70+
71+
72+
#
73+
# Minimal cross-compilation environment
74+
#
75+
76+
FROM wpilib/roborio-cross-ubuntu-minimal:2024-${UBUNTU} AS crossenv
77+
78+
RUN set -xe; \
79+
apt-get update; \
80+
apt-get install -y \
81+
binutils libreadline8 libncursesw5 libssl3 \
82+
libsqlite3-0 libgdbm6 libbz2-1.0 liblzma5 libffi7 zlib1g; \
83+
rm -rf /var/lib/apt/lists/*
84+
85+
COPY --from=pycompile /usr/local /usr/local
86+
COPY --from=pycompile /build/crosspy /build/crosspy
87+
88+
RUN set -xe; \
89+
ldconfig; \
90+
python3.12 -m pip install 'crossenv~=1.4.0'; \
91+
python3.12 -m crossenv /build/crosspy/bin/python3.12 /build/venv --sysroot=$(arm-frc2024-linux-gnueabi-gcc -print-sysroot) --env UNIXCONFDIR=/build/venv/cross/etc; \
92+
/build/venv/bin/cross-pip install wheel;
93+
94+
COPY pip.conf /build/venv/cross/pip.conf
95+
COPY os-release /build/venv/cross/etc/os-release
96+
97+
ENV RPYBUILD_PARALLEL=1
98+

roborio-cross-ubuntu-py/os-release

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
ID="nilrt-academic"
2+
NAME="NI Linux Real-Time - Academic"
3+
VERSION="8.14"
4+
VERSION_ID="8.14"
5+
PRETTY_NAME="NI Linux Real-Time - Academic 8.14"

roborio-cross-ubuntu-py/pip.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
[global]
3+
find-links = https://wpilib.jfrog.io/artifactory/wpilib-python-release-2024/

0 commit comments

Comments
 (0)