Skip to content

Commit

Permalink
CMake builds seem properly integrated, sub and derivative are working…
Browse files Browse the repository at this point in the history
…, need to get wheels built
  • Loading branch information
toastedcrumpets committed May 7, 2021
1 parent 88d1f18 commit cb0414d
Show file tree
Hide file tree
Showing 11 changed files with 273 additions and 272 deletions.
43 changes: 41 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ endif()
### First check if the compiler supports C++11 or C++0x and enable the build flag
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

######################################################################
########## HEADER DIRECTORIES
Expand Down Expand Up @@ -125,6 +126,44 @@ stator_test(symbolic_ad_test)
######################################################################
########## PYTHON INTERFACE
######################################################################

# Build a Python extension module using pybind11
# pybindings_add_module(<module>)
# Here <module> should be the fully qualified name for the module,
# e.g. pybindings_add_module(foo.bar._baz)
# <module> becomes the target name in case you wish to do something to it later
# The source for the binding *must* be placed in src/pybindings/{relpath}/py{name}.cc
# E.g. for module=foo.bar._baz -> src/pybindings/bar/py_baz.cc
function(pybindings_add_module module)
set(target_name ${module})
string(REPLACE "." "/" modpath ${module})
string(REPLACE "." ";" modlist ${module})

# The module name is the last entry
list(GET modlist -1 modname)

# Remove everything that is not the root or the module name
#list(REMOVE_AT modlist 0)
list(REMOVE_AT modlist -1)

# Get the relative path
if(modlist)
string(REPLACE ";" "/" relpath "${modlist}")
else()
set(relpath "")
endif()

# Define the binding source file
set(sources pysrc/${relpath}/${modname}.cpp)

# Invoke pybind11 and set where the library should go, and what it is called
pybind11_add_module(${target_name} ${sources})
set(outdir ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${relpath})
set_target_properties(${target_name} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${outdir})
set_target_properties(${target_name} PROPERTIES OUTPUT_NAME ${modname})
endfunction()

add_subdirectory(extern/pybind11)
pybind11_add_module(core pysrc/stator/core.cpp)
target_include_directories(core PRIVATE ${PROJECT_SOURCE_DIR})
include_directories(${PROJECT_SOURCE_DIR})
pybindings_add_module(stator.core)

5 changes: 5 additions & 0 deletions build-wheels.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
DOCKER_IMAGE=quay.io/pypa/manylinux2014_x86_64
PLAT=manylinux2014_x86_64
docker run --rm -e PLAT=$PLAT -v `pwd`:/io $DOCKER_IMAGE $PRE_CMD /io/scripts/manylinux_entrypoint.sh
ls wheelhouse/
Empty file added dev-requirements.txt
Empty file.
234 changes: 0 additions & 234 deletions install-icc.sh

This file was deleted.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ requires = [
"setuptools>=42",
"wheel",
"pybind11>=2.6.0",
"cmake>=3.13",
]

build-backend = "setuptools.build_meta"
2 changes: 1 addition & 1 deletion pysrc/stator/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ PYBIND11_MODULE(core, m)

m.def("derivative", static_cast<sym::Expr (*)(const sym::Expr&, const sym::Expr&)>(&sym::derivative));
m.def("simplify", static_cast<sym::Expr (*)(const sym::Expr&)>(&sym::simplify));
m.def("subs", static_cast<sym::Expr (*)(const sym::Expr&)>(&sym::simplify));
//m.def("sub", static_cast<sym::Expr (*)(const sym::Expr&, const sym::Expr&)>(&sym::sub));

py::implicitly_convertible<int, sym::Expr>();
py::implicitly_convertible<double, sym::Expr>();
Expand Down
37 changes: 37 additions & 0 deletions scripts/manylinux_entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash
set -e -u -x

function repair_wheel {
wheel="$1"
if ! auditwheel show "$wheel"; then
echo "Skipping non-platform wheel $wheel"
else
auditwheel repair "$wheel" --plat "$PLAT" -w /io/wheelhouse/
fi
}


# Install a system package required by our library
yum install -y gtest-devel

# Compile wheels
ls /opt/python/
mkdir -p /io/wheelhouse
for VER in cp39-cp39; do #cp36-cp36m cp37-cp37m cp38-cp38
PYBIN=/opt/python/$VER/bin
"${PYBIN}/pip" install -r /io/dev-requirements.txt
"${PYBIN}/pip" wheel /io/ --no-deps -w /io/wheelhouse/
done

# Bundle external shared libraries into the wheels
for whl in /io/wheelhouse/*.whl; do
#auditwheel repair "$whl"
repair_wheel "$whl"
done

# Install packages and test
for VER in cp39-cp39; do #cp36-cp36m cp37-cp37m cp38-cp38
PYBIN=/opt/python/$VER/bin
"${PYBIN}/pip" install stator --no-index -f /io/wheelhouse
#(cd "$HOME"; "${PYBIN}/nosetests" pymanylinuxdemo)
done
Loading

0 comments on commit cb0414d

Please sign in to comment.