From 3cde6815caff2aa873f6a67b153c602243703dce Mon Sep 17 00:00:00 2001 From: Jeongseok Lee Date: Fri, 29 Mar 2024 09:47:04 -0700 Subject: [PATCH] w --- CMakeLists.txt | 6 ++-- cmake/DARTFindDependencies.cmake | 15 ++++++++-- pixi.toml | 24 +++++++++++++--- python/CMakeLists.txt | 3 ++ python/dartpy2/CMakeLists.txt | 10 +++++++ python/dartpy2/dartpy2.cpp | 49 ++++++++++++++++++++++++++++++++ 6 files changed, 99 insertions(+), 8 deletions(-) create mode 100644 python/dartpy2/CMakeLists.txt create mode 100644 python/dartpy2/dartpy2.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 7e2ef2722ec21..8041bd079c5a0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -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) diff --git a/cmake/DARTFindDependencies.cmake b/cmake/DARTFindDependencies.cmake index 33af2bb1d0aed..2b64414b926d9 100644 --- a/cmake/DARTFindDependencies.cmake +++ b/cmake/DARTFindDependencies.cmake @@ -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 @@ -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) diff --git a/pixi.toml b/pixi.toml index f4741fcca56f2..64aab83cbec73 100644 --- a/pixi.toml +++ b/pixi.toml @@ -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", ] } @@ -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.*" @@ -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", ] } @@ -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", ] } @@ -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", ] } @@ -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", ] } @@ -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", ] } @@ -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", ] } @@ -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", @@ -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", ] } diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index cc23a4001ca7b..db94f4cacdc29 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -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) diff --git a/python/dartpy2/CMakeLists.txt b/python/dartpy2/CMakeLists.txt new file mode 100644 index 0000000000000..8b36dbfc58cae --- /dev/null +++ b/python/dartpy2/CMakeLists.txt @@ -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) diff --git a/python/dartpy2/dartpy2.cpp b/python/dartpy2/dartpy2.cpp new file mode 100644 index 0000000000000..4413ee3ac3551 --- /dev/null +++ b/python/dartpy2/dartpy2.cpp @@ -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 + +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