| 1 |
# Meson's Python module doesn't support crosscompiling, |
| 2 |
# and python dependencies may be another potential hurdle. |
| 3 |
# There might also be a need to run runtime tests during configure time. |
| 4 |
# |
| 5 |
# The recommended practice is to rely on Docker to provide the x86_64 crosscompile toolchain, |
| 6 |
# enabling native execution via binfmt. |
| 7 |
# |
| 8 |
# In simpler terms, everything except the crosscompile toolchain will be emulated. |
| 9 |
|
| 10 |
name: Linux Qemu tests |
| 11 |
|
| 12 |
on: |
| 13 |
pull_request: |
| 14 |
branches: |
| 15 |
- main |
| 16 |
- maintenance/** |
| 17 |
paths-ignore: |
| 18 |
- '**.pyi' |
| 19 |
- '**.md' |
| 20 |
- '**.rst' |
| 21 |
workflow_dispatch: |
| 22 |
|
| 23 |
defaults: |
| 24 |
run: |
| 25 |
shell: bash |
| 26 |
|
| 27 |
concurrency: |
| 28 |
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} |
| 29 |
cancel-in-progress: true |
| 30 |
|
| 31 |
permissions: |
| 32 |
contents: read |
| 33 |
|
| 34 |
jobs: |
| 35 |
linux_qemu: |
| 36 |
# Only workflow_dispatch is enabled on forks. |
| 37 |
# To enable this job and subsequent jobs on a fork for other events, comment out: |
| 38 |
if: github.repository == 'numpy/numpy' || github.event_name == 'workflow_dispatch' |
| 39 |
runs-on: ubuntu-22.04 |
| 40 |
continue-on-error: true |
| 41 |
strategy: |
| 42 |
fail-fast: false |
| 43 |
matrix: |
| 44 |
BUILD_PROP: |
| 45 |
- [ |
| 46 |
"riscv64", |
| 47 |
"riscv64-linux-gnu", |
| 48 |
"riscv64/ubuntu:22.04", |
| 49 |
"-Dallow-noblas=true", |
| 50 |
"test_kind or test_multiarray or test_simd or test_umath or test_ufunc", |
| 51 |
"riscv64" |
| 52 |
] |
| 53 |
env: |
| 54 |
TOOLCHAIN_NAME: ${{ matrix.BUILD_PROP[1] }} |
| 55 |
DOCKER_CONTAINER: ${{ matrix.BUILD_PROP[2] }} |
| 56 |
MESON_OPTIONS: ${{ matrix.BUILD_PROP[3] }} |
| 57 |
RUNTIME_TEST_FILTER: ${{ matrix.BUILD_PROP[4] }} |
| 58 |
ARCH: ${{ matrix.BUILD_PROP[5] }} |
| 59 |
TERM: xterm-256color |
| 60 |
|
| 61 |
name: "${{ matrix.BUILD_PROP[0] }}" |
| 62 |
steps: |
| 63 |
- uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 |
| 64 |
with: |
| 65 |
submodules: recursive |
| 66 |
fetch-tags: true |
| 67 |
persist-credentials: false |
| 68 |
|
| 69 |
- name: Initialize binfmt_misc for qemu-user-static |
| 70 |
run: | |
| 71 |
# see https://hub.docker.com/r/tonistiigi/binfmt for available versions |
| 72 |
docker run --rm --privileged tonistiigi/binfmt:qemu-v9.2.2-52 --install all |
| 73 |
|
| 74 |
- name: Install GCC cross-compilers |
| 75 |
run: | |
| 76 |
sudo apt update |
| 77 |
sudo apt install -y ninja-build gcc-${TOOLCHAIN_NAME} g++-${TOOLCHAIN_NAME} gfortran-${TOOLCHAIN_NAME} |
| 78 |
|
| 79 |
- name: Cache docker container |
| 80 |
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 |
| 81 |
id: container-cache |
| 82 |
with: |
| 83 |
path: ~/docker_${{ matrix.BUILD_PROP[1] }} |
| 84 |
key: container-${{ runner.os }}-${{ matrix.BUILD_PROP[1] }}-${{ matrix.BUILD_PROP[2] }}-${{ hashFiles('requirements/build_requirements.txt') }} |
| 85 |
|
| 86 |
- name: Creates new container |
| 87 |
if: steps.container-cache.outputs.cache-hit != 'true' |
| 88 |
run: | |
| 89 |
docker run --platform=linux/${ARCH} --name the_container --interactive \ |
| 90 |
-v /:/host -v $(pwd):/numpy ${DOCKER_CONTAINER} /bin/bash -c " |
| 91 |
apt update && |
| 92 |
apt install -y cmake git python3 python-is-python3 python3-dev python3-pip && |
| 93 |
mkdir -p /lib64 && ln -s /host/lib64/ld-* /lib64/ && |
| 94 |
ln -s /host/lib/x86_64-linux-gnu /lib/x86_64-linux-gnu && |
| 95 |
rm -rf /usr/${TOOLCHAIN_NAME} && ln -s /host/usr/${TOOLCHAIN_NAME} /usr/${TOOLCHAIN_NAME} && |
| 96 |
rm -rf /usr/lib/gcc/${TOOLCHAIN_NAME} && ln -s /host/usr/lib/gcc-cross/${TOOLCHAIN_NAME} /usr/lib/gcc/${TOOLCHAIN_NAME} && |
| 97 |
rm -f /usr/bin/gcc && ln -s /host/usr/bin/${TOOLCHAIN_NAME}-gcc /usr/bin/gcc && |
| 98 |
rm -f /usr/bin/g++ && ln -s /host/usr/bin/${TOOLCHAIN_NAME}-g++ /usr/bin/g++ && |
| 99 |
rm -f /usr/bin/gfortran && ln -s /host/usr/bin/${TOOLCHAIN_NAME}-gfortran /usr/bin/gfortran && |
| 100 |
rm -f /usr/bin/ar && ln -s /host/usr/bin/${TOOLCHAIN_NAME}-ar /usr/bin/ar && |
| 101 |
rm -f /usr/bin/as && ln -s /host/usr/bin/${TOOLCHAIN_NAME}-as /usr/bin/as && |
| 102 |
rm -f /usr/bin/ld && ln -s /host/usr/bin/${TOOLCHAIN_NAME}-ld /usr/bin/ld && |
| 103 |
rm -f /usr/bin/ld.bfd && ln -s /host/usr/bin/${TOOLCHAIN_NAME}-ld.bfd /usr/bin/ld.bfd && |
| 104 |
rm -f /usr/bin/ninja && ln -s /host/usr/bin/ninja /usr/bin/ninja && |
| 105 |
git config --global --add safe.directory /numpy && |
| 106 |
# No need to build ninja from source, the host ninja is used for the build |
| 107 |
grep -v ninja /numpy/requirements/build_requirements.txt > /tmp/build_requirements.txt && |
| 108 |
python -m pip install -r /tmp/build_requirements.txt && |
| 109 |
python -m pip install pytest pytest-xdist hypothesis typing_extensions pytest-timeout && |
| 110 |
rm -f /usr/local/bin/ninja && mkdir -p /usr/local/bin && ln -s /host/usr/bin/ninja /usr/local/bin/ninja |
| 111 |
" |
| 112 |
docker commit the_container the_container |
| 113 |
mkdir -p "~/docker_${TOOLCHAIN_NAME}" |
| 114 |
docker save -o "~/docker_${TOOLCHAIN_NAME}/the_container.tar" the_container |
| 115 |
|
| 116 |
- name: Load container from cache |
| 117 |
if: steps.container-cache.outputs.cache-hit == 'true' |
| 118 |
run: docker load -i "~/docker_${TOOLCHAIN_NAME}/the_container.tar" |
| 119 |
|
| 120 |
- name: Meson Build |
| 121 |
run: | |
| 122 |
docker run --rm --platform=linux/${ARCH} -e "TERM=xterm-256color" \ |
| 123 |
-v $(pwd):/numpy -v /:/host the_container \ |
| 124 |
/bin/script -e -q -c "/bin/bash --noprofile --norc -eo pipefail -c ' |
| 125 |
cd /numpy && spin build --clean -- ${MESON_OPTIONS} |
| 126 |
'" |
| 127 |
|
| 128 |
- name: Meson Log |
| 129 |
if: always() |
| 130 |
run: 'cat build/meson-logs/meson-log.txt' |
| 131 |
|
| 132 |
- name: Run Tests |
| 133 |
run: | |
| 134 |
docker run --rm --platform=linux/${ARCH} -e "TERM=xterm-256color" \ |
| 135 |
-v $(pwd):/numpy -v /:/host the_container \ |
| 136 |
/bin/script -e -q -c "/bin/bash --noprofile --norc -eo pipefail -c ' |
| 137 |
export F90=/usr/bin/gfortran |
| 138 |
cd /numpy && spin test -- --timeout=600 --durations=10 -k \"${RUNTIME_TEST_FILTER}\" |
| 139 |
'" |
| 140 |
|
| 141 |
|
| 142 |
linux_loongarch64_qemu: |
| 143 |
# Only workflow_dispatch is enabled on forks. |
| 144 |
# To enable this job and subsequent jobs on a fork for other events, comment out: |
| 145 |
if: github.repository == 'numpy/numpy' || github.event_name == 'workflow_dispatch' |
| 146 |
runs-on: ubuntu-24.04 |
| 147 |
continue-on-error: true |
| 148 |
strategy: |
| 149 |
fail-fast: false |
| 150 |
matrix: |
| 151 |
BUILD_PROP: |
| 152 |
- [ |
| 153 |
"loongarch64", |
| 154 |
"loongarch64-linux-gnu", |
| 155 |
"cnclarechen/numpy-loong64-debian:v1", |
| 156 |
"-Dallow-noblas=true", |
| 157 |
"test_kind or test_multiarray or test_simd or test_umath or test_ufunc", |
| 158 |
"loong64" |
| 159 |
] |
| 160 |
env: |
| 161 |
TOOLCHAIN_NAME: ${{ matrix.BUILD_PROP[1] }} |
| 162 |
DOCKER_CONTAINER: ${{ matrix.BUILD_PROP[2] }} |
| 163 |
MESON_OPTIONS: ${{ matrix.BUILD_PROP[3] }} |
| 164 |
RUNTIME_TEST_FILTER: ${{ matrix.BUILD_PROP[4] }} |
| 165 |
ARCH: ${{ matrix.BUILD_PROP[5] }} |
| 166 |
TERM: xterm-256color |
| 167 |
|
| 168 |
name: "${{ matrix.BUILD_PROP[0] }}" |
| 169 |
steps: |
| 170 |
- uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 |
| 171 |
with: |
| 172 |
submodules: recursive |
| 173 |
fetch-tags: true |
| 174 |
|
| 175 |
- name: Initialize binfmt_misc for qemu-user-static |
| 176 |
run: | |
| 177 |
docker run --rm --privileged tonistiigi/binfmt:qemu-v10.0.4-56 --install all |
| 178 |
|
| 179 |
- name: Install GCC cross-compilers |
| 180 |
run: | |
| 181 |
sudo apt update |
| 182 |
sudo apt install -y ninja-build gcc-14-${TOOLCHAIN_NAME} g++-14-${TOOLCHAIN_NAME} gfortran-14-${TOOLCHAIN_NAME} |
| 183 |
|
| 184 |
- name: Cache docker container |
| 185 |
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 |
| 186 |
id: container-cache |
| 187 |
with: |
| 188 |
path: ~/docker_${{ matrix.BUILD_PROP[1] }} |
| 189 |
key: container-${{ runner.os }}-${{ matrix.BUILD_PROP[1] }}-${{ matrix.BUILD_PROP[2] }}-${{ hashFiles('requirements/build_requirements.txt') }} |
| 190 |
|
| 191 |
- name: Creates new container |
| 192 |
if: steps.container-cache.outputs.cache-hit != 'true' |
| 193 |
run: | |
| 194 |
docker run --platform=linux/${ARCH} --name the_container --interactive \ |
| 195 |
-v /:/host -v $(pwd):/numpy ${DOCKER_CONTAINER} /bin/bash -c " |
| 196 |
mkdir -p /lib64 && ln -s /host/lib64/ld-* /lib64/ && |
| 197 |
ln -s /host/lib/x86_64-linux-gnu /lib/x86_64-linux-gnu && |
| 198 |
ln -s /host/usr/${TOOLCHAIN_NAME} /usr/${TOOLCHAIN_NAME} && |
| 199 |
ln -s /host/usr/lib/gcc-cross/${TOOLCHAIN_NAME} /usr/lib/gcc/${TOOLCHAIN_NAME} && |
| 200 |
rm -f /usr/bin/gcc && ln -s /host/usr/bin/${TOOLCHAIN_NAME}-gcc-14 /usr/bin/gcc && |
| 201 |
rm -f /usr/bin/g++ && ln -s /host/usr/bin/${TOOLCHAIN_NAME}-g++-14 /usr/bin/g++ && |
| 202 |
rm -f /usr/bin/gfortran && ln -s /host/usr/bin/${TOOLCHAIN_NAME}-gfortran-14 /usr/bin/gfortran && |
| 203 |
rm -f /usr/bin/ar && ln -s /host/usr/bin/${TOOLCHAIN_NAME}-ar /usr/bin/ar && |
| 204 |
rm -f /usr/bin/as && ln -s /host/usr/bin/${TOOLCHAIN_NAME}-as /usr/bin/as && |
| 205 |
rm -f /usr/bin/ld && ln -s /host/usr/bin/${TOOLCHAIN_NAME}-ld /usr/bin/ld && |
| 206 |
rm -f /usr/bin/ld.bfd && ln -s /host/usr/bin/${TOOLCHAIN_NAME}-ld.bfd /usr/bin/ld.bfd && |
| 207 |
rm -f /usr/bin/ninja && ln -s /host/usr/bin/ninja /usr/bin/ninja && |
| 208 |
git config --global --add safe.directory /numpy && |
| 209 |
python -m pip install --break-system-packages -r /numpy/requirements/build_requirements.txt && |
| 210 |
python -m pip install --break-system-packages pytest pytest-xdist hypothesis typing_extensions |
| 211 |
" |
| 212 |
docker commit the_container the_container |
| 213 |
mkdir -p "~/docker_${TOOLCHAIN_NAME}" |
| 214 |
docker save -o "~/docker_${TOOLCHAIN_NAME}/the_container.tar" the_container |
| 215 |
|
| 216 |
- name: Load container from cache |
| 217 |
if: steps.container-cache.outputs.cache-hit == 'true' |
| 218 |
run: docker load -i "~/docker_${TOOLCHAIN_NAME}/the_container.tar" |
| 219 |
|
| 220 |
- name: Meson Build |
| 221 |
run: | |
| 222 |
docker run --rm --platform=linux/${ARCH} -e "TERM=xterm-256color" \ |
| 223 |
-v $(pwd):/numpy -v /:/host the_container \ |
| 224 |
/bin/script -e -q -c "/bin/bash --noprofile --norc -eo pipefail -c ' |
| 225 |
cd /numpy/ && spin build --clean -- ${MESON_OPTIONS} |
| 226 |
'" |
| 227 |
|
| 228 |
- name: Meson Log |
| 229 |
if: always() |
| 230 |
run: 'cat build/meson-logs/meson-log.txt' |
| 231 |
|
| 232 |
- name: Run Tests |
| 233 |
run: | |
| 234 |
docker run --rm --platform=linux/${ARCH} -e "TERM=xterm-256color" \ |
| 235 |
-v $(pwd):/numpy -v /:/host the_container \ |
| 236 |
/bin/script -e -q -c "/bin/bash --noprofile --norc -eo pipefail -c ' |
| 237 |
cd /numpy && spin test -- -k \"${RUNTIME_TEST_FILTER}\" |
| 238 |
'" |