Skip to content

Commit

Permalink
Merge pull request #2 from ITISFoundation/working_version
Browse files Browse the repository at this point in the history
Working wheel for python environment
  • Loading branch information
wvangeit authored Dec 27, 2023
2 parents 64027d3 + 9f548f8 commit adb1148
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 17 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build-wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ jobs:
- uses: pypa/[email protected]
env:
CIBW_BUILD: ${{ matrix.python }}*${{ matrix.arch }}
CIBW_BEFORE_ALL: "yum install -y gcc-gfortran lapack-devel boost169-devel boost169-filesystem boost169-program-options boost169-regex boost169-serialization blas-devel"
#CIBW_BEFORE_ALL: "yum install -y gcc-gfortran lapack-devel boost169-devel boost169-filesystem boost169-program-options boost169-regex boost169-serialization blas-devel"
- name: Upload wheels
uses: actions/upload-artifact@v3
with:
name: wheels-${{ matrix.os }}-${{ matrix.python }}-${{ matrix.arch }}
path: wheelhouse/*.whl
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -247,3 +247,4 @@ pyrightconfig.json
build.sh
dakota
dakota_wheel-*
wheelhouse
21 changes: 15 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,24 +1,33 @@
cmake_minimum_required(VERSION 3.15)
project(itis_dakota)

add_definitions(-w)

# set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wall -lpthread -lutil")

find_package(Threads REQUIRED)

set(PY_BUILD_CMAKE_BIN_DIRECTORY ${PY_BUILD_CMAKE_PACKAGE_NAME}-${PY_BUILD_CMAKE_PACKAGE_VERSION}.data/scripts)
set(PY_BUILD_CMAKE_LIB_DIRECTORY ${PY_BUILD_CMAKE_PACKAGE_NAME}-${PY_BUILD_CMAKE_PACKAGE_VERSION}.data/platlib)

add_subdirectory(dakota EXCLUDE_FROM_ALL)

add_custom_target(dakota_for_python ALL DEPENDS environment dakota_src dakota)
add_custom_target(dakota_for_python ALL DEPENDS environment dakota_src ${Dakota_TPL_LIBRARIES})


install(TARGETS dakota
RUNTIME
COMPONENT dakota_for_python
DESTINATION ${PY_BUILD_CMAKE_BIN_DIRECTORY})
#install(TARGETS dakota
# RUNTIME
# COMPONENT dakota_for_python
# DESTINATION ${PY_BUILD_CMAKE_BIN_DIRECTORY})

install(TARGETS dakota_src
LIBRARY
COMPONENT dakota_for_python
LIBRARY DESTINATION ${PY_BUILD_CMAKE_BIN_DIRECTORY})

#install(PROGRAMS ${Dakota_TPL_LIBRARIES}
# COMPONENT dakota_for_python
# DESTINATION ${PY_BUILD_CMAKE_LIB_DIRECTORY}/dakota/environment/)

install(TARGETS environment
LIBRARY
COMPONENT dakota_for_python
Expand Down
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
all:


wheel:
pip wheel -v .
wheel: cache-clean clean
CIBW_BUILD=cp38*x86_64 CIBW_BUILD_VERBOSITY=10 CIBW_SKIP="*musllinux*" cibuildwheel --platform linux

install:
pip install -v .
Expand All @@ -19,4 +19,5 @@ get-dakota-src:
cd dakota && \
git submodule update --init packages/external && \
git submodule update --init packages/pecos && \
git submodule update --init packages/surfpack
git submodule update --init packages/surfpack && \
git apply ../dakota-src.patch
21 changes: 21 additions & 0 deletions dakota-src.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
diff --git a/cmake/DakotaFindPython.cmake b/cmake/DakotaFindPython.cmake
index 43f9fb9..f4c4e28 100644
--- a/cmake/DakotaFindPython.cmake
+++ b/cmake/DakotaFindPython.cmake
@@ -8,7 +8,7 @@ macro(dakota_find_python)
if(DAKOTA_PYTHON_DIRECT_INTERFACE OR DAKOTA_PYTHON_SURROGATES OR
DAKOTA_PYTHON_WRAPPER OR DAKOTA_PYBIND11)
message(STATUS "Dakota enabling Python (Development) for direct or surrogate interface")
- list(APPEND dakota_python_components Development)
+ list(APPEND dakota_python_components Development.Module)

if (DAKOTA_PYTHON_DIRECT_INTERFACE_NUMPY)
message(STATUS "Dakota enabling Python direct interface with NumPy")
@@ -18,6 +18,7 @@ macro(dakota_find_python)
endif()

find_package(Python REQUIRED ${dakota_python_components})
+ # find_package(Python COMPONENTS ${dakota_python_components} REQUIRED)

# pybind11, C3, Acro, etc., use older CMake FindPythonInterp, so we
# coerce it to use same as Dakota; more complex situations may
19 changes: 12 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,21 @@ requires = ["py-build-cmake", "numpy"]
build-backend = "py_build_cmake.build"

[tool.cibuildwheel]
before-build = ["pushd /opt/_internal && tar -xJf static-libs-for-embedding-only.tar.xz && popd", "pip install numpy", "pip install cmake --upgrade"]
before-all = ["yum install -y gcc-gfortran lapack-devel boost169-devel boost169-filesystem boost169-program-options boost169-regex boost169-serialization blas-devel"]
repair-wheel-command = "auditwheel repair -w {dest_dir} {wheel}"
before-build = ["pip install auditwheel --upgrade", "pip install numpy", "pip install cmake --upgrade"]
#before-build = ["pip install auditwheel --upgrade", "pushd /opt/_internal && tar -xJf static-libs-for-embedding-only.tar.xz && popd", "pip install numpy", "pip install cmake --upgrade"]
before-all = ["yum install -y lapack-static boost169-static blas-static python3-devel.x86_64"]

[tool.py-build-cmake.sdist]
include = ["dakota/*", "CMakeLists.txt", "LICENSE.txt"]
repair-wheel-command = "auditwheel repair -w {dest_dir} {wheel} && ./scripts/fix_wheel.sh {dest_dir}"
build-verbosity = 2
skip = "*-musllinux_*"

# [tool.py-build-cmake.sdist]
# include = ["dakota/*", "CMakeLists.txt", "LICENSE.txt"]

[tool.py-build-cmake.cmake]
source_path = "."
options = {"DAKOTA_PYTHON_WRAPPER" = "ON", "BUILD_SHARED_LIBS"="OFF", "CMAKE_SKIP_INSTALL_RPATH" = "ON", "CMAKE_POSITION_INDEPENDENT_CODE" = "ON", "DAKOTA_PYTHON_DIRECT_INTERFACE" = "ON", "BOOST_LIBRARYDIR" = "/usr/lib64/boost169", "BOOST_INCLUDEDIR" = "/usr/include/boost169"}
build_args = ["-j"]
#options = {"Boost_USE_STATIC_LIBS" = "ON", "DAKOTA_PYTHON_WRAPPER" = "ON", "CMAKE_POSITION_INDEPENDENT_CODE" = "ON", "BUILD_SHARED_LIBS"="OFF", "DAKOTA_PYTHON_DIRECT_INTERFACE" = "ON", "BOOST_LIBRARYDIR" = "/usr/lib64/boost169", "BOOST_INCLUDEDIR" = "/usr/include/boost169", "PYTHON_EXECUTABLE" = "/opt/python/cp38-cp38/bin/python", "PYTHON_INCLUDE_DIR" = "/opt/python/cp38-cp38/include", "PYTHON_LIBRARY" = "/opt/python/cp38-cp38/lib/libpython3.8.a", "PYTHON_LIBRARIES" = "/opt/python/cp38-cp38/lib/"}
options = {"DAKOTA_PYTHON_WRAPPER" = "ON", "CMAKE_POSITION_INDEPENDENT_CODE" = "ON", "BUILD_SHARED_LIBS"="OFF", "DAKOTA_PYTHON_DIRECT_INTERFACE" = "ON", "BOOST_LIBRARYDIR" = "/usr/lib64/boost169", "BOOST_INCLUDEDIR" = "/usr/include/boost169", "PYTHON_EXECUTABLE" = "/opt/python/cp38-cp38/bin/python"}
build_args = ["-j4"]
build_type = "Release"
install_components = ["dakota_for_python"]
20 changes: 20 additions & 0 deletions scripts/fix_wheel.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

set -ex

WHEEL_DIR=$1

WHEEL_NAME=$(basename $(ls ${WHEEL_DIR}/*.whl) .whl)

echo "Fixing ${WHEEL_DIR}/${WHEEL_NAME}.whl"

cd ${WHEEL_DIR}

unzip ${WHEEL_DIR}/${WHEEL_NAME}.whl -d ${WHEEL_NAME}

find ${WHEEL_NAME} -type f -name "*.so" -exec patchelf --set-rpath '$ORIGIN/../../itis_dakota.libs' '{}' \;
find ${WHEEL_NAME}/itis_dakota.libs -type f -name "*.so.*" -exec patchelf --set-rpath '$ORIGIN/' '{}' \;

cd ${WHEEL_NAME}
zip -r ${WHEEL_NAME}.whl *
mv ${WHEEL_NAME}.whl ..

0 comments on commit adb1148

Please sign in to comment.