Skip to content

Commit 847e868

Browse files
Merge branch 'master' into ocp8
2 parents 34fc062 + 8b9b218 commit 847e868

7 files changed

Lines changed: 364 additions & 2 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: 'Install micromamba'
2+
runs:
3+
using: 'composite'
4+
steps:
5+
- name: install micromamba
6+
if: ${{ !contains(runner.os,'mac')}}
7+
shell: bash
8+
run: "bash <(curl -L micro.mamba.pm/install.sh) && cp ~/.local/bin/micromamba ."
9+
10+
- name: add to path
11+
if: ${{ !contains(runner.os,'mac')}}
12+
shell: bash
13+
run: echo 'PATH="${PATH}:${HOME}"' >> $GITHUB_PATH
14+
15+
- name: 'Install (MacOS)'
16+
if: contains(runner.os,'mac')
17+
shell: bash
18+
run: brew install micromamba
19+
20+
- name: 'Check installation'
21+
shell: bash
22+
run: which micromamba && micromamba info

.github/workflows/bindings.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Build Bindings
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
tags: [ '*' ]
7+
pull_request:
8+
branches: [ master ]
9+
workflow_dispatch:
10+
11+
jobs:
12+
Linux:
13+
uses: ./.github/workflows/build-job.yml
14+
with:
15+
name: Linux
16+
runner_generate: ubuntu-22.04
17+
runner_compile: ubuntu-22.04
18+
platform: Linux
19+
secrets:
20+
ANACONDA_TOKEN: ${{ secrets.ANACONDA_TOKEN }}
21+
22+
Windows:
23+
uses: ./.github/workflows/build-job.yml
24+
with:
25+
name: Windows
26+
# Note: As per your Azure setup, Windows generation runs on Linux first
27+
runner_generate: ubuntu-22.04
28+
runner_compile: windows-latest
29+
platform: Windows
30+
secrets:
31+
ANACONDA_TOKEN: ${{ secrets.ANACONDA_TOKEN }}
32+
33+
OSX:
34+
uses: ./.github/workflows/build-job.yml
35+
with:
36+
name: OSX
37+
runner_generate: macos-15-intel # Using 13 for x86_64 compatibility or latest as needed
38+
runner_compile: macos-15-intel
39+
platform: OSX
40+
secrets:
41+
ANACONDA_TOKEN: ${{ secrets.ANACONDA_TOKEN }}

.github/workflows/build-job.yml

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

OCP_specific.inc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <Standard_Handle.hxx>
33
#include <type_traits>
44
#include <memory>
5+
#include <fmt/format.h>
56

67
namespace py = pybind11;
78

@@ -50,6 +51,13 @@ inline void copy_if_assignable(T& t1, T& t2){
5051

5152
};
5253

54+
template <typename T> inline opencascade::handle<T> cast_pyobject(const py::object &arg){
55+
if(py::isinstance(arg, py::type::of<T>()))
56+
return opencascade::handle(py::cast<T*>(arg));
57+
else
58+
throw py::value_error(fmt::format("Cannot convert the argument to the required type {}", typeid(T).name()));
59+
};
60+
5361
template<typename T, template<typename> typename Deleter = std::default_delete>
5462
struct shared_ptr : public std::shared_ptr<T>{
5563
explicit shared_ptr(T* t = nullptr) : std::shared_ptr<T>(t, Deleter<T>()) {};

conda/meta.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{% set OCCT_VER = "7.9.3" %}
2-
{% set OCP_TWEAK = "0" %}
2+
{% set OCP_TWEAK = "1" %}
33

44
package:
55
name: ocp

environment.devenv.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ dependencies:
2626
{% else %}
2727
- cxx-compiler
2828
- tbb-devel # [win]
29+
- fmt
2930
- pip:
3031
- git+https://github.com/CadQuery/pybind11-stubgen.git
3132
{% endif %}

0 commit comments

Comments
 (0)