Skip to content

Commit

Permalink
w
Browse files Browse the repository at this point in the history
  • Loading branch information
jslee02 committed Mar 29, 2024
1 parent fa09427 commit 3cde681
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 8 deletions.
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
24 changes: 20 additions & 4 deletions pixi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ install-local = { cmd = "cmake --install build --prefix $CONDA_PREFIX", depends_
"configure_local",
"build",
] }

configure-unix = { cmd = "cmake -G Ninja -S . -B build -DDART_VERBOSE=ON -DDART_USE_SYSTEM_IMGUI=ON -DDART_BUILD_DARTPY2=ON" }
configure-win = { cmd = "cmake -S . -B build -G 'Visual Studio 17 2022' -DCMAKE_BUILD_TYPE=Release -DDART_MSVC_DEFAULT_OPTIONS=ON -DBUILD_SHARED_LIBS=OFF -DDART_VERBOSE=ON -DDART_USE_SYSTEM_IMGUI=OFF -DDART_BUILD_DARTPY2=ON" }

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 @@ -47,6 +58,7 @@ 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"

[build-dependencies]
cmake = "3.22.*"
Expand All @@ -65,7 +77,7 @@ freeglut = ">=3.2.2,<3.3"
imgui = ">=1.90.4,<1.91"

[target.linux-64.tasks]
configure = "cmake -G Ninja -S . -B build -DDART_VERBOSE=ON -DDART_USE_SYSTEM_IMGUI=ON"
configure = { depends_on = ["configure-unix"] }
lint = { cmd = "cmake --build build --target format && black . && isort .", depends_on = [
"configure",
] }
Expand All @@ -81,6 +93,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 All @@ -95,7 +108,7 @@ test-all = { cmd = "cmake --build build -j --target ALL", depends_on = [
clang-format-14 = ">=14.0.6,<14.1"

[target.osx-64.tasks]
configure = "cmake -G Ninja -S . -B build -DDART_VERBOSE=ON -DDART_USE_SYSTEM_IMGUI=ON"
configure = { depends_on = ["configure-unix"] }
lint = { cmd = "cmake --build build --target format && black . && isort .", depends_on = [
"configure",
] }
Expand All @@ -111,6 +124,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 All @@ -128,7 +142,7 @@ clang-format-14 = ">=14.0.6,<14.1"
imgui = ">=1.90.4,<1.91"

[target.osx-arm64.tasks]
configure = "cmake -G Ninja -S . -B build -DDART_VERBOSE=ON -DDART_USE_SYSTEM_IMGUI=ON"
configure = { depends_on = ["configure-unix"] }
lint = { cmd = "cmake --build build --target format && black . && isort .", depends_on = [
"configure",
] }
Expand All @@ -142,6 +156,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 All @@ -162,7 +177,7 @@ imgui = ">=1.90.4,<1.91"
freeglut = ">=3.2.2,<3.3"

[target.win-64.tasks]
configure = "cmake -S . -B build -G 'Visual Studio 17 2022' -DCMAKE_BUILD_TYPE=Release -DDART_MSVC_DEFAULT_OPTIONS=ON -DBUILD_SHARED_LIBS=OFF -DDART_VERBOSE=ON -DDART_USE_SYSTEM_IMGUI=OFF"
configure = { depends_on = ["configure-win"] }
lint = { cmd = "black . && isort .", depends_on = ["configure"] }
check-lint = { cmd = "black . --check && isort . --check", depends_on = [
"configure",
Expand All @@ -176,6 +191,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 3cde681

Please sign in to comment.