Skip to content

Commit 0f73b76

Browse files
python3Packages.piqp: init at 0.4.2 (NixOS#333273)
2 parents fb250e4 + 2046298 commit 0f73b76

File tree

5 files changed

+213
-2
lines changed

5 files changed

+213
-2
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
lib,
3+
stdenv,
4+
fetchFromGitHub,
5+
cmake,
6+
static ? stdenv.hostPlatform.isStatic,
7+
}:
8+
9+
stdenv.mkDerivation rec {
10+
pname = "cpu_features";
11+
version = "0.9.0";
12+
13+
outputs = [
14+
"out"
15+
"dev"
16+
];
17+
18+
src = fetchFromGitHub {
19+
owner = "google";
20+
repo = "cpu_features";
21+
rev = "v${version}";
22+
hash = "sha256-uXN5crzgobNGlLpbpuOxR+9QVtZKrWhxC/UjQEakJwk=";
23+
};
24+
25+
nativeBuildInputs = [ cmake ];
26+
27+
cmakeFlags = [ "-DBUILD_SHARED_LIBS=${if static then "OFF" else "ON"}" ];
28+
29+
meta = with lib; {
30+
description = "A cross platform C99 library to get cpu features at runtime";
31+
homepage = "https://github.com/google/cpu_features";
32+
license = licenses.asl20;
33+
platforms = platforms.all;
34+
maintainers = with maintainers; [ renesat ];
35+
};
36+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
{
2+
lib,
3+
fetchFromGitHub,
4+
buildPythonPackage,
5+
pytestCheckHook,
6+
stdenv,
7+
pythonOlder,
8+
setuptools,
9+
cmake,
10+
ninja,
11+
wheel,
12+
matio,
13+
eigen,
14+
gtest,
15+
cpu_features,
16+
pybind11,
17+
python,
18+
numpy,
19+
scipy,
20+
}:
21+
buildPythonPackage rec {
22+
pname = "piqp";
23+
version = "0.4.2";
24+
pyproject = true;
25+
26+
disabled = pythonOlder "3.7";
27+
28+
src = fetchFromGitHub {
29+
owner = "PREDICT-EPFL";
30+
repo = "piqp";
31+
rev = "refs/tags/v${version}";
32+
hash = "sha256-/lADjg4NyDdV9yeYBW2gbPydY8TfV247B/dI/ViRVlI=";
33+
};
34+
35+
postPatch =
36+
let
37+
# E.g. 3.11.2 -> "311"
38+
pythonVersionMajorMinor =
39+
with lib.versions;
40+
"${major python.pythonVersion}${minor python.pythonVersion}";
41+
42+
# E.g. "linux-aarch64"
43+
platform = with stdenv.hostPlatform.parsed; "${kernel.name}-${cpu.name}";
44+
in
45+
''
46+
build="build/temp.${platform}-cpython-${pythonVersionMajorMinor}/${pname}.${pname}"
47+
mkdir -p $build/_deps
48+
ln -s ${cpu_features.src} $build/_deps/cpu_features-src
49+
'';
50+
51+
patches = [ ./use-nix-packages.patch ];
52+
53+
build-system = [
54+
setuptools
55+
cmake
56+
ninja
57+
wheel
58+
];
59+
60+
buildInputs = [
61+
matio
62+
eigen
63+
gtest
64+
pybind11
65+
];
66+
67+
dontUseCmakeConfigure = true;
68+
69+
pythonImportsCheck = [ "piqp" ];
70+
71+
nativeCheckInputs = [
72+
pytestCheckHook
73+
numpy
74+
scipy
75+
];
76+
77+
meta = with lib; {
78+
description = "A Proximal Interior Point Quadratic Programming solver";
79+
homepage = "https://github.com/PREDICT-EPFL/piqp";
80+
license = licenses.bsd2;
81+
maintainers = with maintainers; [ renesat ];
82+
};
83+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
diff --git a/CMakeLists.txt b/CMakeLists.txt
2+
index ea1da5e..0a6f096 100644
3+
--- a/CMakeLists.txt
4+
+++ b/CMakeLists.txt
5+
@@ -100,7 +100,7 @@ if (BUILD_PYTHON_INTERFACE OR BUILD_MATLAB_INTERFACE)
6+
include(FetchContent)
7+
FetchContent_Declare(
8+
cpu_features
9+
- URL https://github.com/google/cpu_features/archive/refs/tags/v0.9.0.zip
10+
+ DOWNLOAD_COMMAND true
11+
)
12+
set(BUILD_SHARED_LIBS_COPY ${BUILD_SHARED_LIBS})
13+
set(BUILD_SHARED_LIBS OFF)
14+
diff --git a/interfaces/c/tests/CMakeLists.txt b/interfaces/c/tests/CMakeLists.txt
15+
index 010f038..c8f9ec4 100644
16+
--- a/interfaces/c/tests/CMakeLists.txt
17+
+++ b/interfaces/c/tests/CMakeLists.txt
18+
@@ -13,18 +13,8 @@ if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
19+
endif()
20+
21+
# Google Test
22+
-include(FetchContent)
23+
-FetchContent_Declare(
24+
- googletest
25+
- URL https://github.com/google/googletest/archive/86add13493e5c881d7e4ba77fb91c1f57752b3a4.zip
26+
-)
27+
-# For Windows: Prevent overriding the parent project's compiler/linker settings
28+
-set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
29+
-FetchContent_GetProperties(googletest)
30+
-if(NOT googletest_POPULATED)
31+
- FetchContent_Populate(googletest)
32+
- add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR} EXCLUDE_FROM_ALL)
33+
-endif()
34+
+# Use find_package to use the gtest package provided by Nix
35+
+find_package(GTest REQUIRED)
36+
37+
enable_testing()
38+
39+
diff --git a/interfaces/python/CMakeLists.txt b/interfaces/python/CMakeLists.txt
40+
index f7415dc..885aeff 100644
41+
--- a/interfaces/python/CMakeLists.txt
42+
+++ b/interfaces/python/CMakeLists.txt
43+
@@ -14,19 +14,7 @@ if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
44+
endif()
45+
46+
# Find pybind11
47+
-include(FetchContent)
48+
-FetchContent_Declare(
49+
- pybind11
50+
- URL https://github.com/pybind/pybind11/archive/refs/tags/v2.12.0.zip
51+
-)
52+
-FetchContent_MakeAvailable(pybind11)
53+
-
54+
-# detect arm64 cross compilation on macOS
55+
-if(DEFINED ENV{_PYTHON_HOST_PLATFORM})
56+
- if($ENV{_PYTHON_HOST_PLATFORM} MATCHES "arm64")
57+
- set(CMAKE_SYSTEM_PROCESSOR "arm64")
58+
- endif()
59+
-endif()
60+
+find_package(pybind11 REQUIRED)
61+
62+
# add instruction set detection on x86/amd64
63+
pybind11_add_module(instruction_set src/instruction_set.cpp)
64+
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
65+
index d11bd37..2275a62 100644
66+
--- a/tests/CMakeLists.txt
67+
+++ b/tests/CMakeLists.txt
68+
@@ -14,18 +14,8 @@ if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
69+
endif()
70+
71+
# Google Test
72+
-include(FetchContent)
73+
-FetchContent_Declare(
74+
- googletest
75+
- URL https://github.com/google/googletest/archive/86add13493e5c881d7e4ba77fb91c1f57752b3a4.zip
76+
-)
77+
-# For Windows: Prevent overriding the parent project's compiler/linker settings
78+
-set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
79+
-FetchContent_GetProperties(googletest)
80+
-if(NOT googletest_POPULATED)
81+
- FetchContent_Populate(googletest)
82+
- add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR} EXCLUDE_FROM_ALL)
83+
-endif()
84+
+# Use find_package to use the gtest package provided by Nix
85+
+find_package(GTest REQUIRED)
86+
87+
enable_testing()
88+

pkgs/development/python-modules/qpsolvers/default.nix

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
quadprog,
1818
scs,
1919
highspy,
20+
piqp,
2021
}:
2122
buildPythonPackage rec {
2223
pname = "qpsolvers";
@@ -49,7 +50,7 @@ buildPythonPackage rec {
4950
highs = [ highspy ];
5051
# mosek = [ cvxopt mosek ];
5152
osqp = [ osqp ];
52-
# piqp = [ piqp ];
53+
piqp = [ piqp ];
5354
# proxqp = [ proxsuite ];
5455
# qpalm = [ qpalm ];
5556
quadprog = [ quadprog ];
@@ -60,9 +61,10 @@ buildPythonPackage rec {
6061
clarabel
6162
cvxopt
6263
daqp
63-
osqp # piqp proxqp qpalm
6464
ecos
6565
highs
66+
osqp
67+
piqp # proxqp qpalm
6668
quadprog
6769
scs
6870
];

pkgs/top-level/python-packages.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10149,6 +10149,8 @@ self: super: with self; {
1014910149

1015010150
pipetools = callPackage ../development/python-modules/pipetools { };
1015110151

10152+
piqp = callPackage ../development/python-modules/piqp { };
10153+
1015210154
pg8000 = callPackage ../development/python-modules/pg8000 { };
1015310155

1015410156
pgcli = callPackage ../development/python-modules/pgcli { };

0 commit comments

Comments
 (0)