diff --git a/cmake/mt_defs.cmake b/cmake/mt_defs.cmake index 33a6d0e4..a3798f62 100644 --- a/cmake/mt_defs.cmake +++ b/cmake/mt_defs.cmake @@ -422,6 +422,7 @@ endfunction() function(mt_python_binding) set(prefix _ARG) set(options + EXCLUDE_FROM_INSTALL ) set(oneValueArgs NAME @@ -477,4 +478,8 @@ function(mt_python_binding) target_compile_features(${_ARG_NAME} PRIVATE cxx_std_17) target_link_libraries(${_ARG_NAME} PRIVATE ${_ARG_LINK_LIBRARIES}) target_compile_options(${_ARG_NAME} PRIVATE ${_ARG_COMPILE_OPTIONS}) + + if(NOT ${_ARG_EXCLUDE_FROM_INSTALL}) + set_property(GLOBAL APPEND PROPERTY PYMOMENTUM_TARGETS_TO_INSTALL ${_ARG_NAME}) + endif() endfunction() diff --git a/pixi.toml b/pixi.toml index ea83642d..a21811c9 100644 --- a/pixi.toml +++ b/pixi.toml @@ -167,20 +167,10 @@ config_dev = { cmd = """ """, env = { FBXSDK_PATH = ".deps/fbxsdk", MOMENTUM_ENABLE_SIMD = "ON", MOMENTUM_BUILD_PYMOMENTUM = "ON" }, depends_on = [ "install_deps", ] } -build_py = { cmd = """ - python setup.py build \ - --build-base build/$PIXI_ENVIRONMENT_NAME/py \ - build_ext \ - --cmake-args='\ - -DMOMENTUM_BUILD_IO_FBX=ON \ - -DMOMENTUM_BUILD_EXAMPLES=OFF \ - -DMOMENTUM_BUILD_TESTING=ON \ - -DMOMENTUM_ENABLE_SIMD=$MOMENTUM_ENABLE_SIMD \ - -DMOMENTUM_USE_SYSTEM_GOOGLETEST=ON \ - -DMOMENTUM_USE_SYSTEM_PYBIND11=OFF \ - -DMOMENTUM_USE_SYSTEM_RERUN_CPP_SDK=ON \ - ' - """, env = { FBXSDK_PATH = ".deps/fbxsdk", MOMENTUM_ENABLE_SIMD = "ON" }, depends_on = [ +build_py = { cmd = "pip install . -vv", env = { FBXSDK_PATH = ".deps/fbxsdk", CMAKE_ARGS = """ + -DMOMENTUM_BUILD_IO_FBX=ON \ + -DMOMENTUM_ENABLE_SIMD=$MOMENTUM_ENABLE_SIMD +""", MOMENTUM_ENABLE_SIMD = "ON" }, depends_on = [ "install_deps", ] } test_py = { cmd = """ @@ -205,20 +195,10 @@ test_py = { cmd = """ pytorch = ">=2.4.0" [target.osx.tasks] -build_py = { cmd = """ - python setup.py build \ - --build-base build/$PIXI_ENVIRONMENT_NAME/py \ - build_ext \ - --cmake-args='\ - -DMOMENTUM_BUILD_IO_FBX=$MOMENTUM_BUILD_IO_FBX \ - -DMOMENTUM_BUILD_EXAMPLES=OFF \ - -DMOMENTUM_BUILD_TESTING=ON \ - -DMOMENTUM_ENABLE_SIMD=$MOMENTUM_ENABLE_SIMD \ - -DMOMENTUM_USE_SYSTEM_GOOGLETEST=ON \ - -DMOMENTUM_USE_SYSTEM_PYBIND11=ON \ - -DMOMENTUM_USE_SYSTEM_RERUN_CPP_SDK=ON \ - ' - """, env = { MOMENTUM_BUILD_IO_FBX = "OFF", MOMENTUM_ENABLE_SIMD = "ON" } } +build_py = { cmd = "pip install . -vv", env = { CMAKE_ARGS = """ + -DMOMENTUM_BUILD_IO_FBX=$MOMENTUM_BUILD_IO_FBX \ + -DMOMENTUM_ENABLE_SIMD=$MOMENTUM_ENABLE_SIMD +""", MOMENTUM_BUILD_IO_FBX = "OFF", MOMENTUM_ENABLE_SIMD = "ON" } } test_py = { cmd = """ pytest \ pymomentum/test/test_closest_points.py \ @@ -241,20 +221,10 @@ test_py = { cmd = """ pytorch = ">=2.4.0" [target.osx-arm64.tasks] -build_py = { cmd = """ - python setup.py build \ - --build-base build/$PIXI_ENVIRONMENT_NAME/py \ - build_ext \ - --cmake-args='\ - -DMOMENTUM_BUILD_IO_FBX=$MOMENTUM_BUILD_IO_FBX \ - -DMOMENTUM_BUILD_EXAMPLES=OFF \ - -DMOMENTUM_BUILD_TESTING=ON \ - -DMOMENTUM_ENABLE_SIMD=$MOMENTUM_ENABLE_SIMD \ - -DMOMENTUM_USE_SYSTEM_GOOGLETEST=ON \ - -DMOMENTUM_USE_SYSTEM_PYBIND11=ON \ - -DMOMENTUM_USE_SYSTEM_RERUN_CPP_SDK=ON \ - ' - """, env = { MOMENTUM_BUILD_IO_FBX = "OFF", MOMENTUM_ENABLE_SIMD = "ON" } } +build_py = { cmd = "pip install . -vv", env = { CMAKE_ARGS = """ + -DMOMENTUM_BUILD_IO_FBX=$MOMENTUM_BUILD_IO_FBX \ + -DMOMENTUM_ENABLE_SIMD=$MOMENTUM_ENABLE_SIMD +""", MOMENTUM_BUILD_IO_FBX = "OFF", MOMENTUM_ENABLE_SIMD = "ON" } } test_py = { cmd = """ pytest \ pymomentum/test/test_closest_points.py \ diff --git a/pymomentum/CMakeLists.txt b/pymomentum/CMakeLists.txt index 2dbd4c90..2f94d988 100644 --- a/pymomentum/CMakeLists.txt +++ b/pymomentum/CMakeLists.txt @@ -187,3 +187,10 @@ if(MOMENTUM_BUILD_TESTING) LINK_LIBRARIES tensor_utility ) endif() + +#=============================================================================== +# Install +#=============================================================================== + +get_property(pymomentum_targets_to_install GLOBAL PROPERTY PYMOMENTUM_TARGETS_TO_INSTALL) +install(TARGETS ${pymomentum_targets_to_install} DESTINATION pymomentum) diff --git a/pymomentum/__init__.py b/pymomentum/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..5df67a91 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,55 @@ +[build-system] +requires = ["scikit-build-core", "pybind11"] +build-backend = "scikit_build_core.build" + +[project] +name = "pymomentum" +version = "0.1.0" +description = "A library providing foundational algorithms for human kinematic motion and numerical optimization solvers to apply human motion in various applications" +readme = "README.md" +requires-python = ">=3.10" +authors = [ + { name = "Meta Reality Labs Research", email = "jeongseok@meta.com" }, +] +classifiers = ["License :: OSI Approved :: MIT License"] +dependencies = [] + +[project.urls] +Homepage = "https://github.com/facebookincubator/momentum" + +[tool.scikit-build] +build-dir = "build/{wheel_tag}" +cmake.args = [ + "-DBUILD_SHARED_LIBS=OFF", + "-DMOMENTUM_BUILD_PYMOMENTUM=ON", + "-DMOMENTUM_BUILD_EXAMPLES=OFF", + "-DMOMENTUM_BUILD_TESTING=ON", + "-DMOMENTUM_USE_SYSTEM_GOOGLETEST=ON", + "-DMOMENTUM_USE_SYSTEM_PYBIND11=ON", + "-DMOMENTUM_USE_SYSTEM_RERUN_CPP_SDK=ON", +] +minimum-version = "0.10" +sdist.exclude = [ + "cmake/", + "test/", + "*.h", + "*.cpp", + "*.cmake", + ".clang-format", + "CMakeLists.txt", +] +wheel.exclude = ["geometry_test_helper.*"] +wheel.py-api = "cp310" + +[[tool.scikit-build.overrides]] +if.platform-system = "^win32" +cmake.args = [ + "-DBUILD_SHARED_LIBS=OFF", + "-G Visual Studio 17 2022", + "-DMOMENTUM_BUILD_PYMOMENTUM=ON", + "-DMOMENTUM_BUILD_EXAMPLES=OFF", + "-DMOMENTUM_BUILD_TESTING=ON", + "-DMOMENTUM_USE_SYSTEM_GOOGLETEST=ON", + "-DMOMENTUM_USE_SYSTEM_PYBIND11=ON", + "-DMOMENTUM_USE_SYSTEM_RERUN_CPP_SDK=ON", +] diff --git a/setup.py b/setup.py deleted file mode 100644 index 6429e128..00000000 --- a/setup.py +++ /dev/null @@ -1,127 +0,0 @@ -#!/usr/bin/env python3 -# Copyright (c) Meta Platforms, Inc. and affiliates. -# -# This source code is licensed under the MIT license found in the -# LICENSE file in the root directory of this source tree. - -import os -import re -import shutil -import subprocess -import sys - -from setuptools import Extension, find_packages, setup -from setuptools.command.build_ext import build_ext - -ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) - - -class CMakeExtension(Extension): - def __init__(self, name, sourcedir=""): - Extension.__init__(self, name, sources=[]) - self.sourcedir = os.path.abspath(sourcedir) - - -class CMakeBuild(build_ext): - user_options = build_ext.user_options + [ - ("cmake-args=", None, "Additional CMake arguments") - ] - - def initialize_options(self): - super().initialize_options() - self.cmake_args = None - - def finalize_options(self): - super().finalize_options() - - def run(self): - try: - subprocess.check_output(["cmake", "--version"]) - except OSError: - raise RuntimeError("CMake is not available.") - super().run() - - def build_extension(self, ext): - extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.name))) - - if not extdir.endswith(os.path.sep): - extdir += os.path.sep - - cfg = "Debug" if self.debug else "Release" - - cmake_args = [ - f"-DCMAKE_BUILD_TYPE={cfg}", - f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={extdir}", - f"-DBUILD_SHARED_LIBS=OFF", - f"-DMOMENTUM_BUILD_PYMOMENTUM=ON", - f"-DPYTHON_EXECUTABLE={sys.executable}", - ] - - # Parse additional CMake arguments - if self.cmake_args: - cmake_args += self.cmake_args.split() - - build_args = ["--target", os.path.basename(ext.name)] - - if "CMAKE_ARGS" in os.environ: - cmake_args += [item for item in os.environ["CMAKE_ARGS"].split(" ") if item] - - # Default to Ninja - if self.compiler.compiler_type == "msvc": - cmake_args += ["-G Visual Studio 17 2022"] - else: - cmake_args += ["-G Ninja"] - - if sys.platform.startswith("darwin"): - # Cross-compile support for macOS - respect ARCHFLAGS if set - archs = re.findall(r"-arch (\S+)", os.environ.get("ARCHFLAGS", "")) - if archs: - cmake_args += ["-DCMAKE_OSX_ARCHITECTURES={}".format(";".join(archs))] - - if not os.path.exists(self.build_temp): - os.makedirs(self.build_temp) - subprocess.check_call( - ["cmake", ext.sourcedir] + cmake_args, cwd=self.build_temp - ) - subprocess.check_call( - ["cmake", "--build", "."] + build_args, cwd=self.build_temp - ) - - # After building, copy the shared library to pymomentum/ - target_dir = os.path.join(ROOT_DIR, "pymomentum") - if not os.path.exists(target_dir): - os.makedirs(target_dir) - shutil.copy(self.get_ext_fullpath(ext.name), target_dir) - - -def main(): - with open(os.path.join(ROOT_DIR, "README.md"), encoding="utf-8") as f: - long_description = f.read() - - setup( - name="pymomentum", - # TODO: get version from a single source (e.g., version.txt) - version="0.1.0", - description="A library providing foundational algorithms for human kinematic motion and numerical optimization solvers to apply human motion in various applications", - long_description=long_description, - long_description_content_type="text/markdown", - url="https://github.com/facebookincubator/momentum", - author="Meta Reality Labs Research", - license="MIT", - install_requires=["numpy", "typing", "dataclasses"], # TODO: - python_requires=">=3.10", - packages=find_packages(), - zip_safe=False, - ext_modules=[ - CMakeExtension("geometry", sourcedir=ROOT_DIR), - CMakeExtension("quaternion", sourcedir=ROOT_DIR), - CMakeExtension("skel_state", sourcedir=ROOT_DIR), - ], - cmdclass={ - "build_ext": CMakeBuild, - }, - ) - - -if __name__ == "__main__": - main()