Skip to content

Commit b151eee

Browse files
authored
add aarch64 build workflow (#283)
1 parent 9dc550e commit b151eee

File tree

5 files changed

+160
-76
lines changed

5 files changed

+160
-76
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#aarch64-unknown-linux-gnu
2+
TargetCPU :=aarch64
3+
OS :=linux
4+
CXXFLAGS := -O3 -g -fPIC -pedantic
5+
6+
# Standard part
7+
8+
include common.mk

.github/build_scripts/extract_lib.sh

Lines changed: 0 additions & 31 deletions
This file was deleted.
Lines changed: 47 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
#!/bin/bash
2+
set -e
3+
echo $PWD
4+
15
get_absolute_path () {
26
if [[ $1 == /* ]]
37
then
@@ -7,24 +11,52 @@ get_absolute_path () {
711
fi
812
}
913

10-
# set absolute path for directories from args. Default value is current directory
11-
work_dir=$(get_absolute_path $1)
12-
lib_dir=$(get_absolute_path $2)
13-
output_dir=$(get_absolute_path $3)
14+
unpack_wheel () {
15+
local wheel=$1
16+
local unpack_dir=$(mktemp -dt "tempdir.XXX")
17+
local packagename=$(python3 -m wheel unpack $wheel -d $unpack_dir | sed -e 's/.*\/\(.*\)...OK/\1/')
18+
echo $unpack_dir/$packagename
19+
}
20+
21+
extract_lib () {
22+
local wheel=$1
23+
local package_path=$(unpack_wheel $wheel)
24+
echo $package_path/$lib_src_path/$lib_name*.$lib_ext
25+
}
26+
27+
repack_wheel () {
28+
local wheel=$1
29+
local lib_path=$2
30+
local output_dir=$3
31+
local package_path=$(unpack_wheel $wheel)
32+
mkdir -p $package_path/$lib_dest_path
33+
mv $lib_path $package_path/$lib_dest_path/$lib_name.$lib_ext
34+
mkdir -p $output_dir
35+
python3 -m wheel pack $package_path -d $output_dir
36+
}
37+
38+
lib_dest_path=snap7/lib
39+
lib_name=libsnap7
1440

1541
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
16-
libname=libsnap7.so
42+
lib_src_path=python_snap7.libs/
43+
lib_ext=so
44+
ls_pattern=manylinux
1745
else
18-
libname=libsnap7.dylib
46+
lib_src_path=snap7/.dylibs/
47+
lib_ext=dylib
48+
ls_pattern=macosx
1949
fi
2050

21-
cd $work_dir
51+
# set absolute path for directories from args. Default value is current directory
52+
platform_wheel_dir=$(get_absolute_path $1)
53+
pure_wheel_dir=$(get_absolute_path $2)
54+
output_dir=$(get_absolute_path $3)
55+
echo $(ls -la $platform_wheel_dir)
56+
57+
platform_wheel=$(ls $platform_wheel_dir/*.whl | head -n1)
58+
pure_wheel=$(ls $pure_wheel_dir/*.whl | head -n1)
2259

23-
wheel=$(ls *.whl | head -n1)
24-
unpack_dir=$wheel-dir
25-
packagename=$(python3 -m wheel unpack $wheel -d $unpack_dir | sed -e 's/.*\/\(.*\)...OK/\1/')
26-
mkdir -p $unpack_dir/$packagename/snap7/lib
27-
mkdir -p $output_dir
28-
mv $lib_dir/$libname $unpack_dir/$packagename/snap7/lib/$libname
29-
python3 -m wheel pack $unpack_dir/$packagename -d $output_dir
30-
rm -rf $unpack_dir
60+
lib_path=$(extract_lib $platform_wheel)
61+
echo $lib_path
62+
repack_wheel $pure_wheel $lib_path $output_dir
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: build-and-test-wheels
2+
on:
3+
push:
4+
branches: [master]
5+
pull_request:
6+
branches: [master]
7+
env:
8+
snap7-archive-url: https://sourceforge.net/projects/snap7/files/1.4.2/snap7-full-1.4.2.7z/download
9+
jobs:
10+
arm64-build:
11+
name: Build arm64 wheel
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v2
16+
17+
- name: Cache snap7-archive
18+
id: snap7-archive
19+
uses: actions/cache@v2
20+
with:
21+
path: snap7-full-1.4.2.7z
22+
key: ${{ env.snap7-archive-url }}
23+
24+
- name: Get snap7
25+
if: steps.snap7-archive.outputs.cache-hit != 'true'
26+
run: |
27+
wget -O snap7-full-1.4.2.7z --content-disposition -c ${{ env.snap7-archive-url }}
28+
- name: Extract archive
29+
run: 7z x snap7-full-1.4.2.7z
30+
31+
- name: Copy files
32+
run: |
33+
mkdir src
34+
cp snap7-full-1.4.2/release/Wrappers/c-cpp/snap7.h src
35+
cp .github/build_scripts/dummy.c ./
36+
cp .github/build_scripts/aarch64-linux-gnu.mk snap7-full-1.4.2/build/unix/
37+
38+
- name: Set up QEMU
39+
uses: docker/setup-qemu-action@v1
40+
with:
41+
platforms: arm64
42+
43+
- name: Build wheels
44+
uses: joerick/[email protected]
45+
with:
46+
output-dir: wheelhouse
47+
env:
48+
CIBW_ARCHS_LINUX: aarch64
49+
CIBW_BUILD: cp36-*
50+
CIBW_ENVIRONMENT: "BUILD_WHEEL_WITH_EXTENSION=1"
51+
CIBW_BEFORE_ALL_LINUX: cd snap7-full-1.4.2/build/unix/;make -f aarch64-linux-gnu.mk install
52+
53+
- name: Build pure python wheel
54+
run: python3 setup.py bdist_wheel --plat-name=manylinux2014_aarch64
55+
56+
- name: Repack wheel
57+
run: bash .github/build_scripts/repack_wheel.sh wheelhouse dist wheelhouse/${{ runner.os }}
58+
59+
- name: upload artifacts
60+
uses: actions/upload-artifact@v2
61+
with:
62+
name: wheels
63+
path: wheelhouse/*/*.whl
64+
test-wheel:
65+
name: testing wheel
66+
needs: arm64-build
67+
runs-on: ubuntu-latest
68+
strategy:
69+
matrix:
70+
python-version: [3.6, 3.7, 3.8, 3.9]
71+
steps:
72+
- name: Checkout
73+
uses: actions/checkout@v2
74+
- uses: actions/download-artifact@v2
75+
with:
76+
name: wheels
77+
path: wheelhouse
78+
- name: Set up QEMU
79+
uses: docker/setup-qemu-action@v1
80+
with:
81+
platforms: arm64
82+
- name: Run tests in docker:arm64v8
83+
run: |
84+
docker run --rm --interactive -v $PWD/test:/test -v $PWD/wheelhouse:/wheelhouse "arm64v8/python:${{ matrix.python-version }}-buster" /bin/bash -s <<EOF
85+
python -m pip install pytest $(ls wheelhouse/${{ runner.os }}/*.whl)
86+
python -m pytest test/test_server.py test/test_util.py test/test_client.py test/test_mainloop.py test/test_partner.py
87+
EOF

.github/workflows/build-and-test.yml

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ jobs:
1515
uses: actions/checkout@v2
1616

1717
- name: Install choco packages
18-
run: |
19-
choco install 7zip python
20-
choco install --allow-downgrade wget --version 1.20.3.20190531
18+
run: choco install --allow-downgrade wget --version 1.20.3.20190531
2119

2220
- name: Cache snap7-archive
2321
id: snap7-archive
@@ -55,11 +53,6 @@ jobs:
5553
- name: Checkout
5654
uses: actions/checkout@v2
5755

58-
- name: Install Debian packages
59-
run: |
60-
sudo apt-get update -qq
61-
sudo apt-get install -y python3-pip python3-setuptools p7zip
62-
6356
- name: Cache snap7-archive
6457
id: snap7-archive
6558
uses: actions/cache@v2
@@ -69,8 +62,7 @@ jobs:
6962

7063
- name: Get snap7
7164
if: steps.snap7-archive.outputs.cache-hit != 'true'
72-
run: |
73-
wget -O snap7-full-1.4.2.7z --content-disposition -c ${{ env.snap7-archive-url }}
65+
run: wget -O snap7-full-1.4.2.7z --content-disposition -c ${{ env.snap7-archive-url }}
7466

7567
- name: Extract archive
7668
run: 7z x snap7-full-1.4.2.7z
@@ -79,29 +71,25 @@ jobs:
7971
run: |
8072
mkdir src
8173
cp snap7-full-1.4.2/release/Wrappers/c-cpp/snap7.h src
82-
83-
- name: Install cibuildwheel and wheel
84-
run: python3 -m pip install cibuildwheel==1.10.0 wheel --upgrade
85-
74+
cp .github/build_scripts/dummy.c ./
8675
- name: Build pure python wheel
8776
run: python3 setup.py bdist_wheel --plat-name=linux_x86_64
8877

8978
- name: Build platform wheel
90-
run: |
91-
cp .github/build_scripts/dummy.c ./
92-
python3 -m cibuildwheel --output-dir wheelhouse
79+
uses: joerick/[email protected]
80+
with:
81+
output-dir: wheelhouse
9382
env:
9483
CIBW_BUILD: cp36-manylinux_x86_64
9584
CIBW_MANYLINUX_X86_64_IMAGE: manylinux1
9685
CIBW_ENVIRONMENT: "BUILD_WHEEL_WITH_EXTENSION=1"
9786
CIBW_BEFORE_ALL_LINUX: cd snap7-full-1.4.2/build/unix/;make -f x86_64_linux.mk install
9887

9988
- name: Repack wheel
100-
run: |
101-
bash .github/build_scripts/extract_lib.sh wheelhouse dist
102-
bash .github/build_scripts/repack_wheel.sh dist dist wheelhouse/${{ runner.os }}
89+
run: bash .github/build_scripts/repack_wheel.sh wheelhouse dist wheelhouse/${{ runner.os }}
10390

104-
- uses: actions/upload-artifact@v2
91+
- name: upload artifacts
92+
uses: actions/upload-artifact@v2
10593
with:
10694
name: wheels
10795
path: wheelhouse/*/*.whl
@@ -132,6 +120,7 @@ jobs:
132120
run: |
133121
mkdir src
134122
cp snap7-full-1.4.2/release/Wrappers/c-cpp/snap7.h src
123+
cp .github/build_scripts/dummy.c ./
135124
pushd snap7-full-1.4.2/build/osx/
136125
make -f x86_64_osx.mk all
137126
cp ../bin/x86_64-osx/libsnap7.dylib /usr/local/lib
@@ -144,20 +133,19 @@ jobs:
144133
run: python3 setup.py bdist_wheel --plat-name=macosx_10_9_x86_64
145134

146135
- name: Build platform wheel
147-
run: |
148-
cp .github/build_scripts/dummy.c ./
149-
python3 -m cibuildwheel --output-dir wheelhouse
136+
uses: joerick/[email protected]
137+
with:
138+
output-dir: wheelhouse
150139
env:
151140
CIBW_BUILD: cp36-macosx_x86_64
152141
CIBW_BUILD_VERBOSITY: 1
153142
CIBW_ENVIRONMENT: "BUILD_WHEEL_WITH_EXTENSION=1"
154143

155144
- name: Repack wheel
156-
run: |
157-
bash .github/build_scripts/extract_lib.sh wheelhouse dist
158-
bash .github/build_scripts/repack_wheel.sh dist dist wheelhouse/${{ runner.os }}
145+
run: bash .github/build_scripts/repack_wheel.sh wheelhouse dist wheelhouse/${{ runner.os }}
159146

160-
- uses: actions/upload-artifact@v2
147+
- name: upload artifacts
148+
uses: actions/upload-artifact@v2
161149
with:
162150
name: wheels
163151
path: wheelhouse/*/*.whl
@@ -183,7 +171,7 @@ jobs:
183171
run: |
184172
python3 -m pip install --upgrade pip
185173
python3 -m pip install pytest
186-
174+
187175
- uses: actions/download-artifact@v2
188176
with:
189177
name: wheels
@@ -204,7 +192,7 @@ jobs:
204192
- name: Run tests required sudo
205193
if: ${{ runner.os == 'macOS'}}
206194
run: sudo pytest test/test_partner.py
207-
195+
208196
- name: Run tests required sudo
209197
if: ${{ runner.os == 'Windows'}}
210198
run: pytest test/test_partner.py

0 commit comments

Comments
 (0)