Skip to content

Commit dc444f4

Browse files
authored
Merge pull request #592 from Farama-Foundation/macos-workflows-update
Update workflows to support building macOS Apple Silicon (arm64) wheels
2 parents 04a0d6a + 74b2e53 commit dc444f4

10 files changed

+234
-136
lines changed

Diff for: .github/workflows/build-and-test-wheels.yml

+183
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
name: Build and test Python wheels and make PyPI release
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
paths:
7+
- '.github/workflows/build-and-test-wheels.yml'
8+
- 'include/**'
9+
- 'scripts/**'
10+
- 'src/**'
11+
- 'CMakeLists.txt'
12+
- 'setup.py'
13+
- 'pyproject.toml'
14+
branches: [master]
15+
release:
16+
types: [published]
17+
18+
jobs:
19+
build_wheels:
20+
name: Build wheels on ${{ matrix.os }}
21+
runs-on: ${{ matrix.os }}
22+
strategy:
23+
matrix:
24+
os: [ubuntu-22.04, macos-12, macos-14]
25+
fail-fast: false
26+
27+
steps:
28+
- uses: actions/checkout@v4
29+
with:
30+
submodules: recursive
31+
32+
- name: Report OS
33+
run: |
34+
echo ${{ matrix.os }}
35+
echo ${{ runner.os }}
36+
uname -p
37+
38+
- name: Set up QEMU
39+
if: runner.os == 'Linux'
40+
uses: docker/setup-qemu-action@v2
41+
with:
42+
platforms: all
43+
44+
- name: Build manylinux wheels
45+
if: matrix.os == 'ubuntu-22.04'
46+
uses: pypa/[email protected]
47+
env:
48+
# Configure cibuildwheel to build native archs, and some emulated ones
49+
CIBW_ARCHS_LINUX: x86_64 aarch64
50+
CIBW_BUILD_VERBOSITY: 1
51+
52+
- name: Build macOS Intel wheels
53+
if: matrix.os == 'macos-12'
54+
uses: pypa/[email protected]
55+
env:
56+
CIBW_ARCHS_MACOS: x86_64
57+
CIBW_ENVIRONMENT_MACOS: VIZDOOM_MACOS_ARCH=x86_64 HOMEBREW_NO_AUTO_UPDATE=1 HOMEBREW_NO_INSTALL_CLEANUP=1 MACOSX_DEPLOYMENT_TARGET=12.0
58+
CIBW_BUILD_VERBOSITY: 1
59+
60+
- name: Build macOS Apple Silicon wheels
61+
if: matrix.os == 'macos-14'
62+
uses: pypa/[email protected]
63+
env:
64+
CIBW_ARCHS_MACOS: arm64
65+
CIBW_ENVIRONMENT_MACOS: VIZDOOM_MACOS_ARCH=arm64 HOMEBREW_NO_AUTO_UPDATE=1 HOMEBREW_NO_INSTALL_CLEANUP=1 MACOSX_DEPLOYMENT_TARGET=14.0
66+
CIBW_BUILD_VERBOSITY: 1
67+
68+
- name: Report built wheels
69+
run: |
70+
ls -l ./wheelhouse/*.whl
71+
72+
- name: Upload artifacts
73+
uses: actions/upload-artifact@v3
74+
with:
75+
path: ./wheelhouse/*.whl
76+
77+
test_wheels:
78+
name: Test wheels on ${{ matrix.os }}
79+
needs: [build_wheels]
80+
runs-on: ${{ matrix.os }}
81+
strategy:
82+
matrix:
83+
os: [ubuntu-22.04, ubuntu-24.04, macos-12, macos-13, macos-14]
84+
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
85+
fail-fast: false
86+
87+
steps:
88+
- uses: actions/checkout@v4
89+
with:
90+
submodules: recursive
91+
92+
- name: Set up Python ${{ matrix.python-version }} environment
93+
uses: actions/setup-python@v4
94+
with:
95+
python-version: ${{ matrix.python-version }}
96+
97+
- name: Download all dists
98+
uses: actions/download-artifact@v3
99+
with:
100+
# Unpacks default artifact into dist/
101+
# If `name: artifact` is omitted, the action will create extra parent dir
102+
name: artifact
103+
path: dist
104+
105+
- name: Report dist directory
106+
run: ls -l dist
107+
108+
- name: Report environment
109+
run: |
110+
echo ${{ matrix.os }}
111+
echo ${{ runner.os }}
112+
uname -p
113+
python -c "import sys; print(sys.version)"
114+
115+
- name: Install macOS Intel wheel on ${{ matrix.os }}
116+
if: matrix.os == 'macos-12' || matrix.os == 'macos-13'
117+
run: |
118+
export PYTHON_VERSION=$(python -c "import sys; print(f'{sys.version_info.major}{sys.version_info.minor}')")
119+
export WHEEL=$(ls dist/vizdoom*cp${PYTHON_VERSION}*macosx*x86_64.whl)
120+
python -m pip install ${WHEEL}[test]
121+
122+
- name: Install macOS Apple Silicon wheel on ${{ matrix.os }}
123+
if: matrix.os == 'macos-14'
124+
run: |
125+
export PYTHON_VERSION=$(python -c "import sys; print(f'{sys.version_info.major}{sys.version_info.minor}')")
126+
export WHEEL=$(ls dist/vizdoom*cp${PYTHON_VERSION}*macosx*arm64.whl)
127+
python -m pip install ${WHEEL}[test]
128+
129+
- name: Install manylinux wheel on ${{ matrix.os }}
130+
if: matrix.os == 'ubuntu-22.04' || matrix.os == 'ubuntu-24.04'
131+
run: |
132+
export PYTHON_VERSION=$(python -c "import sys; print(f'{sys.version_info.major}{sys.version_info.minor}')")
133+
export WHEEL=$(ls dist/vizdoom*cp${PYTHON_VERSION}*manylinux*x86_64.whl)
134+
python -m pip install ${WHEEL}[test]
135+
136+
- name: Import check
137+
run: python -c "import vizdoom"
138+
139+
- name: Run tests
140+
# Skip tests on macOS with Apple Silicon, because they are slow (TODO: investigate)
141+
if: matrix.os != 'macos-14'
142+
run: pytest tests
143+
144+
build_sdist:
145+
name: Build source distribution
146+
runs-on: ubuntu-latest
147+
steps:
148+
- uses: actions/checkout@v4
149+
with:
150+
submodules: recursive
151+
152+
- name: Build sdist
153+
run: pipx run build --sdist
154+
155+
- name: Upload sdist
156+
uses: actions/upload-artifact@v3
157+
with:
158+
path: dist/*.tar.gz
159+
160+
upload_pypi:
161+
name: Upload to PyPI
162+
needs: [build_wheels, build_sdist, test_wheels]
163+
runs-on: ubuntu-latest
164+
environment: pypi
165+
permissions:
166+
id-token: write
167+
if: github.event_name == 'release' && github.event.action == 'published'
168+
steps:
169+
- name: Download all dists
170+
uses: actions/download-artifact@v3
171+
with:
172+
# Unpacks default artifact into dist/
173+
# If `name: artifact` is omitted, the action will create extra parent dir
174+
name: artifact
175+
path: dist
176+
177+
- name: Publish to PyPI
178+
uses: pypa/gh-action-pypi-publish@release/v1
179+
with:
180+
password: ${{ secrets.PYPI_API_TOKEN }}
181+
# To test:
182+
# with:
183+
# repository_url: https://test.pypi.org/legacy/

Diff for: .github/workflows/build-and-test-windows-wheels.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ on:
1414
branches: [master]
1515
pull_request:
1616
paths:
17-
- '.github/workflows/**'
17+
- '.github/workflows/build-and-test-windows-wheels.yml'
1818
- 'include/**'
1919
- 'scripts/**'
2020
- 'src/**'

Diff for: .github/workflows/build-and-test.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ on:
1414
branches: [master]
1515
pull_request:
1616
paths:
17-
- '.github/workflows/**'
17+
- '.github/workflows/build-and-test.yml'
1818
- 'include/**'
1919
- 'scripts/**'
2020
- 'src/**'
@@ -76,4 +76,6 @@ jobs:
7676
run: python -c "import vizdoom"
7777

7878
- name: Run tests
79+
# Skip tests on macOS with Apple Silicon, because they are slow (TODO: investigate)
80+
if: matrix.os != 'macos-14'
7981
run: pytest tests

Diff for: .github/workflows/build-wheels.yml

-115
This file was deleted.

Diff for: CMakeLists.txt

+9-6
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,15 @@ if(APPLE)
6969
set(CMAKE_MACOSX_RPATH ON)
7070
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -fvisibility-inlines-hidden")
7171

72-
if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "arm64")
73-
set(CMAKE_OSX_ARCHITECTURES "arm64" CACHE INTERNAL "" FORCE)
74-
message(STATUS "Apple Silicon detected, building for arm64")
75-
else()
76-
set(CMAKE_OSX_ARCHITECTURES "x86_64" CACHE INTERNAL "" FORCE)
77-
message(STATUS "Intel CPU detected, building for x86_64")
72+
if(CMAKE_APPLE_SILICON_PROCESSOR MATCHES "")
73+
message(STATUS "CMAKE_APPLE_SILICON_PROCESSOR not set")
74+
if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "arm64")
75+
set(CMAKE_OSX_ARCHITECTURES "arm64" CACHE INTERNAL "" FORCE)
76+
message(STATUS "Apple Silicon detected, building for arm64")
77+
else()
78+
set(CMAKE_OSX_ARCHITECTURES "x86_64" CACHE INTERNAL "" FORCE)
79+
message(STATUS "Intel CPU detected, building for x86_64")
80+
endif()
7881
endif()
7982
endif(APPLE)
8083

Diff for: README.md

+11-5
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ or
7070

7171
## Python quick start
7272

73-
#### At the moment ViZDoom does not work with numpy 2.0. Using ViZDoom with numpy 2.0 results in a silent bug - all the state buffers containing all data. At the moment, please use ViZDoom with numpy 1.26.
73+
#### Versions 1.2.3 and below does not work correctly with numpy 2.0+. Please upgrade ViZDoom to the newest version or downgrade numpy to the last 1.21+ version.
7474

7575
### Linux
7676
To install the latest release of ViZDoom, just run:
@@ -85,12 +85,18 @@ ViZDoom requires a C++11 compiler, CMake 3.12+, Boost 1.54+ SDL2, OpenAL (option
8585

8686

8787
### macOS
88-
To install the latest release of ViZDoom, just run (it may take a few minutes as it will build ViZDoom from source on M1/M2 chips):
88+
To install the latest release of ViZDoom, just run:
8989
```sh
90-
brew install cmake boost sdl2 openal-soft
9190
pip install vizdoom
9291
```
9392
Both Intel and Apple Silicon CPUs are supported.
93+
Pre-build wheels are available for Intel macOS 12.0+ and Apple Silicon macOS 14.0+.
94+
95+
If Python wheel is not available for your platform (Python version <3.8, older macOS version), pip will try to install (build) ViZDoom from the source.
96+
In this case, install the required dependencies using Homebrew:
97+
```sh
98+
brew install cmake boost sdl2
99+
```
94100
We recommend using at least macOS High Sierra 10.13+ with Python 3.8+.
95101
On Apple Silicon (M1, M2, and M3), make sure you are using Python/Pip for Apple Silicon.
96102

@@ -101,7 +107,7 @@ To install the latest release of ViZDoom, just run:
101107
pip install vizdoom
102108
```
103109
At the moment, only x86-64 architecture is supported on Windows.
104-
Wheels are available for Python 3.8+ on Windows.
110+
Wheels are available for Python 3.9+ on Windows.
105111

106112
Please note that the Windows version is not as well-tested as Linux and macOS versions.
107113
It can be used for development and testing but if you want to conduct serious (time and resource-extensive) experiments on Windows,
@@ -124,7 +130,7 @@ See [documentation](https://github.com/Farama-Foundation/ViZDoom/blob/master/doc
124130
- [Python](https://github.com/Farama-Foundation/ViZDoom/blob/master/examples/python) (contain learning examples implemented in PyTorch, TensorFlow, and Theano)
125131
- [C++](https://github.com/Farama-Foundation/ViZDoom/blob/master/examples/c%2B%2B)
126132

127-
Python examples are currently the richest, so we recommend looking at them, even if you plan to use C++.
133+
Python examples are currently the richest, so we recommend looking at them, even if you plan to use C++.
128134
The API is almost identical between the languages, with the only difference being that Python uses snake_case and C++ camelCase for methods and functions.
129135

130136

0 commit comments

Comments
 (0)