Skip to content

Commit d68afa9

Browse files
authored
Merge pull request #16 from ZhuoZhuoCrayon/feat/linux_arm
feat: 支持 Linux ARM 架构 (closed #15)
2 parents fbd1cd2 + 640785c commit d68afa9

File tree

3 files changed

+140
-25
lines changed

3 files changed

+140
-25
lines changed

.github/workflows/build-docker-images.yml

+18-5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ permissions:
1717
contents: read
1818
packages: write
1919

20+
env:
21+
TONGSUO_VERSION: 8.3.2
22+
2023
jobs:
2124
# Build containers for x86
2225
build:
@@ -25,22 +28,32 @@ jobs:
2528
fail-fast: false
2629
matrix:
2730
IMAGE:
28-
- {TAG_NAME: "tongsuopy-manylinux2014:x86_64", DOCKERFILE_PATH: "infra", BUILD_ARGS: "--build-arg PYCA_RELEASE=manylinux2014_x86_64", RUNNER: "ubuntu-latest"}
29-
- {TAG_NAME: "tongsuopy-manylinux_2_24:x86_64", DOCKERFILE_PATH: "infra", BUILD_ARGS: "--build-arg PYCA_RELEASE=manylinux_2_24_x86_64", RUNNER: "ubuntu-latest"}
30-
- {TAG_NAME: "tongsuopy-manylinux_2_28:x86_64", DOCKERFILE_PATH: "infra", BUILD_ARGS: "--build-arg PYCA_RELEASE=manylinux_2_28_x86_64", RUNNER: "ubuntu-latest"}
31-
- {TAG_NAME: "tongsuopy-musllinux_1_1:x86_64", DOCKERFILE_PATH: "infra", BUILD_ARGS: "--build-arg PYCA_RELEASE=musllinux_1_1_x86_64", RUNNER: "ubuntu-latest"}
31+
- {TAG_NAME: "tongsuopy-manylinux2014:x86_64", DOCKERFILE_PATH: "infra", PYCA_RELEASE: "manylinux2014_x86_64", RUNNER: "ubuntu-latest"}
32+
- {TAG_NAME: "tongsuopy-manylinux_2_24:x86_64", DOCKERFILE_PATH: "infra", PYCA_RELEASE: "manylinux_2_24_x86_64", RUNNER: "ubuntu-latest"}
33+
- {TAG_NAME: "tongsuopy-manylinux_2_28:x86_64", DOCKERFILE_PATH: "infra", PYCA_RELEASE: "manylinux_2_28_x86_64", RUNNER: "ubuntu-latest"}
34+
- {TAG_NAME: "tongsuopy-musllinux_1_1:x86_64", DOCKERFILE_PATH: "infra", PYCA_RELEASE: "musllinux_1_1_x86_64", RUNNER: "ubuntu-latest"}
35+
- { TAG_NAME: "tongsuopy-manylinux2014:aarch64", DOCKERFILE_PATH: "infra", PYCA_RELEASE: "manylinux2014_aarch64", RUNNER: "ubuntu-latest" }
36+
- { TAG_NAME: "tongsuopy-manylinux_2_24:aarch64", DOCKERFILE_PATH: "infra", PYCA_RELEASE: "manylinux_2_24_aarch64", RUNNER: "ubuntu-latest" }
37+
- { TAG_NAME: "tongsuopy-manylinux_2_28:aarch64", DOCKERFILE_PATH: "infra", PYCA_RELEASE: "manylinux_2_28_aarch64", RUNNER: "ubuntu-latest" }
38+
- { TAG_NAME: "tongsuopy-musllinux_1_1:aarch64", DOCKERFILE_PATH: "infra", PYCA_RELEASE: "musllinux_1_1_aarch64", RUNNER: "ubuntu-latest" }
3239

3340
name: "${{ matrix.IMAGE.TAG_NAME }}"
3441
steps:
3542
- uses: actions/[email protected]
43+
# add --platform linux/amd64 to fix:
44+
# The requested image's platform (linux/arm64/v8) does not match the detected host platform (linux/amd64) and no specific platform was requested
45+
- id: set-up-qemu
46+
name: Set up QEMU
47+
uses: docker/setup-qemu-action@v2
3648
# Pull the previous image, but if it fails return true anyway.
3749
# Sometimes we add new docker images and if they've never been pushed
3850
# they can't be pulled.
3951
- name: Pull existing image
4052
run: docker pull ghcr.io/tongsuo-project/${{ matrix.IMAGE.TAG_NAME }} || true
4153
if: github.event_name != 'schedule' && github.event_name != 'workflow_dispatch'
4254
- name: Build image
43-
run: docker build --pull --cache-from ghcr.io/tongsuo-project/${{ matrix.IMAGE.TAG_NAME }} -t ghcr.io/tongsuo-project/${{ matrix.IMAGE.TAG_NAME }} ${{ matrix.IMAGE.DOCKERFILE_PATH }} ${{ matrix.IMAGE.BUILD_ARGS }}
55+
run: |
56+
docker build --pull --cache-from ghcr.io/tongsuo-project/${{ matrix.IMAGE.TAG_NAME }} -t ghcr.io/tongsuo-project/${{ matrix.IMAGE.TAG_NAME }} --build-arg PYCA_RELEASE=${{ matrix.IMAGE.PYCA_RELEASE }} --build-arg TONGSUO_VERSION=${TONGSUO_VERSION} --build-arg TONGSUO_HOME=/opt/tongsuo${TONGSUO_VERSION} ${{ matrix.IMAGE.DOCKERFILE_PATH }}
4457
- name: Login to docker
4558
run: 'docker login -u "$DOCKER_USERNAME" -p "$DOCKER_PASSWORD" ghcr.io'
4659
env:

.github/workflows/release-wheel.yml

+97-17
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ on:
88
description: The version to build
99

1010
env:
11+
PYPI_NAME: tongsuopy
1112
TONGSUO_VERSION: 8.3.2
13+
INNER_WORKSPACE: /workspace
14+
INNER_BUILD_DIR: /build
1215

1316
jobs:
1417
sdist:
@@ -62,19 +65,6 @@ jobs:
6265
- uses: actions/[email protected]
6366
with:
6467
name: tongsuopy-sdist
65-
- name: Set TONGSUO_HOME
66-
shell: bash
67-
run: echo "TONGSUO_HOME=${GITHUB_WORKSPACE}/tongsuo${TONGSUO_VERSION}" >> $GITHUB_ENV
68-
- name: Build Tongsuo
69-
working-directory: ${{ runner.temp }}
70-
run: |
71-
wget "https://github.com/Tongsuo-Project/Tongsuo/archive/refs/tags/${TONGSUO_VERSION}.tar.gz"
72-
tar zxf "${TONGSUO_VERSION}.tar.gz"
73-
cd "Tongsuo-${TONGSUO_VERSION}"
74-
./config no-shared enable-ntls --release --prefix=${TONGSUO_HOME}
75-
make -s -j4
76-
make install_sw
77-
cd -
7868
- run: /opt/python/${{ matrix.PYTHON.VERSION }}/bin/python -m venv .venv
7969
- name: Install Python dependencies
8070
run: .venv/bin/pip install -U pip wheel cffi
@@ -97,7 +87,7 @@ jobs:
9787
else
9888
exit 0
9989
fi
100-
- run: .venv/bin/pip install tongsuopy --no-index -f wheelhouse/
90+
- run: .venv/bin/pip install ${{ env.PYPI_NAME }} --no-index -f wheelhouse/
10191
- run: |
10292
.venv/bin/python -c "from tongsuopy.backends.tongsuo.backend import backend;print('Loaded: ' + backend.openssl_version_text());print('Linked Against: ' + backend._ffi.string(backend._lib.OPENSSL_VERSION_TEXT).decode('ascii'))"
10393
- run: mkdir tongsuopy-wheelhouse
@@ -108,7 +98,97 @@ jobs:
10898
password: ${{ secrets.PYPI_API_TOKEN }}
10999
packages_dir: tongsuopy-wheelhouse/
110100
print_hash: true
111-
# repository_url: https://test.pypi.org/legacy/
101+
102+
manylinux-aarch64:
103+
needs: [ sdist ]
104+
runs-on: ubuntu-latest
105+
strategy:
106+
fail-fast: false
107+
matrix:
108+
PYTHON:
109+
- { VERSION: "cp36-cp36m", ABI_VERSION: 'cp36' }
110+
- { VERSION: "pp38-pypy38_pp73" }
111+
- { VERSION: "pp39-pypy39_pp73" }
112+
MANYLINUX:
113+
- { NAME: "manylinux2014_aarch64", CONTAINER: "tongsuopy-manylinux2014:aarch64" }
114+
- { NAME: "manylinux_2_24_aarch64", CONTAINER: "tongsuopy-manylinux_2_24:aarch64" }
115+
- { NAME: "manylinux_2_28_aarch64", CONTAINER: "tongsuopy-manylinux_2_28:aarch64" }
116+
- { NAME: "musllinux_1_1_aarch64", CONTAINER: "tongsuopy-musllinux_1_1:aarch64" }
117+
exclude:
118+
# There are no readily available PyPy distributions
119+
- PYTHON: { VERSION: "pp38-pypy38_pp73" }
120+
MANYLINUX: { NAME: "musllinux_1_1_aarch64", CONTAINER: "tongsuopy-musllinux_1_1:aarch64" }
121+
- PYTHON: { VERSION: "pp39-pypy39_pp73" }
122+
MANYLINUX: { NAME: "musllinux_1_1_aarch64", CONTAINER: "tongsuopy-musllinux_1_1:aarch64" }
123+
124+
125+
name: "${{ matrix.PYTHON.VERSION }} for ${{ matrix.MANYLINUX.NAME }}"
126+
steps:
127+
- uses: actions/[email protected]
128+
with:
129+
name: tongsuopy-sdist
130+
path: ${{ github.workspace }}
131+
132+
- uses: uraimo/run-on-arch-action@v2
133+
name: Build artifact
134+
with:
135+
arch: none
136+
distro: none
137+
base_image: --platform=linux/arm64 ghcr.io/tongsuo-project/${{ matrix.MANYLINUX.CONTAINER }}
138+
139+
# Not required, but speeds up builds
140+
githubToken: ${{ secrets.PAT }}
141+
142+
# Mount the artifacts directory as /artifacts in the container
143+
dockerRunArgs: |
144+
--volume "${{ github.workspace }}:${{ env.INNER_WORKSPACE }}"
145+
--volume "${{ runner.temp }}:${{ env.INNER_BUILD_DIR }}"
146+
147+
# Pass some environment variables to the container
148+
env: |
149+
INNER_WORKSPACE: "${{ env.INNER_WORKSPACE }}"
150+
INNER_BUILD_DIR: "${{ env.INNER_BUILD_DIR }}"
151+
PYTHON_VERSION: "${{ matrix.PYTHON.VERSION }}"
152+
PYTHON_ABI_VERSION: "${{ matrix.PYTHON.ABI_VERSION }}"
153+
MANYLINUX_NAME: "${{ matrix.MANYLINUX.NAME }}"
154+
155+
# Produce a binary artifact and place it in the mounted volume
156+
run: |
157+
cd ${INNER_BUILD_DIR}
158+
/opt/python/${PYTHON_VERSION}/bin/python -m venv .venv
159+
.venv/bin/pip install -U pip wheel cffi
160+
161+
cd ${INNER_WORKSPACE}
162+
tar zxvf tongsuopy*.tar.gz && rm tongsuopy*.tar.gz && mkdir tmpwheelhouse
163+
PY_LIMITED_API=""
164+
if [ -n "${PYTHON_ABI_VERSION}" ]; then
165+
PY_LIMITED_API="--py-limited-api=${PYTHON_ABI_VERSION}"
166+
fi
167+
cd tongsuopy*
168+
${INNER_BUILD_DIR}/.venv/bin/python setup.py bdist_wheel ${PY_LIMITED_API} && mv dist/tongsuopy*.whl ../tmpwheelhouse
169+
170+
cd ${INNER_WORKSPACE}
171+
auditwheel repair --plat ${MANYLINUX_NAME} tmpwheelhouse/tongsuopy*.whl -w wheelhouse/
172+
unzip wheelhouse/*.whl -d execstack.check
173+
results=$(readelf -lW execstack.check/tongsuopy/backends/*.so)
174+
count=$(echo "$results" | grep -c 'GNU_STACK.*[R ][W ]E' || true)
175+
echo "count -> ${count}"
176+
if [ "$count" -ne 0 ]; then
177+
exit 1
178+
fi
179+
180+
cd ${INNER_WORKSPACE}
181+
${INNER_BUILD_DIR}/.venv/bin/pip install ${{ env.PYPI_NAME }} --no-index -f wheelhouse/
182+
${INNER_BUILD_DIR}/.venv/bin/python -c "from tongsuopy.backends.tongsuo.backend import backend;print('Loaded: ' + backend.openssl_version_text());print('Linked Against: ' + backend._ffi.string(backend._lib.OPENSSL_VERSION_TEXT).decode('ascii'))"
183+
mkdir tongsuopy-wheelhouse
184+
mv wheelhouse/tongsuopy*.whl tongsuopy-wheelhouse/
185+
186+
- name: Publish tongsuopy to PyPI
187+
uses: pypa/gh-action-pypi-publish@release/v1
188+
with:
189+
password: ${{ secrets.PYPI_API_TOKEN }}
190+
packages_dir: ${{ github.workspace }}/tongsuopy-wheelhouse/
191+
print_hash: true
112192

113193
macos:
114194
needs: [sdist]
@@ -191,7 +271,7 @@ jobs:
191271
MACOSX_DEPLOYMENT_TARGET: ${{ matrix.PYTHON.DEPLOYMENT_TARGET }}
192272
ARCHFLAGS: ${{ matrix.PYTHON.ARCHFLAGS }}
193273
_PYTHON_HOST_PLATFORM: ${{ matrix.PYTHON._PYTHON_HOST_PLATFORM }}
194-
- run: venv/bin/pip install -f wheelhouse --no-index tongsuopy
274+
- run: venv/bin/pip install -f wheelhouse --no-index ${{ env.PYPI_NAME }}
195275
- name: Show the wheel's minimum macOS SDK and architectures
196276
run: |
197277
find venv/lib/*/site-packages/tongsuopy/backends -name '*.so' -exec vtool -show {} \;
@@ -270,7 +350,7 @@ jobs:
270350
- run: tar zxvf tongsuopy*.tar.gz && mkdir wheelhouse
271351
shell: bash
272352
- run: cd tongsuopy* && python setup.py bdist_wheel --py-limited-api=${{ matrix.PYTHON.ABI_VERSION }} && mv dist/tongsuopy*.whl ../wheelhouse
273-
- run: pip install -f wheelhouse --no-index tongsuopy
353+
- run: pip install -f wheelhouse --no-index ${{ env.PYPI_NAME }}
274354
- name: Print the OpenSSL we built and linked against
275355
run: |
276356
python -c "from tongsuopy.backends.tongsuo.backend import backend;print('Loaded: ' + backend.openssl_version_text());print('Linked Against: ' + backend._ffi.string(backend._lib.OPENSSL_VERSION_TEXT).decode('ascii'))"

infra/Dockerfile

+25-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
ARG PYCA_RELEASE
2+
23
FROM quay.io/pypa/${PYCA_RELEASE}
3-
ARG PYCA_RELEASE
44
MAINTAINER Tongsuo Project Authors
5+
ARG PYCA_RELEASE
6+
ARG TONGSUO_HOME
7+
ARG TONGSUO_VERSION
8+
ENV TONGSUO_HOME=${TONGSUO_HOME}
9+
ENV TONGSUO_VERSION=${TONGSUO_VERSION}
510
WORKDIR /root
611
RUN \
712
if [ $(uname -m) = "x86_64" ]; \
@@ -12,6 +17,9 @@ RUN \
1217
rm -rf /var/cache/yum; \
1318
elif stat /etc/debian_version 1>&2 2>/dev/null; then \
1419
export DEBIAN_FRONTEND=noninteractive && \
20+
sed -i s/deb.debian.org/archive.debian.org/g /etc/apt/sources.list && \
21+
sed -i 's|security.debian.org|archive.debian.org/|g' /etc/apt/sources.list && \
22+
sed -i '/stretch-updates/d' /etc/apt/sources.list && \
1523
apt-get update -qq && \
1624
apt-get install -qq -y --no-install-recommends wget prelink && \
1725
apt-get clean -qq && \
@@ -27,13 +35,16 @@ RUN \
2735
if [ $(uname -m) = "aarch64" ]; \
2836
then \
2937
if stat /etc/redhat-release 1>&2 2>/dev/null; then \
30-
yum -y install libffi-devel perl-IPC-Cmd && \
38+
yum -y install libffi-devel perl-IPC-Cmd wget && \
3139
yum -y clean all && \
3240
rm -rf /var/cache/yum; \
3341
elif stat /etc/debian_version 1>&2 2>/dev/null; then \
3442
export DEBIAN_FRONTEND=noninteractive && \
43+
sed -i s/deb.debian.org/archive.debian.org/g /etc/apt/sources.list && \
44+
sed -i 's|security.debian.org|archive.debian.org/|g' /etc/apt/sources.list && \
45+
sed -i '/stretch-updates/d' /etc/apt/sources.list && \
3546
apt-get update -qq && \
36-
apt-get install -qq -y --no-install-recommends libffi-dev && \
47+
apt-get install -qq -y --no-install-recommends libffi-dev wget prelink && \
3748
apt-get clean -qq && \
3849
rm -rf /var/lib/apt/lists/*; \
3950
else \
@@ -45,3 +56,14 @@ RUN \
4556
apk add --no-cache gcompat; \
4657
fi; \
4758
fi
59+
60+
# build tongsuo
61+
RUN set -ex && \
62+
wget "https://github.com/Tongsuo-Project/Tongsuo/archive/refs/tags/${TONGSUO_VERSION}.tar.gz" && \
63+
tar zxf "${TONGSUO_VERSION}.tar.gz"
64+
65+
RUN set -ex && \
66+
cd "Tongsuo-${TONGSUO_VERSION}" && \
67+
./config no-shared enable-ntls --release --prefix=${TONGSUO_HOME} && \
68+
make -s -j4 && \
69+
make install_sw

0 commit comments

Comments
 (0)