-
Notifications
You must be signed in to change notification settings - Fork 418
164 lines (154 loc) · 6.56 KB
/
build_python_3.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
name: Build Python 3
on:
merge_group:
# Trigger jobs when PR is added to merge queue
types: [checks_requested]
workflow_call:
inputs:
cibw_build:
required: true
type: string
cibw_skip:
required: false
type: string
cibw_prerelease_pythons:
required: false
type: string
jobs:
build-wheels-matrix:
runs-on: ubuntu-latest
outputs:
include: ${{steps.set-matrix.outputs.include}}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.8'
- run: pip install cibuildwheel==2.16.5
- id: set-matrix
env:
CIBW_BUILD: ${{ inputs.cibw_build }}
run: |
MATRIX_INCLUDE=$(
{
cibuildwheel --print-build-identifiers --platform linux --arch x86_64,i686 | jq -cR '{only: ., os: "ubuntu-latest"}' \
&& cibuildwheel --print-build-identifiers --platform linux --arch aarch64 | jq -cR '{only: ., os: "arm-4core-linux"}' \
&& cibuildwheel --print-build-identifiers --platform windows --arch AMD64,x86 | jq -cR '{only: ., os: "windows-latest"}' \
&& cibuildwheel --print-build-identifiers --platform macos --arch x86_64,universal2 | jq -cR '{only: ., os: "macos-12"}'
} | jq -sc
)
echo $MATRIX_INCLUDE
echo "include=${MATRIX_INCLUDE}" >> $GITHUB_OUTPUT
build:
needs: build-wheels-matrix
runs-on: ${{ matrix.os }}
name: Build ${{ matrix.only }}
strategy:
matrix:
include: ${{ fromJson(needs.build-wheels-matrix.outputs.include) }}
steps:
- uses: actions/checkout@v4
# Include all history and tags
with:
fetch-depth: 0
- uses: actions/setup-python@v5
if: matrix.os != 'arm-4core-linux'
name: Install Python
with:
python-version: '3.8'
- name: Install docker and pipx
if: matrix.os == 'arm-4core-linux'
# The ARM64 Ubuntu has less things installed by default
# We need docker, pip and venv for cibuildwheel
# acl allows us to use docker in the same session
run: |
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
sudo usermod -a -G docker $USER
sudo apt install -y acl python3.10-venv python3-pip
sudo setfacl --modify user:runner:rw /var/run/docker.sock
python3 -m pip install pipx
- name: Set up QEMU
if: runner.os == 'Linux' && matrix.os != 'arm-4core-linux'
uses: docker/setup-qemu-action@v2
with:
platforms: all
- name: Build wheels arm64
if: matrix.os == 'arm-4core-linux'
run: /home/runner/.local/bin/pipx run cibuildwheel==2.16.5 --only ${{ matrix.only }}
env:
CIBW_SKIP: ${{ inputs.cibw_skip }}
CIBW_PRERELEASE_PYTHONS: ${{ inputs.cibw_prerelease_pythons }}
CIBW_MUSLLINUX_I686_IMAGE: ghcr.io/datadog/dd-trace-py/pypa_musllinux_1_2_i686:latest
CIBW_BEFORE_ALL: >
if [[ "$(uname -m)-$(uname -i)-$(uname -o | tr '[:upper:]' '[:lower:]')-$(ldd --version 2>&1 | head -n 1 | awk '{print $1}')" != "i686-unknown-linux-musl" ]];
then
curl -sSf https://sh.rustup.rs | sh -s -- -y;
fi
CIBW_BEFORE_ALL_WINDOWS: rustup target add i686-pc-windows-msvc
CIBW_BEFORE_ALL_MACOS: rustup target add aarch64-apple-darwin
CIBW_ENVIRONMENT_LINUX: PATH=$HOME/.cargo/bin:$PATH CMAKE_BUILD_PARALLEL_LEVEL=24
CIBW_REPAIR_WHEEL_COMMAND_LINUX: |
mkdir ./tempwheelhouse &&
unzip -l {wheel} | grep '\.so' &&
auditwheel repair -w ./tempwheelhouse {wheel} &&
for w in ./tempwheelhouse/*.whl; do
python scripts/zip_filter.py $w \*.c \*.cpp \*.cc \*.h \*.hpp \*.pyx
mv $w {dest_dir}
done &&
rm -rf ./tempwheelhouse
CIBW_REPAIR_WHEEL_COMMAND_MACOS: |
zip -d {wheel} \*.c \*.cpp \*.cc \*.h \*.hpp \*.pyx &&
delocate-wheel --require-archs {delocate_archs} -w {dest_dir} -v {wheel}
CIBW_REPAIR_WHEEL_COMMAND_WINDOWS:
choco install -y 7zip &&
7z d -r "{wheel}" *.c *.cpp *.cc *.h *.hpp *.pyx &&
move "{wheel}" "{dest_dir}"
# DEV: Uncomment to debug MacOS
# CIBW_BUILD_VERBOSITY_MACOS: 3
- name: Build wheels
if: matrix.os != 'arm-4core-linux'
uses: pypa/[email protected]
with:
only: ${{ matrix.only }}
env:
CIBW_SKIP: ${{ inputs.cibw_skip }}
CIBW_PRERELEASE_PYTHONS: ${{ inputs.cibw_prerelease_pythons }}
CIBW_MUSLLINUX_I686_IMAGE: ghcr.io/datadog/dd-trace-py/pypa_musllinux_1_2_i686:latest
CIBW_BEFORE_ALL: >
if [[ "$(uname -m)-$(uname -i)-$(uname -o | tr '[:upper:]' '[:lower:]')-$(ldd --version 2>&1 | head -n 1 | awk '{print $1}')" != "i686-unknown-linux-musl" ]];
then
curl -sSf https://sh.rustup.rs | sh -s -- -y;
fi
CIBW_BEFORE_ALL_WINDOWS: rustup target add i686-pc-windows-msvc
CIBW_BEFORE_ALL_MACOS: rustup target add aarch64-apple-darwin
CIBW_ENVIRONMENT_LINUX: PATH=$HOME/.cargo/bin:$PATH CMAKE_BUILD_PARALLEL_LEVEL=24
CIBW_REPAIR_WHEEL_COMMAND_LINUX: |
mkdir ./tempwheelhouse &&
unzip -l {wheel} | grep '\.so' &&
auditwheel repair -w ./tempwheelhouse {wheel} &&
for w in ./tempwheelhouse/*.whl; do
python scripts/zip_filter.py $w \*.c \*.cpp \*.cc \*.h \*.hpp \*.pyx
mv $w {dest_dir}
done &&
rm -rf ./tempwheelhouse
CIBW_REPAIR_WHEEL_COMMAND_MACOS: |
zip -d {wheel} \*.c \*.cpp \*.cc \*.h \*.hpp \*.pyx &&
delocate-wheel --require-archs {delocate_archs} -w {dest_dir} -v {wheel}
CIBW_REPAIR_WHEEL_COMMAND_WINDOWS:
choco install -y 7zip &&
7z d -r "{wheel}" *.c *.cpp *.cc *.h *.hpp *.pyx &&
move "{wheel}" "{dest_dir}"
# DEV: Uncomment to debug MacOS
# CIBW_BUILD_VERBOSITY_MACOS: 3
- if: runner.os != 'Windows'
run: |
echo "ARTIFACT_NAME=${{ matrix.only }}" >> $GITHUB_ENV
- if: runner.os == 'Windows'
run: |
chcp 65001 #set code page to utf-8
echo "ARTIFACT_NAME=${{ matrix.only }}" >> $env:GITHUB_ENV
- uses: actions/upload-artifact@v4
with:
name: wheels-${{ env.ARTIFACT_NAME }}
path: ./wheelhouse/*.whl