Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cross #51

Closed
wants to merge 23 commits into from
5 changes: 3 additions & 2 deletions .cirrus.star
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def main(ctx):
# - commit message containing [wheel build]
######################################################################

if env.get("CIRRUS_REPO_FULL_NAME") != "scipy/scipy":
if env.get("CIRRUS_REPO_FULL_NAME") != "andyfaff/scipy":
return []

if env.get("CIRRUS_CRON", "") == "nightly":
Expand All @@ -38,4 +38,5 @@ def main(ctx):
if "[skip cirrus]" in dct["message"] or "[skip ci]" in dct["message"]:
return []

return fs.read("ci/cirrus_general_ci.yml")
return fs.read("ci/cirrus_cross_compile.yml")
# return fs.read("ci/cirrus_general_ci.yml") + fs.read("ci/cirrus_cross_compile.yml")
139 changes: 139 additions & 0 deletions ci/cirrus_cross_compile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
# a cross-compile task

modified_clone: &MODIFIED_CLONE
# makes sure that for a PR the CI runs against a merged main
clone_script: |
if [ -z "$CIRRUS_PR" ]; then
# if you're not in a PR then clone against the branch name that was pushed to.
git clone --recursive --branch=$CIRRUS_BRANCH https://x-access-token:${CIRRUS_REPO_CLONE_TOKEN}@github.com/${CIRRUS_REPO_FULL_NAME}.git $CIRRUS_WORKING_DIR
git reset --hard $CIRRUS_CHANGE_IN_REPO
else
# it's a PR so clone the main branch then merge the changes from the PR
git clone https://x-access-token:${CIRRUS_REPO_CLONE_TOKEN}@github.com/${CIRRUS_REPO_FULL_NAME}.git $CIRRUS_WORKING_DIR
git fetch origin pull/$CIRRUS_PR/head:pull/$CIRRUS_PR

# CIRRUS_BASE_BRANCH will probably be `main` for the majority of the time
# However, if you do a PR against a maintenance branch we will want to
# merge the PR into the maintenance branch, not main
git checkout $CIRRUS_BASE_BRANCH

# alpine git package needs default user.name and user.email to be set before a merge
git -c user.email="you@example.com" merge --no-commit pull/$CIRRUS_PR
git submodule update --init --recursive
fi


cross_compile_wheel_task:
compute_engine_instance:
image_project: cirrus-images
image: family/docker-builder
platform: linux
cpu: 4
memory: 16G

<<: *MODIFIED_CLONE

pip_cache:
folder: ~/.cache/pip

test_script: |
apt-get update

apt-get install -y --no-install-recommends pkg-config curl pkg-config cmake
apt-get install -y --no-install-recommends gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu gfortran-aarch64-linux-gnu g++-aarch64-linux-gnu

pushd tools
python3 -c "import openblas_support as obs;obs.download_openblas('openblas.tar.gz', 'linux-aarch64', None)"
# extracts files to /usr/local/lib, etc.
tar -zvxf openblas.tar.gz -C /
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH
popd

export PTH=$CIRRUS_VOLUME/miniconda3
curl https://repo.anaconda.com/miniconda/Miniconda3-py310_23.3.1-0-Linux-x86_64.sh -o conda.sh

HOME=$CIRRUS_VOLUME bash conda.sh -b -u -p $PTH
source $PTH/bin/activate
conda config --set channel_priority strict
conda config --add channels conda-forge

export PYVER="3.10"
conda create -n build-env -y python=$PYVER

CONDA_SUBDIR=linux-aarch64 conda create -n host-env -y -q python=$PYVER numpy cython pybind11
export PREFIX=$PTH/envs/host-env
export BUILD_PREFIX=$PTH/envs/build-env
export CMAKE_PREFIX_PATH=$PTH/envs/host-env/lib/python$PYVER/site-packages/pybind11/share/cmake/pybind11/:$CMAKE_PREFIX_PATH
export PKG_CONFIG_PATH=$PTH/envs/host-env/lib/python$PYVER/site-packages/pybind11/share/pkgconfig:$PKG_CONFIG_PATH
export CONDA_BUILD=1
conda activate build-env

pip install numpy cython pybind11 meson meson-python ninja

# setup native file
echo "[binaries]" > native-file.ini
echo "python = '$BUILD_PREFIX/bin/python$PYVER'" >> native-file.ini

# setup cross file
echo "[constants]" > cross-file.ini
echo "sitepkg = '$PREFIX/lib/python$PYVER/site-packages/'" >> cross-file.ini

echo "[properties]" >> cross-file.ini
echo "numpy-include-dir = sitepkg + 'numpy/core/include'" >> cross-file.ini
echo "pythran-include-dir = sitepkg + 'pythran'" >> cross-file.ini

echo "[host_machine]" >> cross-file.ini
echo "system = 'linux'" >> cross-file.ini
echo "cpu_family = 'aarch64'" >> cross-file.ini
echo "cpu = 'aarch64'" >> cross-file.ini
echo "endian = 'little'" >> cross-file.ini

echo "[binaries]" >> cross-file.ini
echo "c = 'aarch64-linux-gnu-gcc'" >> cross-file.ini
echo "cpp = 'aarch64-linux-gnu-g++'" >> cross-file.ini
echo "strip = 'aarch64-linux-gnu-strip'" >> cross-file.ini
echo "ar = 'aarch64-linux-gnu-ar'" >> cross-file.ini
echo "fortran = 'aarch64-linux-gnu-gfortran'" >> cross-file.ini
echo "pybind11-config = sitepkg + 'pybind11/share/pkgconfig'" >> cross-file.ini
echo "pkgconfig = '/usr/bin/pkg-config'" >> cross-file.ini
echo "cmake = '/usr/bin/cmake'" >> cross-file.ini
# echo "python = '$PREFIX/bin/python$PYVER'" >> cross-file.ini

export CROSS_COMPILE=1
export _PYTHON_HOST_PLATFORM='linux_aarch64'

meson setup --cross-file cross-file.ini --native-file native-file.ini build -Duse-pythran=false
python -m pip wheel -w dist -vvv --config-settings builddir=build . --no-build-isolation

crosswheels_artifacts:
path: "dist/*"


test_cross_compiled_wheel_task:
# which bash, etc, may not be present.
depends_on:
- cross_compile_wheel

compute_engine_instance:
image_project: cirrus-images
image: family/docker-builder-arm64
architecture: arm64
platform: linux
cpu: 4
memory: 16G

test_script: |
apt-get update
apt-get install -y python3.10 python3.10-venv
# python3.10 -m ensurepip --default-pip --user

ln -s $(which python3.10) python
export PATH=$PWD:$PATH

python -m pip install numpy pytest pooch

curl https://api.cirrus-ci.com/v1/artifact/build/$CIRRUS_BUILD_ID/crosswheels.zip --output wheels.zip
unzip wheels.zip
python -m pip install dist/scipy*.whl
pushd dist
python -m pytest --pyargs scipy -n2 --durations=10