-
Notifications
You must be signed in to change notification settings - Fork 1
189 lines (160 loc) · 5.32 KB
/
build_mac_win.yaml
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
name: build macos and windows wheels
on:
push:
branches:
- main
tags:
- 'v*'
pull_request:
branches:
- main
workflow_dispatch:
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]
os: [macos-latest] # , windows-latest
fail-fast: false
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Cache pip packages
uses: actions/cache@v4
with:
path: |
~/.cache/pip
key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Cache cargo crates
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
key: ${{ runner.os }}-cargo-${{ matrix.python-version }}-${{ hashFiles('**/Cargo.lock') }}
- uses: actions/cache@v4
if: matrix.os == 'windows-latest'
with:
path: ./vcpkg
key: vcpkg-openblas
save-always: true
- uses: Swatinem/rust-cache@v2
continue-on-error: true
- name: Install maturin on non-linux (without patchelf)
if: matrix.os != 'ubuntu-latest'
run: pip install maturin
- name: Install OpenBLAS on macOS
if: matrix.os == 'macos-latest'
run: brew install openblas
- name: Set up vcpkg
if: matrix.os == 'windows-latest'
run: |
git clone https://github.com/Microsoft/vcpkg.git --depth 1
cd vcpkg
.\bootstrap-vcpkg.bat
shell: cmd
- name: Install OpenBLAS by vcpkg
if: matrix.os == 'windows-latest'
run: |
./vcpkg/vcpkg.exe install openblas:x64-windows-static-md
- name: Set VCPKG_ROOT environment variable on Windows
if: matrix.os == 'windows-latest'
run: |
setx VCPKG_ROOT "%cd%\vcpkg"
setx PATH "%PATH%;%cd%\vcpkg\installed\x64-windows\bin"
shell: cmd
- name: Run cargo tests
run: cargo test
env:
OPENBLAS_DIR: ${{ matrix.os == 'windows-latest' && '%VCPKG_ROOT%/installed/x64-windows' || '/usr/local/opt/openblas' }}
VCPKG_ROOT: ${{ github.workspace }}/vcpkg
- name: Run cargo clippy
run: cargo clippy --all -- -D warnings
env:
OPENBLAS_DIR: ${{ matrix.os == 'windows-latest' && '%VCPKG_ROOT%/installed/x64-windows' || '/usr/local/opt/openblas' }}
VCPKG_ROOT: ${{ github.workspace }}/vcpkg
- name: Build wheels with maturin on macOS
if: matrix.os == 'macos-latest'
run: |
maturin build --release --out dist
env:
OPENBLAS_DIR: /usr/local/opt/openblas
CARGO_FEATURES: "--no-default-features --features accelerate"
- name: Build wheels with maturin on Windows
if: matrix.os == 'windows-latest'
run: |
maturin build --release --out dist
env:
OPENBLAS_DIR: "%VCPKG_ROOT%/installed/x64-windows"
VCPKG_ROOT: ${{ github.workspace }}/vcpkg
- name: Install the built package
run: |
pip install --find-links dist .
- name: Install pytest
run: |
pip install pytest
- name: Run tests
run: |
pytest
env:
PYTHONPATH: .
- name: Upload wheel artifacts
uses: actions/upload-artifact@v3
with:
name: wheels-${{ matrix.os }}-${{ matrix.python-version }}
path: dist
release:
name: Release and Publish
runs-on: ubuntu-latest
if: ${{ startsWith(github.ref, 'refs/tags/v') || github.event_name == 'workflow_dispatch' }}
needs: build
permissions:
id-token: write
contents: write
attestations: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download artifacts
uses: actions/download-artifact@v3
with:
path: dist
- name: Upload wheels to PyPI
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
run: |
pip install twine
twine upload dist/**/*.whl --skip-existing
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
- name: cargo-release Cache
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
id: cargo_release_cache
uses: actions/cache@v4
with:
path: ~/.cargo/bin/cargo-release
key: ${{ runner.os }}-cargo-release
- name: Install cargo-release
if: ${{ steps.cargo_release_cache.outputs.cache-hit != 'true' && startsWith(github.ref, 'refs/tags/v') }}
run: cargo install cargo-release
- name: cargo login
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
run: cargo login ${{ secrets.CRATES_IO_API_TOKEN }}
- name: Publish crate to crates.io
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
run: |-
cargo release \
publish \
--workspace \
--all-features \
--allow-branch HEAD \
--no-confirm \
--no-verify \
--execute