Skip to content

Commit 30b142d

Browse files
committed
Add Python crossenv environment for RoboRIO/Raspbian/Aarch64
1 parent 92d7977 commit 30b142d

16 files changed

+915
-0
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,5 @@ push/minimal-cross: push/minimal-base
6666

6767
push/opensdk:
6868
docker push ${DOCKER_USER}/opensdk-ubuntu:${OPENSDK_UBUNTU}
69+
70+
include cross-ubuntu-py/py.mk

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,10 @@ gazebo-ubuntu
3939
- Based on wpilib/ubuntu-base
4040
- Installs gazebo and protobuf required to build gazebo plugins
4141
- Published as wpilib/gazebo-ubuntu:host ubuntu version (e.g. 18.04)
42+
43+
roborio-cross-ubuntu-pyXXX
44+
raspbian-cross-ubuntu-pyXXX
45+
aarch64-cross-ubuntu-pyXXX
46+
- Based on the minimal cross compiler image
47+
- Contains crossenv at /build/venv for cross-compiling python wheels
48+
- Published as wpilib/{type}-cross-ubuntu:{version}-{ubuntu}-py{pyversion}
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: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
From 0bca228707c3f69cb8e6b4bc59b2ecf54f1f7c76 Mon Sep 17 00:00:00 2001
2+
From: Dustin Spicuzza <[email protected]>
3+
Date: Sat, 3 Oct 2020 12:31:44 -0400
4+
Subject: [PATCH] bpo-41916: allow cross-compiled python to have -pthread set
5+
for CXX
6+
7+
When cross-compiling, the compile/run test for -pthread always fails so -pthread
8+
will never be automatically set without an override from the cache. ac_cv_pthread
9+
can already be overridden, so do the same thing for ac_cv_cxx_thread.
10+
---
11+
configure | 12 +++++++++---
12+
configure.ac | 8 +++++---
13+
2 files changed, 14 insertions(+), 6 deletions(-)
14+
15+
diff --git a/configure b/configure
16+
index 0914e24704..119d720500 100755
17+
--- a/configure
18+
+++ b/configure
19+
@@ -7710,12 +7710,14 @@ fi
20+
21+
# If we have set a CC compiler flag for thread support then
22+
# check if it works for CXX, too.
23+
-ac_cv_cxx_thread=no
24+
if test ! -z "$CXX"
25+
then
26+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CXX also accepts flags for thread support" >&5
27+
$as_echo_n "checking whether $CXX also accepts flags for thread support... " >&6; }
28+
-ac_save_cxx="$CXX"
29+
+if ${ac_cv_cxx_thread+:} false; then :
30+
+ $as_echo_n "(cached) " >&6
31+
+else
32+
+ ac_save_cxx="$CXX"
33+
34+
if test "$ac_cv_kpthread" = "yes"
35+
then
36+
@@ -7744,10 +7746,14 @@ then
37+
fi
38+
rm -fr conftest*
39+
fi
40+
+CXX="$ac_save_cxx"
41+
+fi
42+
+
43+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_cxx_thread" >&5
44+
$as_echo "$ac_cv_cxx_thread" >&6; }
45+
+else
46+
+ ac_cv_cxx_thread=no
47+
fi
48+
-CXX="$ac_save_cxx"
49+
50+
51+
# checks for header files
52+
diff --git a/configure.ac b/configure.ac
53+
index 7051dc109a..6259c0290c 100644
54+
--- a/configure.ac
55+
+++ b/configure.ac
56+
@@ -2080,11 +2080,11 @@ fi
57+
58+
# If we have set a CC compiler flag for thread support then
59+
# check if it works for CXX, too.
60+
-ac_cv_cxx_thread=no
61+
if test ! -z "$CXX"
62+
then
63+
AC_MSG_CHECKING(whether $CXX also accepts flags for thread support)
64+
-ac_save_cxx="$CXX"
65+
+AC_CACHE_VAL(ac_cv_cxx_thread,
66+
+[ac_save_cxx="$CXX"
67+
68+
if test "$ac_cv_kpthread" = "yes"
69+
then
70+
@@ -2113,9 +2113,11 @@ then
71+
fi
72+
rm -fr conftest*
73+
fi
74+
+CXX="$ac_save_cxx"])
75+
AC_MSG_RESULT($ac_cv_cxx_thread)
76+
+else
77+
+ ac_cv_cxx_thread=no
78+
fi
79+
-CXX="$ac_save_cxx"
80+
81+
dnl # check for ANSI or K&R ("traditional") preprocessor
82+
dnl AC_MSG_CHECKING(for C preprocessor type)
83+
--
84+
2.26.2
85+

cross-ubuntu-py/Dockerfile.py310

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+
ARG ARCH=invalid-arch
4+
ARG VERSION=invalid-version
5+
6+
FROM wpilib/${ARCH}-cross-ubuntu-minimal:${VERSION}-${UBUNTU} AS pycompile
7+
8+
ARG TARGET_HOST=invalid-target-host
9+
ARG AC_TARGET_HOST=invalid-ac-target-host
10+
11+
ENV TARGET_HOST=${TARGET_HOST}
12+
ENV AC_TARGET_HOST=${AC_TARGET_HOST}
13+
ENV BUILD_HOST="x86_64"
14+
ENV WORKING_DIRECTORY="/build"
15+
ENV INSTALL_DIRECTORY="/build/crosspy"
16+
ENV PYTHON_VERSION="3.10.9"
17+
ENV SOURCE_DIRECTORY="Python-$PYTHON_VERSION"
18+
ENV PYTHON_ARCHIVE="Python-$PYTHON_VERSION.tar.xz"
19+
ENV PREFIX="$INSTALL_DIRECTORY"
20+
21+
#
22+
# Python compilation prereqs
23+
#
24+
25+
RUN set -xe; \
26+
apt-get update; \
27+
apt-get install -y build-essential checkinstall g++ libreadline-dev libncursesw5-dev libssl-dev \
28+
libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev liblzma-dev lzma-dev libffi-dev zlib1g-dev; \
29+
# cleanup
30+
rm -rf /var/lib/apt/lists/*
31+
32+
#
33+
# Python cross-compilation
34+
#
35+
36+
COPY 0001-bpo-41916-allow-cross-compiled-python-to-have-pthrea.patch /
37+
COPY 0001-Use-specified-host_cpu-when-cross-compiling-for-Linu.patch /
38+
39+
RUN set -xe; \
40+
mkdir -p "$PREFIX"; \
41+
# Download
42+
cd $WORKING_DIRECTORY; \
43+
wget -c https://www.python.org/ftp/python/$PYTHON_VERSION/$PYTHON_ARCHIVE; \
44+
rm -rf $SOURCE_DIRECTORY; \
45+
tar -xf $PYTHON_ARCHIVE; \
46+
cd $SOURCE_DIRECTORY; \
47+
# patch -pthread CXX issue
48+
patch -p1 < /0001-bpo-41916-allow-cross-compiled-python-to-have-pthrea.patch; \
49+
# patch arm cpu hardcoding
50+
patch -p1 < /0001-Use-specified-host_cpu-when-cross-compiling-for-Linu.patch; \
51+
# Build python for host
52+
cd $WORKING_DIRECTORY;cd $SOURCE_DIRECTORY; \
53+
./configure --enable-optimizations --with-ensurepip=install; \
54+
make -j altinstall; \
55+
# cross-compile
56+
cd $WORKING_DIRECTORY;cd $SOURCE_DIRECTORY; make distclean; \
57+
./configure --host=$TARGET_HOST --build=$BUILD_HOST --prefix=$PREFIX \
58+
--disable-ipv6 --enable-unicode=ucs4 \
59+
ac_cv_host=$AC_TARGET_HOST \
60+
ac_cv_buggy_getaddrinfo=no \
61+
ac_cv_file__dev_ptmx=no ac_cv_file__dev_ptc=no \
62+
ac_cv_have_long_long_format=yes \
63+
ac_cv_pthread_is_default=no ac_cv_pthread=yes ac_cv_cxx_thread=yes; \
64+
make -j; \
65+
# make install here is fine because we include --prefix in the configure statement
66+
make install
67+
68+
69+
#
70+
# Minimal cross-compilation environment
71+
#
72+
73+
FROM wpilib/${ARCH}-cross-ubuntu-minimal:${VERSION}-${UBUNTU} AS crossenv
74+
75+
RUN set -xe; \
76+
apt-get update; \
77+
apt-get install -y \
78+
binutils libreadline8 libncursesw5 libssl3 \
79+
libsqlite3-0 libgdbm6 libbz2-1.0 liblzma5 libffi7 zlib1g; \
80+
rm -rf /var/lib/apt/lists/*
81+
82+
COPY --from=pycompile /usr/local /usr/local
83+
COPY --from=pycompile /build/crosspy /build/crosspy
84+
85+
ARG ARCH=invalid-arch
86+
ARG TARGET_HOST=invalid-target-host
87+
88+
RUN set -xe; \
89+
ldconfig; \
90+
python3.10 -m pip install crossenv==1.4.0; \
91+
python3.10 -m crossenv /build/crosspy/bin/python3.10 /build/venv --sysroot=$(${TARGET_HOST}-gcc -print-sysroot) --env UNIXCONFDIR=/build/venv/cross/etc; \
92+
/build/venv/bin/cross-pip install wheel;
93+
94+
COPY pip-${ARCH}.conf /build/venv/cross/pip.conf
95+
COPY os-release-${ARCH} /build/venv/cross/etc/os-release
96+
97+
ENV RPYBUILD_PARALLEL=1
98+

cross-ubuntu-py/Dockerfile.py311

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
2+
ARG UBUNTU=22.04
3+
ARG ARCH=invalid-arch
4+
ARG VERSION=invalid-version
5+
6+
FROM wpilib/${ARCH}-cross-ubuntu-minimal:${VERSION}-${UBUNTU} AS pycompile
7+
8+
ARG TARGET_HOST=invalid-target-host
9+
ARG AC_TARGET_HOST=invalid-ac-target-host
10+
11+
ENV TARGET_HOST=${TARGET_HOST}
12+
ENV AC_TARGET_HOST=${AC_TARGET_HOST}
13+
ENV BUILD_HOST="x86_64"
14+
ENV WORKING_DIRECTORY="/build"
15+
ENV INSTALL_DIRECTORY="/build/crosspy"
16+
ENV PYTHON_VERSION="3.11.1"
17+
ENV PYTHON_FTP_VERSION="3.11.1"
18+
ENV PYTHON_EXE="python3.11"
19+
ENV SOURCE_DIRECTORY="Python-$PYTHON_VERSION"
20+
ENV PYTHON_ARCHIVE="Python-$PYTHON_VERSION.tar.xz"
21+
ENV PREFIX="$INSTALL_DIRECTORY"
22+
23+
#
24+
# Python compilation prereqs
25+
#
26+
27+
RUN set -xe; \
28+
apt-get update; \
29+
apt-get install -y build-essential checkinstall g++ libreadline-dev libncursesw5-dev libssl-dev \
30+
libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev liblzma-dev lzma-dev libffi-dev zlib1g-dev; \
31+
# cleanup
32+
rm -rf /var/lib/apt/lists/*
33+
34+
#
35+
# Python cross-compilation
36+
#
37+
38+
COPY 0001-bpo-41916-allow-cross-compiled-python-to-have-pthrea.patch /
39+
COPY 0001-Use-specified-host_cpu-when-cross-compiling-for-Linu.patch /
40+
41+
RUN set -xe; \
42+
mkdir -p "$PREFIX"; \
43+
# Download
44+
cd $WORKING_DIRECTORY; \
45+
wget -c https://www.python.org/ftp/python/$PYTHON_FTP_VERSION/$PYTHON_ARCHIVE; \
46+
rm -rf $SOURCE_DIRECTORY; \
47+
tar -xf $PYTHON_ARCHIVE; \
48+
cd $SOURCE_DIRECTORY; \
49+
# patch -pthread CXX issue
50+
patch -p1 < /0001-bpo-41916-allow-cross-compiled-python-to-have-pthrea.patch; \
51+
# patch arm cpu hardcoding
52+
patch -p1 < /0001-Use-specified-host_cpu-when-cross-compiling-for-Linu.patch; \
53+
# Build python for host
54+
cd $WORKING_DIRECTORY;cd $SOURCE_DIRECTORY; \
55+
./configure --enable-optimizations --with-ensurepip=install; \
56+
make -j; \
57+
make -j altinstall; \
58+
# cross-compile
59+
cd $WORKING_DIRECTORY;cd $SOURCE_DIRECTORY; make distclean; \
60+
./configure --host=$TARGET_HOST --build=$BUILD_HOST --prefix=$PREFIX \
61+
--with-build-python=$(which $PYTHON_EXE) \
62+
--disable-ipv6 \
63+
ac_cv_host=$AC_TARGET_HOST \
64+
ac_cv_buggy_getaddrinfo=no \
65+
ac_cv_file__dev_ptmx=no ac_cv_file__dev_ptc=no \
66+
ac_cv_have_long_long_format=yes \
67+
ac_cv_pthread_is_default=no ac_cv_pthread=yes ac_cv_cxx_thread=yes; \
68+
make -j; \
69+
# make install here is fine because we include --prefix in the configure statement
70+
make install
71+
72+
73+
#
74+
# Minimal cross-compilation environment
75+
#
76+
77+
FROM wpilib/${ARCH}-cross-ubuntu-minimal:${VERSION}-${UBUNTU} AS crossenv
78+
79+
RUN set -xe; \
80+
apt-get update; \
81+
apt-get install -y \
82+
binutils libreadline8 libncursesw5 libssl3 \
83+
libsqlite3-0 libgdbm6 libbz2-1.0 liblzma5 libffi7 zlib1g; \
84+
rm -rf /var/lib/apt/lists/*
85+
86+
COPY --from=pycompile /usr/local /usr/local
87+
COPY --from=pycompile /build/crosspy /build/crosspy
88+
89+
ARG ARCH=invalid-arch
90+
ARG TARGET_HOST=invalid-target-host
91+
92+
RUN set -xe; \
93+
ldconfig; \
94+
python3.11 -m pip install crossenv==1.4.0; \
95+
python3.11 -m crossenv /build/crosspy/bin/python3.11 /build/venv --sysroot=$(${TARGET_HOST}-print-sysroot) --env UNIXCONFDIR=/build/venv/cross/etc; \
96+
/build/venv/bin/cross-pip install wheel;
97+
98+
COPY pip-${ARCH}.conf /build/venv/cross/pip.conf
99+
COPY os-release-${ARCH} /build/venv/cross/etc/os-release
100+
101+
ENV RPYBUILD_PARALLEL=1
102+

0 commit comments

Comments
 (0)