Skip to content

Commit

Permalink
[dartpy] Add nanobind dependency
Browse files Browse the repository at this point in the history
w
  • Loading branch information
jslee02 committed Mar 31, 2024
1 parent 5ba1e72 commit bf86c13
Show file tree
Hide file tree
Showing 10 changed files with 116 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci_windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ jobs:
bullet3
freeglut
glfw3
nanobind
nlopt
opengl
osg
Expand All @@ -55,7 +56,7 @@ jobs:
tracy
urdfdom
triplet: x64-windows
revision: "2024.02.14"
revision: "2024.03.25"
github-binarycache: true
token: ${{ github.token }}

Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/publish_dartpy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ jobs:
freeglut
glfw3
imgui
nanobind
nlopt
ode
opengl
Expand All @@ -119,7 +120,7 @@ jobs:
tinyxml2
urdfdom
triplet: x64-windows
revision: "2024.02.14"
revision: "2024.03.25"
github-binarycache: true
token: ${{ github.token }}

Expand Down
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ dart_option(DART_ENABLE_SIMD
"Build DART with all SIMD instructions on the current local machine" ON)
dart_option(DART_BUILD_GUI_OSG "Build osgDart library" ON)
dart_option(DART_BUILD_DARTPY "Build dartpy" ON)
dart_option(DART_BUILD_DARTPY2 "[Experimental] Build Python binding (dartpy2) with nanobind" OFF)
dart_option(DART_BUILD_PROFILE "Build DART with profiling options" OFF)
dart_option(DART_CODECOV "Turn on codecov support" OFF)
dart_option(DART_FAST_DEBUG "Add -O1 option for DEBUG mode build" OFF)
Expand Down Expand Up @@ -162,8 +163,9 @@ endif()
#===============================================================================
# Build type settings
#===============================================================================
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build, options are: Debug | Release | RelWithDebInfo | MinSizeRel" FORCE)
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()
string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_UPPERCASE)

Expand Down
15 changes: 13 additions & 2 deletions cmake/DARTFindDependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,19 @@ endif()
# Optional dependencies
#=======================

find_package(Python3 COMPONENTS Interpreter Development REQUIRED)

if(DART_BUILD_DARTPY2)
include(FetchContent)
FetchContent_Declare(nanobind
GIT_REPOSITORY https://github.com/wjakob/nanobind.git
GIT_TAG master
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
)
FetchContent_MakeAvailable(nanobind)
endif()

if(DART_BUILD_PROFILE)
include(FetchContent)
FetchContent_Declare(tracy
Expand All @@ -126,8 +139,6 @@ if(DART_BUILD_PROFILE)
endif()
endif()

find_package(Python3 COMPONENTS Interpreter Development)

option(DART_SKIP_spdlog "If ON, do not use spdlog even if it is found." OFF)
mark_as_advanced(DART_SKIP_spdlog)
dart_find_package(spdlog)
Expand Down
1 change: 1 addition & 0 deletions docker/dev/v6.14/Dockerfile.ubuntu.noble
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ RUN apt-get install -y --no-install-recommends \

RUN apt-get install -y --no-install-recommends \
libpython3-dev \
nanobind-dev \
pybind11-dev \
python3 \
python3-dev \
Expand Down
19 changes: 19 additions & 0 deletions pixi.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions pixi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ ipopt = ">=3.14.14,<3.15"
nlopt = ">=2.7.1,<2.8"
pagmo = ">=2.19.0,<2.20"
numpy = ">=1.26.4,<1.27"
nanobind = ">=1.9.2,<1.10"
python = ">=3.12.2,<3.13"

[tasks]
clean = "rm -rf build"
Expand All @@ -48,6 +50,13 @@ install-local = { cmd = "cmake --install build --prefix $CONDA_PREFIX", depends_
configure-unix = { cmd = "cmake -G Ninja -S . -B build -DCMAKE_BUILD_TYPE=Release -DDART_VERBOSE=ON -DDART_USE_SYSTEM_IMGUI=ON" }
configure-win = { cmd = "cmake -S . -B build -G 'Visual Studio 17 2022' -DDART_VERBOSE=ON -DDART_MSVC_DEFAULT_OPTIONS=ON -DBUILD_SHARED_LIBS=OFF -DDART_USE_SYSTEM_IMGUI=OFF" }

build-dartpy2-unix = { cmd = "cmake --build build -j --target dartpy2", depends_on = [
"configure",
] }
build-dartpy2-win = { cmd = "cmake --build build -j --target dartpy2 --config Release", depends_on = [
"configure",
] }

example-hello-world = { cmd = "cmake --build build --target hello_world --parallel && ./build/bin/hello_world", depends_on = [
"configure",
] }
Expand Down Expand Up @@ -101,6 +110,7 @@ build-tests = { cmd = "cmake --build build -j --target tests", depends_on = [
build-dartpy = { cmd = "cmake --build build -j --target dartpy", depends_on = [
"configure",
] }
build-dartpy2 = { depends_on = ["build-dartpy2-unix"] }
test = { cmd = "ctest --test-dir build --output-on-failure", depends_on = [
"build-tests",
] }
Expand Down Expand Up @@ -140,6 +150,7 @@ build-tests = { cmd = "cmake --build build -j --target tests", depends_on = [
build-dartpy = { cmd = "cmake --build build -j --target dartpy", depends_on = [
"configure",
] }
build-dartpy2 = { depends_on = ["build-dartpy2-unix"] }
test = { cmd = "ctest --test-dir build --output-on-failure", depends_on = [
"build-tests",
] }
Expand Down Expand Up @@ -175,6 +186,7 @@ build-tests = { cmd = "cmake --build build -j --target tests", depends_on = [
build-dartpy = { cmd = "cmake --build build -j --target dartpy", depends_on = [
"configure",
] }
build-dartpy2 = { depends_on = ["build-dartpy2-unix"] }
test = { cmd = "ctest --test-dir build --output-on-failure", depends_on = [
"build-tests",
] }
Expand Down Expand Up @@ -207,6 +219,7 @@ build-tests = { cmd = "cmake --build build --config Release -j --target tests",
build-dartpy = { cmd = "cmake --build build -j --target dartpy", depends_on = [
"configure",
] }
build-dartpy2 = { depends_on = ["build-dartpy2-win"] }
test = { cmd = "ctest --test-dir build --build-config Release --output-on-failure", depends_on = [
"build-tests",
] }
Expand Down
3 changes: 3 additions & 0 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ endif()
set(DART_DARTPY_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/dartpy")

add_subdirectory(dartpy)
if(DART_BUILD_DARTPY2)
add_subdirectory(dartpy2)
endif()
add_subdirectory(tests)
add_subdirectory(examples)
add_subdirectory(tutorials)
Expand Down
10 changes: 10 additions & 0 deletions python/dartpy2/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright (c) 2011-2024, The DART development contributors
# All rights reserved.
#
# The list of contributors can be found at:
# https://github.com/dartsim/dart/blob/main/LICENSE
#
# This file is provided under the "BSD-style" License

find_package(Python3 COMPONENTS Interpreter Development.Module REQUIRED)
nanobind_add_module(dartpy2 dartpy2.cpp)
49 changes: 49 additions & 0 deletions python/dartpy2/dartpy2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright (c) 2011-2024, The DART development contributors
* All rights reserved.
*
* The list of contributors can be found at:
* https://github.com/dartsim/dart/blob/main/LICENSE
*
* This file is provided under the following "BSD-style" License:
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/

#include <nanobind/nanobind.h>

namespace dart::python {

NB_MODULE(dartpy2, m)
{
// m.doc() = "dartpy2: Python API of Dynamic Animation and Robotics
// Toolkit";

// #ifdef DARTPY_VERSION_INFO
// m.attr("__version__") = DARTPY_VERSION_INFO;
// #else
// m.attr("__version__") = "dev";
// #endif
}

} // namespace dart::python

0 comments on commit bf86c13

Please sign in to comment.