Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
MAminSFV committed Sep 14, 2024
1 parent a006799 commit ff5ee01
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 13 deletions.
21 changes: 17 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,18 @@ cmake_minimum_required(VERSION 3.16...3.27)

# Scikit-build-core sets these values for you, or you can just hard-code the
# name and version.
project(drake_extension LANGUAGES CXX)
project(
${SKBUILD_PROJECT_NAME}
VERSION ${SKBUILD_PROJECT_VERSION}
LANGUAGES CXX)

include(CTest)
option(RUN_X11_TESTS "Run tests that require X11" OFF)
find_package(drake CONFIG REQUIRED)

# Find the module development requirements (requires FindPython from 3.17 or
# scikit-build-core's built-in backport)
find_package(Python REQUIRED COMPONENTS Interpreter Development.Module)
find_package(pybind11 CONFIG REQUIRED)

execute_process(COMMAND ${Python3_EXECUTABLE}-config --exec-prefix
Expand All @@ -32,6 +39,12 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON)

# Add a library using FindPython's tooling (pybind11 also provides a helper like
# this)
pybind11_add_module(drake_extension MODULE src/drake_extension.cpp)
target_link_libraries(drake_extension PUBLIC drake::drake)
set_target_properties(drake_extension PROPERTIES CXX_VISIBILITY_PRESET default)
pybind11_add_module(_ext MODULE src/ext.cpp WITH_SOABI)
target_link_libraries(_ext PUBLIC drake::drake)
set_target_properties(_ext PROPERTIES CXX_VISIBILITY_PRESET default)

# This is passing in the version as a define just as an example
target_compile_definitions(_ext PRIVATE VERSION_INFO=${PROJECT_VERSION})

# The install directory is the output (wheel) directory
install(TARGETS _ext DESTINATION drake_extension)
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ If you think the current setup can be improved, please open an issue or a pull r

## Setup Guide
> [!NOTE]
> The setup has only been tested with Ubuntu 24.04 (Noble) operating system, Python 3.12 and Drake v1.32.0
> The setup has only been tested with Ubuntu 22.04 (Jammy) operating system, Python 3.10 and Drake v1.32.0
> If you encountered any issues feel free to leave an issue so we can fix it together.
> You are also welcome to make a PR and extend the support.
Expand Down Expand Up @@ -47,7 +47,6 @@ py.test
```

## TODOs
- [ ] Add Github Actions to Automated Testing
- [ ] Add a Dockerfile for more reproducibility and transparency of the setup
- [ ] Try `nanobind` and compare resulting binary sizes with `pybind`
- [ ] Add information about how to shared the packaged python wheel.
Expand Down
10 changes: 3 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
[build-system]
requires = [
"setuptools>=42",
"wheel",
"ninja",
"cmake>=3.12",
]
build-backend = "setuptools.build_meta"
requires = ["scikit-build-core>=0.3.3", "pybind11"]
build-backend = "scikit_build_core.build"


[project]
name = "drake_extension"
Expand Down
4 changes: 4 additions & 0 deletions src/drake_extension/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from __future__ import annotations
from ._ext import __doc__, __version__, SimpleAdder

__all__ = ["__doc__", "__version__", "SimpleAdder"]
6 changes: 6 additions & 0 deletions src/drake_extension.cpp → src/ext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ PYBIND11_MODULE(drake_extension , m) {

py::class_<SimpleAdder<T>, LeafSystem<T>>(m, "SimpleAdder")
.def(py::init<T>(), py::arg("add"));

#ifdef VERSION_INFO
m.attr("__version__") = MACRO_STRINGIFY(VERSION_INFO);
#else
m.attr("__version__") = "dev";
#endif
}

} // namespace drake_extension

0 comments on commit ff5ee01

Please sign in to comment.