Skip to content

Commit 9fff886

Browse files
committed
Merged PR 19680: Support macos builds for ARM64 and X86_64
This PR adds the support to allow building the macos wheels using cibuildwheel for x86_64 and arm64
2 parents 57ee185 + 14db489 commit 9fff886

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+137
-93
lines changed

.github/workflows/main.yml

Lines changed: 36 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# This is a basic workflow to help you get started with Actions
22
name: build
33

4-
# Controls when the action will run.
4+
# Controls when the action will run.
55
on:
66
# Triggers the workflow on push or pull request events but only for the master branch
77
push:
88
branches:
99
- '**'
1010
tags:
11-
- '*.*.*'
11+
- '*.*.*'
1212
pull_request:
1313
branches: [ master ]
1414

@@ -34,7 +34,8 @@ jobs:
3434
${PYLON_DOWNLOAD_URL_BASE_7_2}pylon_7.2.1.25747_x86_64_setup.tar.gz
3535
${PYLON_DOWNLOAD_URL_BASE_7_2}pylon_7.2.1.25747_aarch64_setup.tar.gz
3636
${PYLON_DOWNLOAD_URL_BASE}pylon_6.2.0.21487_armhf_setup.tar.gz
37-
${PYLON_DOWNLOAD_URL_BASE}pylon-6.1.2.19990.zip
37+
${PYLON_DOWNLOAD_URL_BASE}pylon-6.2.0.21487.dmg
38+
${PYLON_DOWNLOAD_ARM64_URL_BASE}pylon_7.3.1.0006_Darwin-arm64_SDK.selfsh
3839
EOF
3940
- uses: actions/cache@v3
4041
id: cache
@@ -49,6 +50,7 @@ jobs:
4950
PYLON_DOWNLOAD_URL_BASE_6_2: ${{ secrets.PYLON_DOWNLOAD_URL_BASE_6_2 }}
5051
PYLON_DOWNLOAD_URL_BASE_6_3: ${{ secrets.PYLON_DOWNLOAD_URL_BASE_6_3 }}
5152
PYLON_DOWNLOAD_URL_BASE_7_2: ${{ secrets.PYLON_DOWNLOAD_URL_BASE_7_2 }}
53+
PYLON_DOWNLOAD_ARM64_URL_BASE: ${{ secrets.PYLON_DOWNLOAD_ARM64_URL_BASE }}
5254
run: |
5355
mkdir pylon-installer && cd pylon-installer
5456
while read line; do
@@ -64,7 +66,7 @@ jobs:
6466
with:
6567
name: pylon-installer
6668
path: pylon-installer
67-
69+
6870
- name: Check for release build
6971
if: startsWith(github.ref, 'refs/tags/')
7072
run: |
@@ -104,12 +106,12 @@ jobs:
104106
ls pylon-installer
105107
docker run --rm --privileged multiarch/qemu-user-static:register --reset
106108
./scripts/build/build-arch.sh --platform-tag $P --abi-tag $A --pylon-dir ./pylon-installer $ARGS
107-
109+
108110
- uses: actions/upload-artifact@v3
109111
with:
110112
name: build-results-${{ matrix.p }}-${{ matrix.a }}
111113
path: dist/*
112-
114+
113115
- name: Upload Release Asset
114116
if: needs.prepare.outputs.is_release_build == 'true'
115117
uses: softprops/action-gh-release@v1
@@ -123,89 +125,57 @@ jobs:
123125
run: |
124126
sudo pip3 install twine
125127
python3 -m twine upload --non-interactive --skip-existing dist/*
126-
127-
128+
129+
128130
build-macos:
129131
needs: prepare
130-
runs-on: macos-10.15
132+
runs-on: macos-11
131133
strategy:
132134
fail-fast: false
133-
matrix:
134-
a: [cp36, cp37, cp38, cp39, cp3_10, cp3_11]
135-
env:
136-
P: macosx-10.15-intel
137-
A: ${{ matrix.a }}
138135
steps:
139136
- uses: actions/checkout@v3
140-
137+
138+
- name: Install Python
139+
uses: actions/setup-python@v4
140+
with:
141+
python-version: "3.6 - 3.11"
142+
141143
- uses: actions/download-artifact@v3
142144
with:
143145
name: pylon-installer
144146
path: pylon-installer
145147

146-
147-
- name: Build and test
148+
- name: Setup pylon
148149
run: |
149-
eval "$(pyenv init -)"
150-
export PATH=$HOME/.pyenv/bin:$PATH
151-
case $A in
152-
cp36)
153-
PYENV_VERSION="3.6"
154-
curl -sSfL -o python.pkg "https://www.python.org/ftp/python/3.6.8/python-3.6.8-macosx10.9.pkg"
155-
;;
156-
cp37)
157-
PYENV_VERSION="3.7"
158-
curl -sSfL -o python.pkg "https://www.python.org/ftp/python/3.7.9/python-3.7.9-macosx10.9.pkg"
159-
;;
160-
cp38)
161-
PYENV_VERSION="3.8"
162-
curl -sSfL -o python.pkg "https://www.python.org/ftp/python/3.8.7/python-3.8.7-macosx10.9.pkg"
163-
;;
164-
cp39)
165-
PYENV_VERSION="3.9"
166-
curl -sSfL -o python.pkg "https://www.python.org/ftp/python/3.9.1/python-3.9.1-macosx10.9.pkg"
167-
;;
168-
cp3_10)
169-
PYENV_VERSION="3.10"
170-
curl -sSfL -o python.pkg "https://www.python.org/ftp/python/3.10.2/python-3.10.2-macos11.pkg"
171-
;;
172-
cp3_11)
173-
PYENV_VERSION="3.11"
174-
curl -sSfL -o python.pkg "https://www.python.org/ftp/python/3.11.0/python-3.11.0-macos11.pkg"
175-
;;
176-
*)
177-
echo "Invalid python version $A"
178-
exit -1
179-
;;
180-
esac
181-
sudo installer -pkg python.pkg -target /
150+
# install x86_64
182151
cd pylon-installer
183-
unzip pylon-*.zip
184152
hdiutil attach pylon-*.dmg
185153
sudo installer -pkg /Volumes/pylon\ *\ Camera\ Software\ Suite/pylon-*.pkg -target /
186154
hdiutil detach /Volumes/pylon\ *\ Camera\ Software\ Suite
187-
brew install swig
188-
cd ${GITHUB_WORKSPACE}
189-
pip3 install numpy
190-
pip3 install wheel
191-
# pylon 6.1 is linked against 10.14
192-
export MACOSX_DEPLOYMENT_TARGET=10.14
193-
python3 setup.py test
194-
python3 setup.py bdist_wheel
195-
155+
# install arm64
156+
chmod a+x pylon_7.3.1.0006_Darwin-arm64_SDK.selfsh
157+
./pylon_7.3.1.0006_Darwin-arm64_SDK.selfsh --accept
158+
mkdir /tmp/pylon_framework
159+
cp -pr pylon/Frameworks/* /tmp/pylon_framework
160+
161+
- name: Build wheels
162+
uses: pypa/[email protected]
163+
env:
164+
PYLON_FRAMEWORK_ARM64: /tmp/pylon_framework
165+
PYLON_FRAMEWORK_X86_64: /Library/Frameworks
166+
196167
- uses: actions/upload-artifact@v3
197168
with:
198-
name: build-results-macosx-${{ matrix.a }}
199-
path: dist/*
200-
169+
path: ./wheelhouse/*.whl
170+
201171
- name: Upload Release Asset
202172
if: needs.prepare.outputs.is_release_build == 'true'
203173
uses: softprops/action-gh-release@v1
204174
env:
205175
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
206176
with:
207-
files: dist/*
208-
177+
files: ./wheelhouse/*.whl
178+
209179
- name: Publish package to (Test)PyPI
210180
if: needs.prepare.outputs.is_release_build == 'true'
211181
run: |
@@ -226,4 +196,4 @@ jobs:
226196
with:
227197
name: pylon-installer
228198

229-
199+

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,6 @@ scripts/reference_types.txt
3535
NodeMap.pfs
3636

3737
#ignore generated html
38-
pypylon.*.html
38+
pypylon.*.html
39+
osx_includes
40+
wheelhouse

README.md

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ You are welcome to post any questions or issues on [GitHub](https://github.com/b
1616
* Install [pylon](https://www.baslerweb.com/pylon)
1717
This is strongly recommended but not mandatory. See [known issues](#known-issues) for further details.
1818
* Install pypylon: ```pip3 install pypylon```
19-
For more installation options and the supported systems please read the [Installation](#installation) paragraph.
19+
For more installation options and the supported systems please read the [Installation](#Installation) paragraph.
2020
* Look at [samples/grab.py](https://github.com/basler/pypylon/blob/master/samples/grab.py) or use the following snippet:
2121

2222
```python
@@ -68,20 +68,22 @@ The following versions are available on pypi:
6868
| Linux x86_64* | x | x | x | x | x | x |
6969
| Linux armv7l* | x | x | x | x | x | x |
7070
| Linux aarch64* | x | x | x | x | x | x |
71-
| Mac OS** | x | x | x | x | x | x |
71+
| macOS x86_64** | x | x | x | x | x | x |
72+
| macOS arm64** | | | x | x | x | x |
7273

7374

7475
> Additional Notes on binary packages:
7576
> * (*) The linux binaries are manylinux_2_28 conformant.
7677
This is roughly equivalent to a minimum glibc version >= 2.28.
7778
:warning: You need at least pip 20.3 to install them.
78-
> * (**) MacOS binaries are built for macOS >= 10.14 (Mojave)
79+
> * (**) macOS binaries are built for macOS >= 11.0 (Big-Sur)
7980
8081
## Installation from Source
81-
Building the pypylon bindings is supported and tested on Windows and Linux.
82+
Building the pypylon bindings is supported and tested on Windows, Linux and macOS
8283

8384
You need a few more things to compile pypylon:
84-
* A compiler for your system (Visual Studio on Windows, gcc on linux)
85+
* An installation of pylon SDK for your platform
86+
* A compiler for your system (Visual Studio on Windows, gcc on linux, xCode commandline tools on macOS)
8587
* Python development files (e.g. `sudo apt install python-dev` on linux)
8688
* [swig](http://www.swig.org) >= 4.0
8789
* For all 64bit platforms you can install the tool via `pip install swig`
@@ -92,6 +94,12 @@ git clone https://github.com/basler/pypylon.git
9294
cd pypylon
9395
pip install .
9496
```
97+
98+
If pylon SDK is not installed in a default location you have to specify the location from the environment
99+
* on Linux: `export PYLON_ROOT=<installation directory of pylon SDK>`
100+
* on macOS: `export PYLON_FRAMEWORK_LOCATION=<framework base folder that contains pylon.framework>`
101+
102+
95103
# Development
96104

97105
Pull requests to pypylon are very welcome. To help you getting started with pypylon improvements, here are some hints:
@@ -106,9 +114,9 @@ After changing pypylon, execute `python setup.py build` and test...
106114
## Running Unit Tests
107115
> NOTE: The unit tests try to import `pypylon....`, so they run against the *installed* version of pypylon.
108116
```console
109-
python -m unittest tests/....
110-
python tests/....
117+
pytest tests/....
111118
```
119+
112120
# Known Issues
113121
* For USB 3.0 cameras to work on Linux, you need to install appropriate udev rules.
114122
The easiest way to get them is to install the official [pylon](http://www.baslerweb.com/pylon) package.

VersionInfo.py

Lines changed: 0 additions & 9 deletions
This file was deleted.

changelog.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
Version [next]
2-
- Date 2023-MM-DD
1+
Version 2.2.0rc1
2+
- Date 2023-06-14
3+
- Integrate macos build for arm64
34
- Fix memory leak if ImageDecompressor is called on invalid data
45
- Call Pylon::PylonTerminate on module unload to free pylon ressources
56
- Fix Warnings from swig and c++ compile steps
67
- Add support for swig installed via pypi
8+
- move tests to pytest format
79

810
Version 2.0.0
911
- Date 2023-05-24

pyproject.toml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
[build-system]
2+
requires = ["setuptools>=42", "swig>=4.0", "wheel"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[tool.cibuildwheel]
6+
build-verbosity = "0"
7+
archs = "x86_64 arm64"
8+
build = "*-macosx_*"
9+
skip = "pp*"
10+
test-requires = "pytest numpy"
11+
12+
[tool.cibuildwheel.macos]
13+
before-all = 'echo "Building: $CIBW_BUILD"'
14+
repair-wheel-command = ""
15+
test-command = [
16+
'''
17+
pytest {project}/tests/genicam_tests {project}/tests/pylon_tests/emulated
18+
'''
19+
]
20+
21+
22+
[[tool.cibuildwheel.overrides]]
23+
select = "*-macosx_arm64"
24+
before-build = [
25+
'''
26+
echo "arm framework"
27+
if [ -z "${PYLON_FRAMEWORK_ARM64}" ]; then
28+
echo "Set PYLON_FRAMEWORK_ARM64 to the directory where pylon.framework for arm64 is installed"
29+
exit -1
30+
fi
31+
'''
32+
]
33+
environment = { PYLON_FRAMEWORK_LOCATION="${PYLON_FRAMEWORK_ARM64}",MACOSX_DEPLOYMENT_TARGET="11.0" }
34+
35+
[[tool.cibuildwheel.overrides]]
36+
select = "*-macosx_x86_64"
37+
before-build = [
38+
'''
39+
echo "intel framework"
40+
if [ -z "${PYLON_FRAMEWORK_X86_64}" ]; then
41+
echo "Set PYLON_FRAMEWORK_X86_64 to the directory where pylon.framework for x86_64 is installed"
42+
echo "default of /Library/Frameworks will be used"
43+
fi
44+
'''
45+
]
46+
environment = { SYSTEM_VERSION_COMPAT="0",PYLON_FRAMEWORK_LOCATION="${PYLON_FRAMEWORK_X86_64}",MACOSX_DEPLOYMENT_TARGET="11.0" }
47+

0 commit comments

Comments
 (0)