Skip to content

Commit

Permalink
copy necessary py folders
Browse files Browse the repository at this point in the history
  • Loading branch information
littlemine committed Jul 8, 2024
1 parent c43abc1 commit 3b3cd93
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 16 deletions.
34 changes: 19 additions & 15 deletions projects/CUDA/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ if (ZS_PYTHON_FOUND AND ZENO_WITH_PyZpc)
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory ${PY_LIBS_DIR}/zpcjit
COMMAND ${CMAKE_COMMAND} -E make_directory ${PY_LIBS_DIR}/zpcjit/zpc_jit/lib
COMMAND ${CMAKE_COMMAND} -E make_directory ${PY_LIBS_DIR}/zpcjit/zpc_jit/zpc/include
COMMENT "creating pyzpc jit module directory at ${PY_LIBS_DIR}/zpcjit"
)
file(GLOB ZPC_JIT_SRC ${CMAKE_CURRENT_SOURCE_DIR}/zpc_jit/pyzpc/*.py)
Expand All @@ -104,34 +105,34 @@ if (ZS_PYTHON_FOUND AND ZENO_WITH_PyZpc)
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${ZPCJIT_FILE} ${PY_LIBS_DIR}/zpcjit
COMMENT "Copying zpcjit src file: ${ZPCJIT_FILE}")
endforeach()
cmake_path(GET ZS_OVERWRITE_PYTHON_EXECUTABLE PARENT_PATH PYTHON_ENV_PATH)
if (WIN32)
cmake_path(GET ZS_OVERWRITE_PYTHON_INCLUDE_DIR PARENT_PATH PYTHON_ENV_PATH)
message(STATUS "python3 parent: ${PYTHON_ENV_PATH}")
add_custom_command(
TARGET copy_py
POST_BUILD
# COMMAND ${CMAKE_COMMAND} -E copy_directory ${PYTHON_ENV_PATH}/lib ${RESOURCE_BASE_DIR}/lib
# COMMAND ${CMAKE_COMMAND} -E copy_directory ${PYTHON_ENV_PATH}/dlls ${RESOURCE_BASE_DIR}/dlls
COMMAND ${CMAKE_COMMAND}
-DOBJECTS=${PYTHON_ENV_PATH}/lib
-DOBJECTS=${PYTHON_ENV_PATH}/Lib
-DOUTPUT=${RESOURCE_BASE_DIR}
-P ${CMAKE_CURRENT_SOURCE_DIR}/copy_dir.cmake

COMMAND ${CMAKE_COMMAND}
-DOBJECTS=${PYTHON_ENV_PATH}/dlls
-DOBJECTS=${PYTHON_ENV_PATH}/DLLs
-DOUTPUT=${RESOURCE_BASE_DIR}
-P ${CMAKE_CURRENT_SOURCE_DIR}/copy_dir.cmake

COMMAND ${CMAKE_COMMAND}
-DOBJECTS=${PYTHON_ENV_PATH}/library
-DOUTPUT=${RESOURCE_BASE_DIR}
-P ${CMAKE_CURRENT_SOURCE_DIR}/copy_dir.cmake
# COMMAND ${CMAKE_COMMAND}
# -DOBJECTS=${PYTHON_ENV_PATH}/library
# -DOUTPUT=${RESOURCE_BASE_DIR}
# -P ${CMAKE_CURRENT_SOURCE_DIR}/copy_dir.cmake

COMMAND ${CMAKE_COMMAND}
-DLIB="${PYTHON_ENV_PATH}/zlib.dll"
-DDLL_DIR=${PYTHON_ENV_PATH}
-DOUTPUT=$<TARGET_FILE_DIR:zpc_py_interop>
-P ${CMAKE_CURRENT_SOURCE_DIR}/copy_dll.cmake
# COMMAND ${CMAKE_COMMAND}
# -DLIB="${PYTHON_ENV_PATH}/zlib.dll"
# -DDLL_DIR=${PYTHON_ENV_PATH}
# -DOUTPUT=$<TARGET_FILE_DIR:zpc_py_interop>
# -P ${CMAKE_CURRENT_SOURCE_DIR}/copy_dll.cmake

COMMENT "copying python lib directories at ${PYTHON_ENV_PATH} to ${RESOURCE_BASE_DIR}"
)
Expand All @@ -143,8 +144,6 @@ if (ZS_PYTHON_FOUND AND ZENO_WITH_PyZpc)
)
endforeach()
else()
cmake_path(GET ZS_OVERWRITE_PYTHON_INCLUDE_DIR PARENT_PATH PYTHON_ENV_PATH)
cmake_path(GET PYTHON_ENV_PATH PARENT_PATH PYTHON_ENV_PATH)
message(STATUS "python3 parent: ${PYTHON_ENV_PATH}")
add_custom_command(
TARGET copy_py
Expand All @@ -156,6 +155,12 @@ if (ZS_PYTHON_FOUND AND ZENO_WITH_PyZpc)
)
endif()

# prepare zpc headers for pyzpc
add_custom_command(
TARGET copy_py POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/zpc/include/zensim ${PY_LIBS_DIR}/zpcjit/zpc_jit/zpc/include
COMMENT "Copying zpc source files: ${CMAKE_CURRENT_SOURCE_DIR}/zpc/include/zensim")
# prepare zpc libs for pyzpc
foreach(ZPC_BIN_FILE IN LISTS ZPC_BINARIES)
if(EXISTS ${RESOURCE_BASE_DIR}/${PREFIX}${ZPC_BIN_FILE}${SUFFIX})
add_custom_command(
Expand All @@ -168,7 +173,6 @@ if (ZS_PYTHON_FOUND AND ZENO_WITH_PyZpc)
endforeach(ZPC_BIN_FILE IN LISTS ZPC_BINARIES)
endif(ZS_PYTHON_FOUND AND ZENO_WITH_PyZpc)


add_library(zshelper INTERFACE)
target_include_directories(zshelper INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
Expand Down
3 changes: 3 additions & 0 deletions projects/PyZpc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ target_link_libraries(zeno PRIVATE zpc_jit_py)
target_link_libraries(zeno PRIVATE zshelper)

#
# find_package(PkgConfig)
# pkg_check_modules(LIBFFI REQUIRED IMPORTED_TARGET libffi)
# target_link_libraries(zeno PRIVATE PkgConfig::LIBFFI)
target_sources(zeno PRIVATE
pyzfx.cpp
)
Expand Down
13 changes: 12 additions & 1 deletion projects/PyZpc/pyzfx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,18 @@ static callback_t zpc_init_callback = [] (auto _) {
#endif
auto zeno_lib_path = exe_dir + "/" + ZENO_PYZPC_DLL_FILE;
auto py_libs_dir = exe_dir + "/resource/py_libs";
if (PyRun_SimpleString(("__import__('sys').path.insert(0, '" +
if (PyRun_SimpleString("import sys; sys.path.append('C\:/Develop/vcpkg/installed/x64-windows/tools/python3/DLLs'); ") < 0) {
log_warn("Failed to initialize Python module");
return;
}
#if 0
if (PyRun_SimpleString(("import sys; import os; sys.path.append(os.path.join('" +
exe_dir + "', 'DLLs')); ").c_str()) < 0) {
log_warn("Failed to initialize Python module");
return;
}
#endif
if (PyRun_SimpleString(("sys.path.append('" +
py_libs_dir + "'); import zpy; zpy.init_zeno_lib('" + zeno_lib_path +
"'); zpy.zeno_lib_path = '" + zeno_lib_path + "'").c_str()) < 0) {
log_warn("Failed to initialize Python module");
Expand Down

0 comments on commit 3b3cd93

Please sign in to comment.