-
Notifications
You must be signed in to change notification settings - Fork 2
405 lines (366 loc) · 14.7 KB
/
build.yml
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
name: Build RG3
on:
push:
branches:
- main
- dev/*
tags:
- "*"
jobs:
build_rg3:
runs-on: ${{ matrix.config.os }}
strategy:
matrix:
config:
- {
name: "Windows MSVC",
os: windows-2022,
os_id: "windows",
cc: "cl",
cxx: "cl",
boost_toolset: msvc,
cmake_generator: "Visual Studio 17 2022",
llvm_tag: "llvmorg-19.1.4",
python_version: "3.10",
os_version: "2022",
artifact_id: "RG3_Windows",
protobuf_tag: "v29.1"
}
- {
name: "Ubuntu Linux",
os: ubuntu-24.04,
os_id: "linux",
cc: "gcc-13",
cxx: "g++-13",
boost_toolset: gcc,
cmake_generator: "Ninja",
llvm_tag: "llvmorg-19.1.4",
python_version: "3.10",
os_version: "24.04",
artifact_id: "RG3_Linux",
protobuf_tag: "v29.1"
}
- {
name: "macOS",
os: macos-13,
os_id: "macos",
cc: "clang",
cxx: "clang++",
boost_toolset: gcc,
cmake_generator: "Ninja",
llvm_tag: "llvmorg-19.1.4",
python_version: "3.10",
os_version: "13",
artifact_id: "RG3_macOS",
protobuf_tag: "v29.1"
}
steps:
# Download repository with submodules
- name: Checkout
uses: actions/checkout@v3
with:
submodules: "recursive"
# Setup msbuild
- name: Add msbuild to PATH (Windows only)
if: matrix.config.os_id == 'windows'
uses: microsoft/[email protected]
with:
msbuild-architecture: x64
# Setup Ninja
- name: Setup Ninja (Linux)
if: matrix.config.os_id == 'linux'
run: |
sudo apt-get install -y ninja-build gcc-13 g++-13 libboost-all-dev
# Setup Python of specific version
- name: Install Python
if: matrix.config.os_id != 'macos'
id: install-python3
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.config.python_version }}
- name: Setup PyENV and other tools (macOS)
if: matrix.config.os_id == 'macos'
env:
HOMEBREW_NO_AUTO_UPDATE: 1
run: |
brew install pyenv
brew install ninja
pyenv install 3.10-dev -s
echo "Python3_ROOT_DIR=$HOME/.pyenv/versions/3.10-dev" >> $GITHUB_ENV
# ---------------
# Boost
# ---------------
- name: Cache Boost binaries
id: cache-boost-binaries
uses: actions/cache@v3
with:
key: ${{ runner.os }}-boost_1_81_0
path: boost_1_81_0
- name: Download and build Boost (Linux)
if: steps.cache-boost-binaries.outputs.cache-hit != 'true' && matrix.config.os_id == 'linux'
run: |
wget https://boostorg.jfrog.io/artifactory/main/release/1.81.0/source/boost_1_81_0.tar.gz
tar xzf boost_1_81_0.tar.gz
cd boost_1_81_0
./bootstrap.sh --with-libraries=system,filesystem,python --with-python=$(which python3)
./b2 link=static variant=release cxxflags=-fPIC cflags=-fPIC
- name: Download and build Boost (Windows)
if: steps.cache-boost-binaries.outputs.cache-hit != 'true' && matrix.config.os_id == 'windows'
run: |
Invoke-WebRequest -Uri "https://boostorg.jfrog.io/artifactory/main/release/1.81.0/source/boost_1_81_0.tar.gz" -OutFile "boost_1_81_0.tar.gz"
tar xzf boost_1_81_0.tar.gz
cd boost_1_81_0
.\bootstrap.bat --with-libraries=system,filesystem,python
.\b2 link=static variant=release
- name: Download and build Boost (macOS)
if: steps.cache-boost-binaries.outputs.cache-hit != 'true' && matrix.config.os_id == 'macos'
run: |
curl -L -O https://boostorg.jfrog.io/artifactory/main/release/1.81.0/source/boost_1_81_0.tar.gz
tar -xzf boost_1_81_0.tar.gz
cd boost_1_81_0
./bootstrap.sh --with-libraries=python,system,filesystem --with-python=$HOME/.pyenv/versions/3.10-dev/bin/python3 --with-python-version=3.10 --with-python-root=$HOME/.pyenv/versions/3.10-dev
./b2 link=static variant=release cxxflags=-fPIC cflags=-fPIC target-os=darwin architecture=arm+x86
# ---------------
# LLVM
# ---------------
- name: Cache LLVM binaries
id: cache-llvm-binaries
uses: actions/cache@v3
with:
key: "${{ runner.os }}-build-${{ matrix.config.llvm_tag }}"
path: |
llvm_repo/cmake
llvm_repo/build/cmake
llvm_repo/build/MinSizeRel
llvm_repo/build/include
llvm_repo/build/lib
llvm_repo/build/tools/clang/include
llvm_repo/llvm
llvm_repo/clang
# Checkout & Build LLVM (On cache miss - build from sources!)
- name: Checkout LLVM
if: steps.cache-llvm-binaries.outputs.cache-hit != 'true'
uses: actions/checkout@v3
with:
submodules: "recursive"
repository: "llvm/llvm-project"
ref: ${{ matrix.config.llvm_tag }}
path: "llvm_repo"
# Build LLVM
- name: Build LLVM
if: steps.cache-llvm-binaries.outputs.cache-hit != 'true'
working-directory: llvm_repo
env:
CC: ${{ matrix.config.cc }}
CXX: ${{ matrix.config.cxx }}
run: |
mkdir build
cmake -DLLVM_ENABLE_PROJECTS="clang" -DCMAKE_BUILD_TYPE="MinSizeRel" -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DLLVM_ENABLE_ZLIB=OFF -DLLVM_ENABLE_ZSTD=OFF -DLLVM_ENABLE_RTTI=ON -DLLVM_INCLUDE_BENCHMARKS=OFF -DLLVM_INCLUDE_EXAMPLES=OFF -DLLVM_INCLUDE_TESTS=OFF -DLLVM_INCLUDE_TOOLS=ON -DLLVM_TARGETS_TO_BUILD="host" -DLLVM_BUILD_32_BITS=OFF -DLLVM_ENABLE_BINDINGS=OFF -DLLVM_BUILD_DOCS=OFF -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" -S llvm -B build -G "${{ matrix.config.cmake_generator }}"
cd build
cmake --build . --config MinSizeRel
# Save LLVM cache
- name: Save LLVM Cache
if: steps.cache-llvm-binaries.outputs.cache-hit != 'true'
uses: actions/cache/save@v3
with:
key: "${{ runner.os }}-build-${{ matrix.config.llvm_tag }}"
path: |
llvm_repo/cmake
llvm_repo/build/cmake
llvm_repo/build/MinSizeRel
llvm_repo/build/include
llvm_repo/build/lib
llvm_repo/build/tools/clang/include
llvm_repo/llvm
llvm_repo/clang
- name: Checkout Protobuf
uses: actions/checkout@v3
with:
submodules: "recursive"
repository: "protocolbuffers/protobuf"
ref: ${{ matrix.config.protobuf_tag }}
path: "protobuf_repo"
# Protobuf (will use cache later)
- name: Build Protobuf
working-directory: protobuf_repo
env:
CC: ${{ matrix.config.cc }}
CXX: ${{ matrix.config.cxx }}
run: |
mkdir build
mkdir build/install
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded -DBUILD_SHARED_LIBS=OFF -DABSL_PROPAGATE_CXX_STD=ON -DCMAKE_CXX_STANDARD=17 -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_INSTALL_PREFIX=build/install -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" -B build -S . -G "${{ matrix.config.cmake_generator }}"
cmake --build build --config Release
cmake --install build
# Build our project
- name: Build RG3
env:
LLVM_DIR: ${{ github.workspace }}/llvm_repo/build/lib/cmake/llvm
CLANG_DIR: ${{ github.workspace }}/llvm_repo/build/lib/cmake/clang
Boost_ROOT: ${{ github.workspace }}/boost_1_81_0/stage/lib/cmake/Boost-1.81.0
absl_DIR: ${{ github.workspace }}/protobuf_repo/build/install/lib/cmake/absl
utf8_range_DIR: ${{ github.workspace }}/protobuf_repo/build/install/lib/cmake/utf8_range
Protobuf_DIR: ${{ github.workspace }}/protobuf_repo/build/install/lib/cmake/protobuf
Python3_USE_STATIC_LIBS: "TRUE"
CC: ${{ matrix.config.cc }}
CXX: ${{ matrix.config.cxx }}
run: |
mkdir build
cmake -DCMAKE_BUILD_TYPE="MinSizeRel" -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" -B build -G "${{ matrix.config.cmake_generator }}"
cd build
cmake --build . --config MinSizeRel
# Install Clang Latest (for testing env)
- name: Install Clang TestEnv (Windows, Linux)
if: matrix.config.os_id != 'macos'
uses: egor-tensin/setup-clang@v1
with:
version: latest
platform: x64
# Run Unit Tests
- name: RG3 Run unit tests
run: |
cd build
ctest . -C MinSizeRel --verbose --output-on-failure
# Run Python Unit Tests
- name: RG3 Run python unit tests (Windows)
if: matrix.config.os_id == 'windows'
run: |
cp PyBind/rg3py.pyd Tests/PyIntegration
cp PyBind/rg3py.pyi Tests/PyIntegration
cd Tests/PyIntegration
pip install pytest
pytest tests.py
# Run Python Unit Tests (Linux, macOS)
- name: RG3 Run python unit tests (Linux, macOS)
if: matrix.config.os_id == 'linux' || matrix.config.os_id == 'macos'
run: |
cp PyBind/rg3py.so Tests/PyIntegration
cp PyBind/rg3py.pyi Tests/PyIntegration
cd Tests/PyIntegration
pip install pytest
pytest tests.py
# Make dist folder with pyd & pyi files.
- name: Create distribution package (Windows)
if: matrix.config.os_id == 'windows'
run: |
mkdir dist
mv PyBind/rg3py.pyi dist
mv PyBind/rg3py.pyd dist
- name: Create distribution package (not Windows)
if: matrix.config.os_id != 'windows'
run: |
mkdir dist
mv PyBind/rg3py.pyi dist
mv PyBind/rg3py.so dist
# Upload artifacts
- name: Upload RG3 artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.config.artifact_id }}
path: dist
public_release_template:
name: Create release and public PyPI packages
needs: [build_rg3]
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
steps:
# --------------------------------------------------------------------
# Create GitHub release
# --------------------------------------------------------------------
- name: Get version
id: get_version
run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//}
- name: Create release
id: release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.get_version.outputs.VERSION }}
release_name: ${{ steps.get_version.outputs.VERSION }}
draft: true
prerelease: ${{ contains(github.ref, '-pre') }}
- name: Download all artifact
uses: actions/download-artifact@v4
- name: Package artifact for release
run: zip -r RG3_Release_v${{ steps.get_version.outputs.VERSION }}.zip *
- name: Upload release asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.release.outputs.upload_url }}
asset_path: ./RG3_Release_v${{ steps.get_version.outputs.VERSION }}.zip
asset_name: RG3_Release_v${{ steps.get_version.outputs.VERSION }}.zip
asset_content_type: application/zip
# --------------------------------------------------------------------
# Publish PyPI libs
# --------------------------------------------------------------------
# Clone whole project with all submodules
- name: Checkout
uses: actions/checkout@v3
with:
submodules: "recursive"
# Install any python 3.x to run Extensions/setup.pys
- name: Install Python
id: install-python3
uses: actions/setup-python@v5
with:
python-version: '3.x'
# Install build tools
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
# Download all available artifacts
- name: Download artifacts
uses: actions/download-artifact@v4
- name: Build WHL for Linux
env:
RG3_DEPLOY_VERSION: ${{ steps.get_version.outputs.VERSION }}
RG3_DEPLOY_OS: 'linux'
run: |
mv RG3_Linux/rg3py.so Extension/rg3py
mv RG3_Linux/rg3py.pyi Extension/rg3py
cd Extension
python setup.py bdist_wheel --plat-name manylinux_2_28_x86_64
rm build/lib/rg3py/rg3py.so
rm build/lib/rg3py/rg3py.pyi
cd ..
rm Extension/rg3py/rg3py.so
rm Extension/rg3py/rg3py.pyi
- name: Build WHL for Windows
env:
RG3_DEPLOY_VERSION: ${{ steps.get_version.outputs.VERSION }}
RG3_DEPLOY_OS: 'windows'
run: |
mv RG3_Windows/rg3py.pyd Extension/rg3py
mv RG3_Windows/rg3py.pyi Extension/rg3py
cd Extension
python setup.py bdist_wheel --plat-name win_amd64
rm build/lib/rg3py/rg3py.pyd
rm build/lib/rg3py/rg3py.pyi
cd ..
rm Extension/rg3py/rg3py.pyd
rm Extension/rg3py/rg3py.pyi
- name: Build WHL for macOS
env:
RG3_DEPLOY_VERSION: ${{ steps.get_version.outputs.VERSION }}
RG3_DEPLOY_OS: 'macos'
run: |
mv RG3_macOS/rg3py.so Extension/rg3py
mv RG3_macOS/rg3py.pyi Extension/rg3py
cd Extension
python setup.py bdist_wheel --plat-name macosx_14_0_universal2
rm build/lib/rg3py/rg3py.so
rm build/lib/rg3py/rg3py.pyi
cd ..
rm Extension/rg3py/rg3py.so
rm Extension/rg3py/rg3py.pyi
- name: Upload wheels
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
working-directory: Extension
run: |
twine upload dist/*