diff --git a/CMakeLists.txt b/CMakeLists.txt index ecdf4b5..9ec5b83 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 4.0) -project(autoopt) +project(slopefit) set(CMAKE_CXX_STANDARD 23) @@ -15,17 +15,15 @@ execute_process( OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE nanobind_ROOT) find_package(nanobind CONFIG REQUIRED) -file(GLOB_RECURSE SOURCES src/*.cpp) +file(GLOB_RECURSE SOURCES lib/*.cpp) add_library(autoopt STATIC ${SOURCES}) target_include_directories(autoopt PUBLIC include) target_link_libraries(autoopt PUBLIC Eigen3::Eigen) -install(DIRECTORY include/autoopt DESTINATION include) - -nanobind_add_module(slopefit NOMINSIZE pysrc/module.cpp) +nanobind_add_module(slopefit NOMINSIZE src/module.cpp) target_link_libraries(slopefit PRIVATE autoopt) -install(TARGETS slopefit DESTINATION lib/python3.13/site-packages) +install(TARGETS slopefit DESTINATION slopefit) # add tests if gtest is found find_library(GTestPackage gtest QUIET) diff --git a/README.md b/README.md new file mode 100644 index 0000000..098598b --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# slopefit diff --git a/build.nix b/build.nix new file mode 100644 index 0000000..046235d --- /dev/null +++ b/build.nix @@ -0,0 +1,27 @@ +{ + cmake, + ninja, + eigen, + python3Packages, +}: +python3Packages.buildPythonPackage { + pname = "slopefit"; + version = "0.1.0"; + pyproject = true; + + buildInputs = [ eigen ]; + + nativeBuildInputs = [ + cmake + ninja + python3Packages.scikit-build-core + python3Packages.nanobind + ]; + + buildPhase = '' + cd .. + pypaBuildPhase + ''; + + src = ./.; +} diff --git a/flake.nix b/flake.nix index f8689c2..36cb9f4 100644 --- a/flake.nix +++ b/flake.nix @@ -1,5 +1,5 @@ { - description = "auto-opt-cpp"; + description = "slopefit"; inputs = { nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; @@ -16,66 +16,24 @@ system: let pkgs = nixpkgs.legacyPackages.${system}; - pkg = - { - stdenv, - cmake, - ninja, - lib, - eigen, - gtest, - python313, - python313Packages, - withTests ? false, - }: - let - fs = lib.fileset; - in - stdenv.mkDerivation { - pname = "autoopt-cpp"; - version = "0.1.0"; - - src = fs.toSource { - root = ./.; - fileset = fs.unions [ - ./include - ./CMakeLists.txt - ./tests - ./src - ./pysrc - ]; - }; - - buildInputs = lib.optionals withTests [ gtest ]; - - nativeBuildInputs = [ - cmake - ninja - eigen - (python313.withPackages ( - ps: with ps; [ - nanobind - matplotlib - numpy - ] - )) - ]; - }; + pkg = import ./build.nix; in rec { packages = rec { - autoopt-cpp = pkgs.callPackage pkg { }; - autoopt-cpp-with-tests = pkgs.callPackage pkg { withTests = true; }; - default = autoopt-cpp; + slopefit = pkgs.callPackage pkg { }; + slopefit-with-tests = pkgs.callPackage pkg { }; + default = slopefit; }; devShells = { default = pkgs.mkShell { inputsFrom = [ - packages.autoopt-cpp-with-tests + packages.slopefit-with-tests ]; + buildInputs = [ pkgs.python3Packages.pip ]; + shellHook = '' - echo "Development shell for autoopt-cpp" + echo "Development shell for slopefit" ''; }; }; diff --git a/src/interface.cpp b/lib/interface.cpp similarity index 100% rename from src/interface.cpp rename to lib/interface.cpp diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..d84817e --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,34 @@ +[build-system] +requires = ["scikit-build-core>=0.11", "nanobind"] +build-backend = "scikit_build_core.build" + + +[tool.scikit-build] +# Protect the configuration against future changes in scikit-build-core +minimum-version = "0.4" + +# Setuptools-style build caching in a local directory +build-dir = "build/{wheel_tag}" + +# Build stable ABI wheels for CPython 3.12+ +wheel.py-api = "cp312" + +[project] +name = "slopefit" +version = "0.1.0" +authors = [ + { name="Valentin Leon Stöcker", email="valentin@stoeckermail.de" }, +] +description = "fit conic sections" +readme = "README.md" +requires-python = ">=3.9" +classifiers = [ + "Programming Language :: Python :: 3", + "Operating System :: OS Independent", +] +license = "MIT" + +[project.urls] +Homepage = "https://gitea.valentinstoecker.de/vls/slopfit" +Issues = "https://gitea.valentinstoecker.de/vls/slopfit/issues" + diff --git a/pysrc/module.cpp b/src/module.cpp similarity index 100% rename from pysrc/module.cpp rename to src/module.cpp