Skip to content

Commit 39729cd

Browse files
committed
Add cross compiled python and setup toolchain
1 parent 94745ff commit 39729cd

File tree

7 files changed

+218
-19
lines changed

7 files changed

+218
-19
lines changed

Makefile

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
DOCKER = docker
88

99
# Docker organization to pull the images from
10-
ORG = dockcross
10+
#ORG = quay.io/pypa
11+
ORG = odidev
1112

1213
# Directory where to generate the dockcross script for each images (e.g bin/dockcross-manylinux1-x64)
1314
BIN = ./bin
@@ -48,7 +49,7 @@ ifeq ("$(CIRCLECI)", "true")
4849
endif
4950

5051
# Tag images with date and Git short hash in addition to revision
51-
TAG := $(shell date '+%Y%m%d')-$(shell git rev-parse --short HEAD)
52+
TAG := $(shell date '+%Y-%m-%d')-$(shell git rev-parse --short HEAD)
5253

5354
#
5455
# images: This target builds all IMAGES (because it is the first one, it is built by default)
@@ -102,15 +103,19 @@ web-wasm.test: web-wasm
102103
# manylinux2014-aarch64
103104
#
104105
manylinux2014-aarch64: manylinux2014-aarch64/Dockerfile
106+
@# Get libstdc++ from quay.io/pypa/manylinux2014_aarch64 container
107+
docker run -v `pwd`:/host --rm -it -e LIB_PATH=/host/$@/xc_script/ quay.io/pypa/manylinux2014_aarch64 bash -c "PASS=1 /host/$@/xc_script/docker_setup_scrpits/copy_libstd.sh"
105108
mkdir -p $@/imagefiles && cp -r imagefiles $@/
106-
$(DOCKER) build -t $(ORG)/manylinux2014-aarch64:latest \
107-
-t $(ORG)/manylinux2014-aarch64:$(TAG) \
109+
$(DOCKER) build -t $(ORG)/manylinux2014_aarch64:latest \
110+
-t $(ORG)/manylinux2014_aarch64:$(TAG) \
108111
--build-arg IMAGE=$(ORG)/manylinux2014-aarch64 \
109112
--build-arg VCS_REF=`git rev-parse --short HEAD` \
110113
--build-arg VCS_URL=`git config --get remote.origin.url` \
111114
--build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \
112115
-f manylinux2014-aarch64/Dockerfile .
113116
rm -rf $@/imagefiles
117+
@# libstdc++ is coppied into image, now remove it
118+
docker run -v `pwd`:/host --rm -it quay.io/pypa/manylinux2014_aarch64 bash -c "rm -rf /host/$@/xc_script/usr"
114119

115120
manylinux2014-aarch64.test: manylinux2014-aarch64
116121
$(DOCKER) run $(RM) $(ORG)/manylinux2014-aarch64 > $(BIN)/dockcross-manylinux2014-aarch64 && chmod +x $(BIN)/dockcross-manylinux2014-aarch64

manylinux2014-aarch64/Dockerfile.in

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@ RUN \
2020
qemu-system-arm && \
2121
yum clean all
2222

23+
RUN cd /usr/xcc/aarch64-unknown-linux-gnueabi/lib/gcc/aarch64-unknown-linux-gnueabi/9.3.0/include && \
24+
wget https://gist.githubusercontent.com/nhatminhle/5181506/raw/541482dbc61862bba8a156edaae57faa2995d791/stdatomic.h
25+
26+
# Running scripts to cross compile python and copy libstdc++ into toolcain
27+
ADD manylinux2014-aarch64/xc_script /tmp/
28+
RUN PASS=2 /tmp/docker_setup_scrpits/copy_libstd.sh
29+
RUN /tmp/docker_setup_scrpits/prepare_cross_env.sh
30+
RUN rm -rf /tmp/docker_setup_scrpits
31+
RUN yum update
2332
# The CROSS_TRIPLE is a configured alias of the "aarch64-unknown-linux-gnueabi" target.
2433
ENV CROSS_TRIPLE aarch64-unknown-linux-gnueabi
2534

@@ -50,7 +59,7 @@ ENV AUDITWHEEL_PLAT manylinux2014_$AUDITWHEEL_ARCH
5059

5160
# Build-time metadata as defined at http://label-schema.org
5261
ARG BUILD_DATE
53-
ARG IMAGE=dockcross/manylinux2014-aarch64
62+
ARG IMAGE=odidev/manylinux2014_aarch64
5463
ARG VERSION=latest
5564
ARG VCS_REF
5665
ARG VCS_URL

manylinux2014-aarch64/crosstool-ng.config

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -356,15 +356,15 @@ CT_CC_CORE_PASSES_NEEDED=y
356356
CT_CC_CORE_PASS_1_NEEDED=y
357357
CT_CC_CORE_PASS_2_NEEDED=y
358358
CT_CC_gcc=y
359-
CT_CC_GCC_VERSION="4.8.5"
359+
CT_CC_GCC_VERSION="9.3.0"
360360
# CT_CC_GCC_SHOW_LINARO is not set
361-
CT_CC_GCC_V_4_8_5=y
361+
CT_CC_GCC_V_9_3_0=y
362362
# CT_CC_GCC_V_5_4_0 is not set
363363
# CT_CC_GCC_V_4_9_4 is not set
364-
CT_CC_GCC_4_8_or_later=y
364+
CT_CC_GCC_9_3_or_later=y
365365
# CT_CC_GCC_4_9_or_later=y
366-
CT_CC_GCC_4_or_later=y
367-
CT_CC_GCC_4=y
366+
CT_CC_GCC_9_or_later=y
367+
CT_CC_GCC_9=y
368368
# CT_CC_GCC_6_or_later=y
369369
CT_CC_GCC_ENABLE_PLUGINS=y
370370
CT_CC_GCC_GOLD=y
@@ -463,7 +463,6 @@ CT_GETTEXT_NEEDED=y
463463
CT_GMP_NEEDED=y
464464
CT_MPFR_NEEDED=y
465465
CT_ISL_NEEDED=y
466-
CT_CLOOG_NEEDED=y
467466
CT_MPC_NEEDED=y
468467
# CT_EXPAT_NEEDED=y
469468
CT_NCURSES_NEEDED=y
@@ -473,7 +472,6 @@ CT_GETTEXT=y
473472
CT_GMP=y
474473
CT_MPFR=y
475474
CT_ISL=y
476-
CT_CLOOG=y
477475
CT_MPC=y
478476
# CT_EXPAT=y
479477
CT_NCURSES=y
@@ -488,15 +486,11 @@ CT_GMP_5_0_2_or_later=y
488486
CT_GMP_VERSION="6.1.2"
489487
CT_MPFR_V_3_1_5=y
490488
CT_MPFR_VERSION="3.1.5"
491-
CT_ISL_V_0_11_1=y
489+
CT_ISL_V_0_15=y
492490
# CT_ISL_V_0_15_or_later=y
493491
# CT_ISL_V_0_14_or_later=y
494-
CT_ISL_V_0_11_or_later=y
495-
CT_ISL_VERSION="0.11.1"
496-
CT_CLOOG_V_0_18_0=y
497-
CT_CLOOG_VERSION="0.18.0"
498-
# CT_CLOOG_0_18_4_or_later=y
499-
CT_CLOOG_0_18_or_later=y
492+
CT_ISL_V_0_15_or_later=y
493+
CT_ISL_VERSION="0.15"
500494
CT_MPC_V_1_0_3=y
501495
CT_MPC_VERSION="1.0.3"
502496
# CT_EXPAT_V_2_2_0=y
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
3+
# AUTHOR: odidev
4+
# DATE: 2021-07-20
5+
# DESCRIPTION: This file is invoked two times. first time from Makefile with
6+
# PASS == 1 and second time in Dockerfile.in with PASS == 2. In
7+
# dockcross container, the current libstdc++ is not the same as
8+
# in manylinux containers. So, copying the libstdc++ form manylinux
9+
# container to dockcross container. It is being done int 2 pass.
10+
# during PASS == 1, the script will copy libstdc++ from manylinux
11+
# container to build machine and then during PASS == 2, libstdc++
12+
# will be copied from build machine to dockcross container
13+
14+
if [ $PASS == 1 ]; then
15+
echo "library location on host: " ${LIB_PATH}
16+
echo "PASS 1: copying libstdc++ library on host"
17+
files=$(rpm -ql libstdc++)
18+
for file in ${files}; do
19+
if [ -f ${file} -a ! -L ${file} -a ! -d ${file} ]; then
20+
if grep -q "shared object" <<< $(file $file); then
21+
install -m 0644 -D ${file} "${LIB_PATH}${file}"
22+
break;
23+
fi
24+
fi
25+
done
26+
echo "Done"
27+
elif [ $PASS == 2 ]; then
28+
echo "PASS 2: copying libstdc++ library in docker image"
29+
old_libstdc_path=$(find /usr/xcc/ -name libstdc++.so*[0-9] -type f)
30+
old_libstdc_directory=$(dirname "${old_libstdc_path}")
31+
target_libstdc_path=$(find /tmp -name libstdc++.so*[0-9] -type f)
32+
target_libstdc_filename=$(basename "${target_libstdc_path}")
33+
target_libstdc_new_path=${old_libstdc_directory}/${target_libstdc_filename}
34+
install -m 0555 -D ${target_libstdc_path} ${target_libstdc_new_path}
35+
echo "Done"
36+
links=$(find /usr/xcc/ \( -name libstdc++.so*[{0-9}] -o -name libstdc++.so \) -type l)
37+
echo "Creating soft links for target libstdc++ library"
38+
for link in ${links}; do
39+
ln -sf ${target_libstdc_new_path} ${link}
40+
done
41+
echo "Done"
42+
fi
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#!/bin/bash
2+
3+
# AUTHOR: odidev
4+
# DATE: 2021-07-20
5+
# DESCRIPTION: This file intended to cross compile the python and create necessary
6+
# crossenv enrironment
7+
8+
# The current env is not compatible to build python so resetting it as
9+
# in quay.io/pypa/manylinux2014_x86_64 containers
10+
unset $(env | awk -F= '{print $1}')
11+
export SSL_CERT_FILE=/opt/_internal/certs.pem
12+
export TERM=xterm
13+
export LC_ALL=en_US.UTF-8
14+
export LD_LIBRARY_PATH=/opt/rh/devtoolset-9/root/usr/lib64:/opt/rh/devtoolset-9/root/usr/lib:/opt/rh/devtoolset-9/root/usr/lib64/dyninst:/opt/rh/devtoolset-9/root/usr/lib/dyninst:/usr/local/lib64
15+
export PATH=/opt/rh/devtoolset-9/root/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
16+
export PWD=/work
17+
export LANG=en_US.UTF-8
18+
export AUDITWHEEL_ARCH=x86_64
19+
export DEVTOOLSET_ROOTPATH=/opt/rh/devtoolset-9/root
20+
export HOME=/root
21+
export SHLVL=1
22+
export LANGUAGE=en_US.UTF-8
23+
export AUDITWHEEL_PLAT=manylinux2014_aarch64
24+
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
25+
export AUDITWHEEL_POLICY=manylinux2014
26+
27+
# Python to be cross compiled
28+
#declare -A buildpy=( ["3.6.13"]="cp36-cp36m" ["3.7.10"]="cp37-cp37m" ["3.8.9"]="cp38-cp38" ["3.9.4"]="cp39-cp39" ["3.10.0"]="cp310-cp310")
29+
#python_vers="3.6.13 3.7.10 3.8.9 3.9.4 3.10.0"
30+
# 3.10 is not supported in crossenv for now
31+
declare -A buildpy=( ["3.6.13"]="cp36-cp36m" ["3.7.10"]="cp37-cp37m" ["3.8.9"]="cp38-cp38" ["3.9.4"]="cp39-cp39")
32+
python_vers="3.6.13 3.7.10 3.8.9 3.9.4"
33+
34+
# Adding cross compiler path in PATH env variable
35+
export PATH=/usr/xcc/aarch64-unknown-linux-gnueabi/bin:$PATH
36+
37+
OLD_PATH=$PATH
38+
CROSS_PY_BASE=/opt/_internal
39+
CROSS_PY_BASE_LN=/opt/python
40+
BUILD_DIR=/tmp/builds
41+
LN=ln
42+
sub_rel=""
43+
# Loop over each python version and cross compile it
44+
for python_ver in $python_vers; do
45+
echo ${python_ver}
46+
echo ${buildpy[$python_ver]}
47+
48+
#if [ $python_ver = "3.10.0" ]; then
49+
# sub_rel="b2"
50+
#fi
51+
52+
mkdir -p ${BUILD_DIR} && cd ${BUILD_DIR}
53+
wget https://www.python.org/ftp/python/${python_ver}/Python-${python_ver}${sub_rel}.tgz
54+
tar xzf Python-${python_ver}${sub_rel}.tgz
55+
cd Python-${python_ver}${sub_rel}
56+
57+
# Setting up build python path required by crassenv
58+
BUILD_PYBIN=${CROSS_PY_BASE_LN}/${buildpy[$python_ver]}/bin
59+
BUILD_PIP=${BUILD_PYBIN}/pip3
60+
BUILD_PYTHON=${BUILD_PYBIN}/python3
61+
62+
# Setting up target python required by crossenv
63+
TARGET_PYPATH=${CROSS_PY_BASE}/xc/xcpython-${python_ver}
64+
TARGET_PYTHON=${TARGET_PYPATH}/bin/python3
65+
66+
# Setting up cross env path
67+
CROSS_ENV=${CROSS_PY_BASE}/${buildpy[$python_ver]}-xc
68+
CROSS_ENV_LN=${CROSS_PY_BASE_LN}/${buildpy[$python_ver]}-xc
69+
CROSS_ENV_PIP=${CROSS_ENV_LN}/cross/bin/pip
70+
71+
# Adding build python path as it is required to
72+
# configure the python for cross compilation
73+
PATH=${BUILD_PYBIN}:${OLD_PATH}
74+
export PATH
75+
76+
./configure --prefix=${TARGET_PYPATH} \
77+
--host=aarch64-unknown-linux-gnueabi \
78+
--build=x86_64-linux-gnu \
79+
--without-ensurepip \
80+
ac_cv_buggy_getaddrinfo=no \
81+
ac_cv_file__dev_ptmx=yes \
82+
ac_cv_file__dev_ptc=no \
83+
--enable-optimizations
84+
make -j32 install
85+
make install
86+
87+
# Create the necessary env and its link
88+
${BUILD_PIP} install --upgrade pip crossenv
89+
${BUILD_PYTHON} -m crossenv ${TARGET_PYTHON} ${CROSS_ENV}
90+
${LN} -s ${CROSS_ENV} ${CROSS_ENV_LN}
91+
${CROSS_ENV_PIP} install wheel
92+
rm -rf ${BUILD_DIR}
93+
done
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
3+
# AUTHOR: odidev
4+
# DATE: 2021-07-20
5+
# DESCRIPTION: This file will be invoked by cibuildwheel when before all is set.
6+
# It will install the package in manylinux container and copy back
7+
# the installed files on host machine will will be coppied to
8+
# toolchain
9+
10+
install_dir='/host/tmp/install_deps'
11+
packages=$(echo $1 | sed 's/\(yum\s*\|install\s*\|-y\s*\)//g')
12+
13+
# Installing the packages
14+
echo "Installing dependencies: $packages"
15+
if $1; then
16+
echo "Installed successfully"
17+
else
18+
echo "Failed"
19+
exit 1
20+
fi
21+
22+
# Coping the installed files
23+
if list=`rpm -ql $packages`; then
24+
25+
echo "Copying dependencies files to prepare cross toolchain-"
26+
27+
for file in $list; do
28+
test -f $file && echo "Copy $file --> ${install_dir}${file}"
29+
test -f $file && install -m 0644 -D $file "${install_dir}${file}"
30+
done
31+
else
32+
echo $list
33+
echo "Dependencies not resolved"
34+
exit 1
35+
fi
36+
exit 0
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
3+
# AUTHOR: odidev
4+
# DATE: 2021-07-20
5+
# DESCRIPTION: The wheels are cross compiled and we can't be repair in currnet
6+
# environment. So, better to repair in manylinux container. So,
7+
# we need to run BEFORE_ALL again in target manylinux contaner. So,
8+
# instead of running BEFORE_ALL again we can copy the stored files.
9+
# INPUT: $1 --> Dependeicies install path on host machine with respect to
10+
# container
11+
# $2 --> Wheel repair command
12+
13+
install_dir="$1"
14+
15+
for file in `find $install_dir -type f`; do
16+
install_path=$(echo ${file} | sed 's/^.*usr/\/usr/')
17+
install -m 0644 -D ${file} ${install_path}
18+
done
19+
20+
$2

0 commit comments

Comments
 (0)