-
Notifications
You must be signed in to change notification settings - Fork 42
289 lines (255 loc) · 9.86 KB
/
build-job.yml
File metadata and controls
289 lines (255 loc) · 9.86 KB
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
name: Build Bindings Logic
on:
workflow_call:
inputs:
name:
required: true
type: string
runner_generate:
required: true
type: string
runner_compile:
required: true
type: string
platform:
required: true
type: string
secrets:
ANACONDA_TOKEN:
required: false
jobs:
# -----------------------------------------------------------------------------
# PHASE 1: Generate Bindings (Python wrapper generation)
# -----------------------------------------------------------------------------
generate:
name: Generate ${{ inputs.name }}
runs-on: ${{ inputs.runner_generate }}
timeout-minutes: 360
outputs:
output_dir: ${{ steps.conf.outputs.OUTPUT }}
steps:
- uses: actions/checkout@v4
with:
submodules: true
- uses: ./.github/actions/micromamba
# --- Mac SDK Hack ---
- name: SDK install and symlink (Mac)
if: contains(inputs.runner_generate, 'mac')
run: |
curl -L -O https://github.com/phracker/MacOSX-SDKs/releases/download/11.3/MacOSX11.3.sdk.tar.xz
sudo mkdir -p /opt
sudo tar -xf MacOSX11.3.sdk.tar.xz -C /opt
sudo mkdir -p /opt/usr/local/
sudo ln -s /opt/MacOSX11.3.sdk/usr/include /opt/usr/local/include
sudo ln -s /opt/MacOSX11.3.sdk/System/Library/Frameworks/OpenGL.framework/Headers /usr/local/include/OpenGL
# --- Setup Environment ---
- name: install conda-devenv
run: micromamba install mamba conda-devenv
- name: Prepare conda environment (mamba-devenv)
run: |
export CONDA_DEVENV_ENV_MANAGER=mamba
micromamba create -n cpp-py-bindgen
micromamba run mamba-devenv -f environment.devenv.yml
- name: Read output dir
id: conf
run: |
OUTPUT=`micromamba run -n cpp-py-bindgen python -c'import toml; print(toml.load("ocp.toml")["output_folder"])'`
echo "OUTPUT=$OUTPUT" >> $GITHUB_OUTPUT
- name: Restore OCP_src cache
id: cache-ocp-src-restore
uses: actions/cache/restore@v4
with:
path: ${{ steps.conf.outputs.OUTPUT }}
key: OCP-src-${{ inputs.platform }}-
# --- Generation Logic ---
# Windows Special Case (Running on Linux targeting Windows)
- name: Generate (Windows on Linux)
if: inputs.platform == 'Windows' && steps.cache-ocp-src-restore.outputs.cache-hit != 'true'
run: |
micromamba create --yes --platform win-64 --no-deps --prefix ./occt occt=7.9.2
micromamba run -n cpp-py-bindgen cmake -S . -B . -G Ninja \
-DPython_ROOT_DIR=$CONDA_PREFIX \
-DPython3_ROOT_DIR=$CONDA_PREFIX \
-DPython_FIND_VIRTUALENV=ONLY \
-DPython3_FIND_VIRTUALENV=ONLY \
-DOCCT_LIB_DIR=./occt/Library/bin/ \
-DPLATFORM=Windows
cmake --build . -- -v
ls -lRht
# Standard Case (Linux/Mac)
- name: Generate (Standard)
if: inputs.platform != 'Windows' && steps.cache-ocp-src-restore.outputs.cache-hit != 'true'
run: |
micromamba run -n cpp-py-bindgen cmake -S . -B . -G Ninja \
-DPython_ROOT_DIR=$CONDA_PREFIX \
-DPython3_ROOT_DIR=$CONDA_PREFIX \
-DPython_FIND_VIRTUALENV=ONLY \
-DPython3_FIND_VIRTUALENV=ONLY
cmake --build .
ls -lRht
- name: Cache OCP_src
id: cache-ocp-src-save
uses: actions/cache/save@v4
with:
path: ${{ steps.conf.outputs.OUTPUT }}
key: ${{ steps.cache-ocp-src-restore.outputs.cache-primary-key }}
- name: Copy pkl output
if: steps.cache-ocp-src-restore.outputs.cache-hit != 'true'
shell: bash -l {0}
run: |
mkdir -p ${{ steps.conf.outputs.OUTPUT }}_pkl
cp *.pkl ${{ steps.conf.outputs.OUTPUT }}_pkl/
# --- Artifact Upload ---
- name: Upload Sources
# if: steps.cache-ocp-src-restore.outputs.cache-hit != 'true'
uses: actions/upload-artifact@v4
with:
name: OCP_src_${{ inputs.platform }}
path: ${{ steps.conf.outputs.OUTPUT }}
- name: Upload Pickles
if: steps.cache-ocp-src-restore.outputs.cache-hit != 'true'
uses: actions/upload-artifact@v4
with:
name: OCP_pkl_${{ inputs.platform }}
path: ${{ steps.conf.outputs.OUTPUT }}_pkl
# -----------------------------------------------------------------------------
# PHASE 2: Compile (Matrix)
# -----------------------------------------------------------------------------
compile:
needs: generate
name: Compile ${{ inputs.name }} (3.${{ matrix.py_min }})
runs-on: ${{ inputs.runner_compile }}
# timeout-minutes: 360
strategy:
fail-fast: false
matrix:
py_min: [10, 11, 12, 13]
env:
OCP_src: OCP_src_${{ inputs.platform }}
n_cores: 2
PYTHON_VERSION: 3.${{ matrix.py_min }}
STAGE: "compile"
ANACONDA_TOKEN: ${{ secrets.ANACONDA_TOKEN }}
steps:
- uses: actions/checkout@v4
with:
submodules: true
# rely on source artifact??
# - name: Restore OCP_src cache
# id: cache-ocp-src-restore
# uses: actions/cache/restore@v4
# with:
# path: ${{ steps.conf.outputs.OUTPUT }}
# key: OCP-src-${{ inputs.platform }}-
# --- Download Artifacts ---
- name: Download Source Artifact
uses: actions/download-artifact@v4
with:
name: OCP_src_${{ inputs.platform }}
path: ../${{ env.OCP_src }}
# --- Mac SDK Hack (Compile Phase) ---
- name: SDK install (Mac)
if: contains(inputs.runner_compile, 'mac')
run: |
curl -L -O https://github.com/phracker/MacOSX-SDKs/releases/download/11.3/MacOSX10.15.sdk.tar.xz
sudo mkdir -p /opt
sudo tar -xf MacOSX10.15.sdk.tar.xz -C /opt
# --- Setup Environment ---
- uses: mamba-org/setup-micromamba@v3
env:
ACTIONS_STEP_DEBUG: true
with:
# micromamba-version: '1.5.8-0'
# REMOVE: environment-file: environment.devenv.yml
environment-name: placeholder
# Create a minimal environment with mamba-devenv
init-shell: bash
create-args: >-
python=${{ env.PYTHON_VERSION }}
conda-devenv
mamba
- name: Prepare conda environment
shell: bash -l {0}
run: |
export CONDA_DEVENV_ENV_MANAGER=mamba
mamba create -n cpp-py-bindgen
mamba-devenv -f environment.devenv.yml
# --- Compilation ---
# Ubuntu Compile
- name: Compile (Ubuntu)
if: contains(inputs.runner_compile, 'ubuntu')
shell: bash -l {0}
run: |
micromamba activate cpp-py-bindgen
cmake -B build -S "../${OCP_src}" -G Ninja -DCMAKE_BUILD_TYPE=Release
cmake --build build -j 2 -- -k 0
rm -rf build/CMakeFiles
# Mac Compile
- name: Compile (Mac)
if: contains(inputs.runner_compile, 'mac')
shell: bash -l {0}
run: |
micromamba activate cpp-py-bindgen
cmake -B build -S "../${OCP_src}" -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_OSX_SYSROOT=/opt/MacOSX10.15.sdk/
cmake --build build -j 2 -- -k 0
rm -rf build/CMakeFiles
# Windows Compile
- name: Compile (Windows)
if: contains(inputs.runner_compile, 'windows')
shell: powershell
run: |
# Note: PowerShell interpolation of env vars is different
micromamba run -n cpp-py-bindgen cmake -B build -S "../$env:OCP_src" -G Ninja -DCMAKE_BUILD_TYPE=Release -DPython3_FIND_STRATEGY=LOCATION -DPython3_ROOT_DIR=$env:CONDA_PREFIX -DCMAKE_LINKER=lld-link.exe
micromamba run -n cpp-py-bindgen cmake --build build -j 1 -- -v -k 0
micromamba run -n cpp-py-bindgen cmake -E rm -rf build\CMakeFiles
env:
CXX: "cl.exe"
- name: Upload Compilation Artifacts
uses: actions/upload-artifact@v4
with:
name: OCP_${{ inputs.platform }}_py3${{ matrix.py_min }}
path: build
# --- Stubs & Test ---
- name: Generate stubs
shell: bash -l {0}
run: |
micromamba activate cpp-py-bindgen
cd build
python -m pybind11_stubgen -o . OCP
rm -rf OCP-stubs/setup.py OCP-stubs/__pycache__ OCP-stubs/MANIFEST.in
cp -r "../../$(OCP_src)" ../upload
cp -r OCP-stubs ../upload/
- name: Upload Stubs Artifacts
uses: actions/upload-artifact@v4
with:
name: OCP_src_stubs_${{ inputs.platform }}_py3${{ matrix.py_min }}
path: upload
- name: Test Import
shell: bash -l {0}
run: |
micromamba activate cpp-py-bindgen
cd build
# LD_DEBUG is linux specific, keeping it safe for others
if [[ "${{ inputs.platform }}" == "Linux" ]]; then
LD_DEBUG=libs python -c"import OCP"
else
python -c"import OCP"
fi
# --- Conda Packaging ---
- name: Build Conda Package
shell: bash -l {0}
env:
BUILD_STRING: "1"
TOKEN: ${{ secrets.ANACONDA_TOKEN }}
run: |
# Install build tools in a fresh env
micromamba create -n build -y -c conda-forge python=3.11 liblief=0.14.1 conda-build anaconda-client
micromamba activate build
# Determine flags based on event
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
echo "Building for PR..."
conda build -c conda-forge --override-channels conda
else
echo "Building and Uploading..."
conda build --token $TOKEN --user cadquery --label dev -c conda-forge --override-channels conda
fi