Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
34 changes: 2 additions & 32 deletions .github/workflows/build-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ jobs:

- uses: ./.github/actions/micromamba

# --- Mac SDK Hack ---
- name: SDK install and symlink (Mac)
if: contains(inputs.runner_generate, 'mac')
run: |
Expand All @@ -63,19 +62,10 @@ jobs:
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'
if: inputs.platform == 'Windows'
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 \
Expand All @@ -90,7 +80,7 @@ jobs:

# Standard Case (Linux/Mac)
- name: Generate (Standard)
if: inputs.platform != 'Windows' && steps.cache-ocp-src-restore.outputs.cache-hit != 'true'
if: inputs.platform != 'Windows'
run: |
micromamba run -n cpp-py-bindgen cmake -S . -B . -G Ninja \
-DPython_ROOT_DIR=$CONDA_PREFIX \
Expand All @@ -100,30 +90,18 @@ jobs:
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 }}
Expand Down Expand Up @@ -154,14 +132,6 @@ jobs:
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
Expand Down
239 changes: 139 additions & 100 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,131 +1,170 @@
cmake_minimum_required( VERSION 3.29 )
project( OCP )

set( N_PROC 2 CACHE STRING "Number of processes used for generating code")
set( DLL_EXT dll CACHE STRING "DLL suffix")
set( MSVC_VER 16 CACHE STRING "MSVC version to download for win generation")
set( OCCT_LIB_DIR CACHE PATH "Location of OCCT sos/dlls")

find_package( OpenGL REQUIRED )
find_package( LLVM REQUIRED )
find_package( VTK REQUIRED
COMPONENTS
CommonCore
WrappingPythonCore
RenderingCore
RenderingOpenGL2
CommonDataModel
CommonExecutionModel
freetype
)
cmake_minimum_required(VERSION 3.29)
project(OCP)

set(N_PROC
2
CACHE STRING "Number of processes used for generating code")
set(DLL_EXT
dll
CACHE STRING "DLL suffix")
set(MSVC_VER
16
CACHE STRING "MSVC version to download for win generation")
set(OCCT_LIB_DIR CACHE PATH "Location of OCCT sos/dlls")

find_package(OpenGL REQUIRED)
find_package(LLVM REQUIRED)
find_package(
VTK REQUIRED
COMPONENTS CommonCore
WrappingPythonCore
RenderingCore
RenderingOpenGL2
CommonDataModel
CommonExecutionModel
freetype)

message(STATUS "VTK ${VTK_VERSION} found")

find_package( RapidJSON REQUIRED )
find_package( Clang REQUIRED )
find_package(RapidJSON REQUIRED)
find_package(Clang REQUIRED)

set( Python_FIND_VIRTUALENV FIRST )
find_package( Python COMPONENTS Interpreter Development REQUIRED )
set(Python_FIND_VIRTUALENV FIRST)
find_package(
Python
COMPONENTS Interpreter Development
REQUIRED)

# find OCCT and dump symbols
if( EXISTS ${OCCT_LIB_DIR})
file(GLOB occt_libs LIST_DIRECTORIES false ${OCCT_LIB_DIR}/*.${DLL_EXT} )
message(STATUS Found OCCT libs: ${occt_libs})
if(EXISTS ${OCCT_LIB_DIR})
file(
GLOB occt_libs
LIST_DIRECTORIES false
${OCCT_LIB_DIR}/*.${DLL_EXT})
message(STATUS Found OCCT libs: ${occt_libs})
else()
find_package( OpenCASCADE REQUIRED )

foreach(target ${OpenCASCADE_LIBRARIES} )
get_target_property(loc ${target} IMPORTED_LOCATION_RELEASE)
list( APPEND occt_libs ${loc} )
endforeach()
find_package(
OpenCASCADE REQUIRED
)

foreach(target ${OpenCASCADE_LIBRARIES})
get_target_property(loc ${target} IMPORTED_LOCATION_RELEASE)
list(APPEND occt_libs ${loc})
endforeach()
endif()

execute_process(
COMMAND
${Python_EXECUTABLE}
${CMAKE_SOURCE_DIR}/dump_symbols.py
"${occt_libs}"
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
execute_process(COMMAND ${Python_EXECUTABLE} ${CMAKE_SOURCE_DIR}/dump_symbols.py
"${occt_libs}" WORKING_DIRECTORY ${CMAKE_BINARY_DIR})

get_target_property( LIBCLANG_PATH libclang IMPORTED_LOCATION_RELEASE )
get_target_property( VTK_INCLUDE_DIR VTK::CommonCore INTERFACE_INCLUDE_DIRECTORIES )
get_target_property(LIBCLANG_PATH libclang IMPORTED_LOCATION_RELEASE)
get_target_property(VTK_INCLUDE_DIR VTK::CommonCore
INTERFACE_INCLUDE_DIRECTORIES)

# for some reason I get multiple generator expressions
string(REPLACE ">" ">;" VTK_INCLUDE_DIR ${VTK_INCLUDE_DIR})
list(GET VTK_INCLUDE_DIR 0 VTK_INCLUDE_DIR)

message( STATUS "Include dirs: ${VTK_INCLUDE_DIR}")
message( STATUS "Include dirs: ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES}")
message(STATUS "Include dirs: ${VTK_INCLUDE_DIR}")
message(STATUS "Include dirs: ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES}")

# OSX
if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
list( APPEND CXX_INCLUDES -i /opt/usr/local/include/c++/v1/ -i /opt/usr/local/include/ )
list(APPEND CXX_INCLUDES -i /opt/usr/local/include/c++/v1/ -i
/opt/usr/local/include/)

# Linux-like
# Linux-like
elseif(NOT PLATFORM STREQUAL "Windows")
foreach( inc IN LISTS CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES)
list( APPEND CXX_INCLUDES -i ${inc}/ )
endforeach()
foreach(inc IN LISTS CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES)
list(APPEND CXX_INCLUDES -i ${inc}/)
endforeach()

# X-generation from Linux to Windows
# X-generation from Linux to Windows
else()
# download part of msvc 16 and winsdk
if( NOT EXISTS ${CMAKE_BINARY_DIR}/msvc )
execute_process(
COMMAND
${Python_EXECUTABLE}
${CMAKE_SOURCE_DIR}/extern/msvc-wine/vsdownload.py
--major ${MSVC_VER}
--accept-license
--dest msvc
Win10SDK_10.0.19041
Microsoft.VisualCpp.CRT.Headers
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
endif()

list( APPEND CXX_INCLUDES -i ${CMAKE_BINARY_DIR}/msvc/VC/Tools/MSVC/14.29.30133/include )
list( APPEND CXX_INCLUDES -i ${CMAKE_BINARY_DIR}/msvc/Windows\ Kits/10/Include/10.0.19041.0/ucrt/ )
list( APPEND CXX_INCLUDES -i ${CMAKE_SOURCE_DIR}/extern/include/ )
# download part of msvc 16 and winsdk
if(NOT EXISTS ${CMAKE_BINARY_DIR}/msvc)
execute_process(
COMMAND
${Python_EXECUTABLE} ${CMAKE_SOURCE_DIR}/extern/msvc-wine/vsdownload.py
--major ${MSVC_VER} --accept-license --dest msvc Win10SDK_10.0.19041
Microsoft.VisualCpp.CRT.Headers
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
endif()

list(APPEND CXX_INCLUDES -i
${CMAKE_BINARY_DIR}/msvc/VC/Tools/MSVC/14.29.30133/include)
list(APPEND CXX_INCLUDES -i
${CMAKE_BINARY_DIR}/msvc/Windows\ Kits/10/Include/10.0.19041.0/ucrt/)
list(APPEND CXX_INCLUDES -i ${CMAKE_SOURCE_DIR}/extern/include/)
endif()

if(PLATFORM)
message( STATUS "Requested platform: ${PLATFORM}")
message(STATUS "Requested platform: ${PLATFORM}")
else()
message( STATUS "Platform not specified.")

if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
set(PLATFORM Windows)
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
set(PLATFORM OSX)
else()
set(PLATFORM Linux)
endif()
message(STATUS "Platform not specified.")

if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
set(PLATFORM Windows)
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
set(PLATFORM OSX)
else()
set(PLATFORM Linux)
endif()
endif()

set(ENV{PYTHONPATH} ${CMAKE_SOURCE_DIR}/pywrap )
set(ENV{PYTHONPATH} ${CMAKE_SOURCE_DIR}/pywrap)

add_custom_command(
OUTPUT ${CMAKE_BINARY_DIR}/tmp.pkl
COMMAND
${CMAKE_COMMAND} -E env "PYTHONPATH=${CMAKE_SOURCE_DIR}/pywrap"
${Python_EXECUTABLE} -m bindgen -n ${N_PROC} -l ${LIBCLANG_PATH} -i
${VTK_INCLUDE_DIR}/
# -i ${OPENGL_INCLUDE_DIRS}
-i ${RapidJSON_INCLUDE_DIRS} -i
${CLANG_INSTALL_PREFIX}/lib/clang/${LLVM_VERSION_MAJOR}/include/ -p
${CMAKE_SOURCE_DIR} ${CXX_INCLUDES} parse ${CMAKE_SOURCE_DIR}/ocp.toml
tmp.pkl ${PLATFORM}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
DEPENDS ${CMAKE_SOURCE_DIR}/ocp.toml
USES_TERMINAL
COMMENT "Running pywrap - parse")

add_custom_target(pywrap_parse ALL DEPENDS ${CMAKE_BINARY_DIR}/tmp.pkl)

add_custom_command(
OUTPUT ${CMAKE_BINARY_DIR}/OCP/CMakeLists.txt
COMMAND
${CMAKE_COMMAND} -E env "PYTHONPATH=${CMAKE_SOURCE_DIR}/pywrap"
${Python_EXECUTABLE}
-m bindgen
-n ${N_PROC}
-l ${LIBCLANG_PATH}
-i ${VTK_INCLUDE_DIR}/
-i ${OPENGL_INCLUDE_DIRS}
-i ${RapidJSON_INCLUDE_DIRS}
-i ${CLANG_INSTALL_PREFIX}/lib/clang/${LLVM_VERSION_MAJOR}/include/
-p ${CMAKE_SOURCE_DIR}
${CXX_INCLUDES}
all ${CMAKE_SOURCE_DIR}/ocp.toml ${PLATFORM}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
DEPENDS ${CMAKE_SOURCE_DIR}/ocp.toml
USES_TERMINAL
COMMENT "Running pywrap"
)

add_custom_target(pywrap ALL DEPENDS ${CMAKE_BINARY_DIR}/OCP/CMakeLists.txt )
OUTPUT ${CMAKE_BINARY_DIR}/tmp_filtered.pkl
COMMAND
${CMAKE_COMMAND} -E env "PYTHONPATH=${CMAKE_SOURCE_DIR}/pywrap"
${Python_EXECUTABLE} -m bindgen -n ${N_PROC} -l ${LIBCLANG_PATH} -i
${VTK_INCLUDE_DIR}/
# -i ${OPENGL_INCLUDE_DIRS}
-i ${RapidJSON_INCLUDE_DIRS} -i
${CLANG_INSTALL_PREFIX}/lib/clang/${LLVM_VERSION_MAJOR}/include/ -p
${CMAKE_SOURCE_DIR} ${CXX_INCLUDES} transform ${CMAKE_SOURCE_DIR}/ocp.toml
${PLATFORM} tmp.pkl tmp_filtered.pkl
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
DEPENDS ${CMAKE_BINARY_DIR}/tmp.pkl
USES_TERMINAL
COMMENT "Running pywrap - transform")

add_custom_target(pywrap_transform ALL
DEPENDS ${CMAKE_BINARY_DIR}/tmp_filtered.pkl)

add_custom_command(
OUTPUT ${CMAKE_BINARY_DIR}/OCP/CMakeLists.txt
COMMAND
${CMAKE_COMMAND} -E env "PYTHONPATH=${CMAKE_SOURCE_DIR}/pywrap"
${Python_EXECUTABLE} -m bindgen -n ${N_PROC} -l ${LIBCLANG_PATH} -i
${VTK_INCLUDE_DIR}/
# -i ${OPENGL_INCLUDE_DIRS}
-i ${RapidJSON_INCLUDE_DIRS} -i
${CLANG_INSTALL_PREFIX}/lib/clang/${LLVM_VERSION_MAJOR}/include/ -p
${CMAKE_SOURCE_DIR} ${CXX_INCLUDES} generate ${CMAKE_SOURCE_DIR}/ocp.toml
${PLATFORM} tmp_filtered.pkl
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
DEPENDS ${CMAKE_BINARY_DIR}/tmp_filtered.pkl
USES_TERMINAL
COMMENT "Running pywrap - generate")

add_custom_target(pywrap_generate ALL
DEPENDS ${CMAKE_BINARY_DIR}/OCP/CMakeLists.txt)
10 changes: 7 additions & 3 deletions OCP_specific.inc
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,14 @@ inline void register_default_constructor(py::module m, const char* name){
};

template <typename T>
inline void copy_if_copy_constructible(T& t1, T& t2){
inline void copy_if_assignable(T& t1, T& t2){

if constexpr (std::is_copy_constructible<T>::value){
t1 = t2;
if constexpr (std::is_assignable<T, T>::value){
t1 = t2;
}
else
{
throw py::type_error("Cannot assign, function wrapper not working properly.");
}

};
Expand Down
2 changes: 1 addition & 1 deletion environment.devenv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: cpp-py-bindgen
channels:
- conda-forge
dependencies:
- occt=7.9.3=all*
- occt=8.0.0=all*
- pybind11=2.13.*
- python={{ get_env("PYTHON_VERSION", default="3.13") }}
- cmake >3.24
Expand Down
Loading
Loading