|
| 1 | +name: Build Bindings Logic |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + name: |
| 7 | + required: true |
| 8 | + type: string |
| 9 | + runner_generate: |
| 10 | + required: true |
| 11 | + type: string |
| 12 | + runner_compile: |
| 13 | + required: true |
| 14 | + type: string |
| 15 | + platform: |
| 16 | + required: true |
| 17 | + type: string |
| 18 | + secrets: |
| 19 | + ANACONDA_TOKEN: |
| 20 | + required: false |
| 21 | + |
| 22 | +jobs: |
| 23 | + # ----------------------------------------------------------------------------- |
| 24 | + # PHASE 1: Generate Bindings (Python wrapper generation) |
| 25 | + # ----------------------------------------------------------------------------- |
| 26 | + generate: |
| 27 | + name: Generate ${{ inputs.name }} |
| 28 | + runs-on: ${{ inputs.runner_generate }} |
| 29 | + timeout-minutes: 360 |
| 30 | + outputs: |
| 31 | + output_dir: ${{ steps.conf.outputs.OUTPUT }} |
| 32 | + |
| 33 | + steps: |
| 34 | + - uses: actions/checkout@v4 |
| 35 | + with: |
| 36 | + submodules: true |
| 37 | + |
| 38 | + # --- Mac SDK Hack --- |
| 39 | + - name: SDK install and symlink (Mac) |
| 40 | + if: contains(inputs.runner_generate, 'mac') |
| 41 | + run: | |
| 42 | + curl -L -O https://github.com/phracker/MacOSX-SDKs/releases/download/11.3/MacOSX11.3.sdk.tar.xz |
| 43 | + sudo mkdir -p /opt |
| 44 | + sudo tar -xf MacOSX11.3.sdk.tar.xz -C /opt |
| 45 | + sudo mkdir -p /opt/usr/local/ |
| 46 | + sudo ln -s /opt/MacOSX11.3.sdk/usr/include /opt/usr/local/include |
| 47 | + sudo ln -s /opt/MacOSX11.3.sdk/System/Library/Frameworks/OpenGL.framework/Headers /usr/local/include/OpenGL |
| 48 | +
|
| 49 | + # --- Setup Environment --- |
| 50 | + - uses: mamba-org/setup-micromamba@v2 |
| 51 | + with: |
| 52 | + # REMOVE: environment-file: environment.devenv.yml |
| 53 | + environment-name: placeholder |
| 54 | + # cache-environment: true |
| 55 | + # Create a minimal environment with mamba-devenv |
| 56 | + create-args: >- |
| 57 | + -c conda-forge python=3.12 conda-devenv mamba |
| 58 | +
|
| 59 | + - name: Prepare conda environment (mamba-devenv) |
| 60 | + shell: bash -l {0} |
| 61 | + run: | |
| 62 | + export CONDA_DEVENV_ENV_MANAGER=mamba |
| 63 | + mamba create -n cpp-py-bindgen |
| 64 | + mamba-devenv -f environment.devenv.yml |
| 65 | +
|
| 66 | + - name: Read output dir |
| 67 | + id: conf |
| 68 | + shell: bash -l {0} |
| 69 | + run: | |
| 70 | + micromamba activate cpp-py-bindgen |
| 71 | + OUTPUT=`python -c'import toml; print(toml.load("ocp.toml")["output_folder"])'` |
| 72 | + echo "OUTPUT=$OUTPUT" >> $GITHUB_OUTPUT |
| 73 | +
|
| 74 | + - name: Restore OCP_src cache |
| 75 | + id: cache-ocp-src-restore |
| 76 | + uses: actions/cache/restore@v4 |
| 77 | + with: |
| 78 | + path: ${{ steps.conf.outputs.OUTPUT }} |
| 79 | + key: OCP-src-${{ inputs.platform }}- |
| 80 | + |
| 81 | + # --- Generation Logic --- |
| 82 | + |
| 83 | + # Windows Special Case (Running on Linux targeting Windows) |
| 84 | + - name: Generate (Windows on Linux) |
| 85 | + if: inputs.platform == 'Windows' && steps.cache-ocp-src-restore.outputs.cache-hit != 'true' |
| 86 | + shell: bash -l {0} |
| 87 | + run: | |
| 88 | + micromamba create --yes --platform win-64 --no-deps --prefix ./occt occt=7.9.2 |
| 89 | + micromamba activate cpp-py-bindgen |
| 90 | + cmake -S . -B . -G Ninja \ |
| 91 | + -DPython_ROOT_DIR=$CONDA_PREFIX \ |
| 92 | + -DPython3_ROOT_DIR=$CONDA_PREFIX \ |
| 93 | + -DPython_FIND_VIRTUALENV=ONLY \ |
| 94 | + -DPython3_FIND_VIRTUALENV=ONLY \ |
| 95 | + -DOCCT_LIB_DIR=./occt/Library/bin/ \ |
| 96 | + -DPLATFORM=Windows |
| 97 | + cmake --build . -- -v |
| 98 | + ls -lRht |
| 99 | +
|
| 100 | + # Standard Case (Linux/Mac) |
| 101 | + - name: Generate (Standard) |
| 102 | + if: inputs.platform != 'Windows' && steps.cache-ocp-src-restore.outputs.cache-hit != 'true' |
| 103 | + shell: bash -l {0} |
| 104 | + run: | |
| 105 | + micromamba activate cpp-py-bindgen |
| 106 | + cmake -S . -B . -G Ninja \ |
| 107 | + -DPython_ROOT_DIR=$CONDA_PREFIX \ |
| 108 | + -DPython3_ROOT_DIR=$CONDA_PREFIX \ |
| 109 | + -DPython_FIND_VIRTUALENV=ONLY \ |
| 110 | + -DPython3_FIND_VIRTUALENV=ONLY |
| 111 | + cmake --build . |
| 112 | + ls -lRht |
| 113 | +
|
| 114 | + - name: Cache OCP_src |
| 115 | + id: cache-ocp-src-save |
| 116 | + uses: actions/cache/save@v4 |
| 117 | + with: |
| 118 | + path: ${{ steps.conf.outputs.OUTPUT }} |
| 119 | + key: ${{ steps.cache-ocp-src-restore.outputs.cache-primary-key }} |
| 120 | + |
| 121 | + - name: Copy pkl output |
| 122 | + if: steps.cache-ocp-src-restore.outputs.cache-hit != 'true' |
| 123 | + shell: bash -l {0} |
| 124 | + run: | |
| 125 | + mkdir -p ${{ steps.conf.outputs.OUTPUT }}_pkl |
| 126 | + cp *.pkl ${{ steps.conf.outputs.OUTPUT }}_pkl/ |
| 127 | +
|
| 128 | + # --- Artifact Upload --- |
| 129 | + - name: Upload Sources |
| 130 | + # if: steps.cache-ocp-src-restore.outputs.cache-hit != 'true' |
| 131 | + uses: actions/upload-artifact@v4 |
| 132 | + with: |
| 133 | + name: OCP_src_${{ inputs.platform }} |
| 134 | + path: ${{ steps.conf.outputs.OUTPUT }} |
| 135 | + |
| 136 | + - name: Upload Pickles |
| 137 | + if: steps.cache-ocp-src-restore.outputs.cache-hit != 'true' |
| 138 | + uses: actions/upload-artifact@v4 |
| 139 | + with: |
| 140 | + name: OCP_pkl_${{ inputs.platform }} |
| 141 | + path: ${{ steps.conf.outputs.OUTPUT }}_pkl |
| 142 | + |
| 143 | + # ----------------------------------------------------------------------------- |
| 144 | + # PHASE 2: Compile (Matrix) |
| 145 | + # ----------------------------------------------------------------------------- |
| 146 | + compile: |
| 147 | + needs: generate |
| 148 | + name: Compile ${{ inputs.name }} (3.${{ matrix.py_min }}) |
| 149 | + runs-on: ${{ inputs.runner_compile }} |
| 150 | + # timeout-minutes: 360 |
| 151 | + strategy: |
| 152 | + fail-fast: false |
| 153 | + matrix: |
| 154 | + py_min: [10, 11, 12, 13] |
| 155 | + |
| 156 | + env: |
| 157 | + OCP_src: OCP_src_${{ inputs.platform }} |
| 158 | + n_cores: 2 |
| 159 | + PYTHON_VERSION: 3.${{ matrix.py_min }} |
| 160 | + STAGE: "compile" |
| 161 | + ANACONDA_TOKEN: ${{ secrets.ANACONDA_TOKEN }} |
| 162 | + |
| 163 | + steps: |
| 164 | + - uses: actions/checkout@v4 |
| 165 | + with: |
| 166 | + submodules: true |
| 167 | + |
| 168 | + # rely on source artifact?? |
| 169 | + # - name: Restore OCP_src cache |
| 170 | + # id: cache-ocp-src-restore |
| 171 | + # uses: actions/cache/restore@v4 |
| 172 | + # with: |
| 173 | + # path: ${{ steps.conf.outputs.OUTPUT }} |
| 174 | + # key: OCP-src-${{ inputs.platform }}- |
| 175 | + |
| 176 | + # --- Download Artifacts --- |
| 177 | + - name: Download Source Artifact |
| 178 | + uses: actions/download-artifact@v4 |
| 179 | + with: |
| 180 | + name: OCP_src_${{ inputs.platform }} |
| 181 | + path: ../${{ env.OCP_src }} |
| 182 | + |
| 183 | + # --- Mac SDK Hack (Compile Phase) --- |
| 184 | + - name: SDK install (Mac) |
| 185 | + if: contains(inputs.runner_compile, 'mac') |
| 186 | + run: | |
| 187 | + curl -L -O https://github.com/phracker/MacOSX-SDKs/releases/download/11.3/MacOSX10.15.sdk.tar.xz |
| 188 | + sudo mkdir -p /opt |
| 189 | + sudo tar -xf MacOSX10.15.sdk.tar.xz -C /opt |
| 190 | +
|
| 191 | + # --- Setup Environment --- |
| 192 | + - uses: mamba-org/setup-micromamba@v2 |
| 193 | + with: |
| 194 | + # micromamba-version: '1.5.8-0' |
| 195 | + # REMOVE: environment-file: environment.devenv.yml |
| 196 | + environment-name: placeholder |
| 197 | + # Create a minimal environment with mamba-devenv |
| 198 | + create-args: >- |
| 199 | + -c conda-forge python=${{ env.PYTHON_VERSION }} conda-devenv mamba |
| 200 | +
|
| 201 | + - name: Prepare conda environment |
| 202 | + shell: bash -l {0} |
| 203 | + run: | |
| 204 | + export CONDA_DEVENV_ENV_MANAGER=mamba |
| 205 | + mamba create -n cpp-py-bindgen |
| 206 | + mamba-devenv -f environment.devenv.yml |
| 207 | +
|
| 208 | + # --- Compilation --- |
| 209 | + |
| 210 | + # Ubuntu Compile |
| 211 | + - name: Compile (Ubuntu) |
| 212 | + if: contains(inputs.runner_compile, 'ubuntu') |
| 213 | + shell: bash -l {0} |
| 214 | + run: | |
| 215 | + micromamba activate cpp-py-bindgen |
| 216 | + cmake -B build -S "../${OCP_src}" -G Ninja -DCMAKE_BUILD_TYPE=Release |
| 217 | + cmake --build build -j 2 -- -k 0 |
| 218 | + rm -rf build/CMakeFiles |
| 219 | +
|
| 220 | + # Mac Compile |
| 221 | + - name: Compile (Mac) |
| 222 | + if: contains(inputs.runner_compile, 'mac') |
| 223 | + shell: bash -l {0} |
| 224 | + run: | |
| 225 | + micromamba activate cpp-py-bindgen |
| 226 | + cmake -B build -S "../${OCP_src}" -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_OSX_SYSROOT=/opt/MacOSX10.15.sdk/ |
| 227 | + cmake --build build -j 2 -- -k 0 |
| 228 | + rm -rf build/CMakeFiles |
| 229 | +
|
| 230 | + # Windows Compile |
| 231 | + - name: Compile (Windows) |
| 232 | + if: contains(inputs.runner_compile, 'windows') |
| 233 | + shell: powershell |
| 234 | + run: | |
| 235 | + # Note: PowerShell interpolation of env vars is different |
| 236 | + 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 |
| 237 | + micromamba run -n cpp-py-bindgen cmake --build build -j 1 -- -v -k 0 |
| 238 | + micromamba run -n cpp-py-bindgen cmake -E rm -rf build\CMakeFiles |
| 239 | + env: |
| 240 | + CXX: "cl.exe" |
| 241 | + |
| 242 | + - name: Upload Compilation Artifacts |
| 243 | + uses: actions/upload-artifact@v4 |
| 244 | + with: |
| 245 | + name: OCP_${{ inputs.platform }}_py3${{ matrix.py_min }} |
| 246 | + path: build |
| 247 | + |
| 248 | + # --- Stubs & Test --- |
| 249 | + - name: Generate stubs |
| 250 | + shell: bash -l {0} |
| 251 | + run: | |
| 252 | + micromamba activate cpp-py-bindgen |
| 253 | + cd build |
| 254 | + python -m pybind11_stubgen -o . OCP |
| 255 | + rm -rf OCP-stubs/setup.py OCP-stubs/__pycache__ OCP-stubs/MANIFEST.in |
| 256 | + cp -r "../../$(OCP_src)" ../upload |
| 257 | + cp -r OCP-stubs ../upload/ |
| 258 | +
|
| 259 | + - name: Upload Stubs Artifacts |
| 260 | + uses: actions/upload-artifact@v4 |
| 261 | + with: |
| 262 | + name: OCP_src_stubs_${{ inputs.platform }}_py3${{ matrix.py_min }} |
| 263 | + path: upload |
| 264 | + |
| 265 | + - name: Test Import |
| 266 | + shell: bash -l {0} |
| 267 | + run: | |
| 268 | + micromamba activate cpp-py-bindgen |
| 269 | + cd build |
| 270 | + # LD_DEBUG is linux specific, keeping it safe for others |
| 271 | + if [[ "${{ inputs.platform }}" == "Linux" ]]; then |
| 272 | + LD_DEBUG=libs python -c"import OCP" |
| 273 | + else |
| 274 | + python -c"import OCP" |
| 275 | + fi |
| 276 | +
|
| 277 | + # --- Conda Packaging --- |
| 278 | + - name: Build Conda Package |
| 279 | + shell: bash -l {0} |
| 280 | + env: |
| 281 | + BUILD_STRING: "1" |
| 282 | + TOKEN: ${{ secrets.ANACONDA_TOKEN }} |
| 283 | + run: | |
| 284 | + # Install build tools in a fresh env |
| 285 | + micromamba create -n build -y -c conda-forge python=3.11 liblief=0.14.1 conda-build anaconda-client |
| 286 | + micromamba activate build |
| 287 | + |
| 288 | + # Determine flags based on event |
| 289 | + if [[ "${{ github.event_name }}" == "pull_request" ]]; then |
| 290 | + echo "Building for PR..." |
| 291 | + conda build -c conda-forge --override-channels conda |
| 292 | + else |
| 293 | + echo "Building and Uploading..." |
| 294 | + conda build --token $TOKEN --user cadquery --label dev -c conda-forge --override-channels conda |
| 295 | + fi |
0 commit comments