-
Notifications
You must be signed in to change notification settings - Fork 1
/
pyperscan.nix
131 lines (109 loc) · 3.81 KB
/
pyperscan.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
inputs:
{ lib
, callPackage
, stdenv
, makeRustPlatform
, rustPlatform
, cargo
, rustc
, maturin
, cargo-llvm-cov
, system
, libiconv
, boost
, hyperscan
, vectorscan
, python3
, util-linux
, ruff
, vendorHyperscan ? false
, vendorVectorscan ? false
, coverage ? false
}:
assert vendorHyperscan -> !vendorVectorscan;
assert vendorVectorscan -> !vendorHyperscan;
let
inherit (lib) optional optionals optionalString;
craneLib = inputs.crane.lib.${system};
cppFilter = path: _type: builtins.match ".*/hyperscan-sys/(wrapper.h|hyperscan|vectorscan).*$" path != null;
pyFilter = path: _type: builtins.match ".*pyi?$|.*/py.typed$|.*/pyproject.toml|.*/README.md$|.*/LICENSE" path != null;
testFilter = p: t: builtins.match ".*/(tests|tests/.*\.py|examples|examples/.*\.py)$" p != null;
sourceFilter = path: type:
(cppFilter path type) || (craneLib.filterCargoSources path type);
vendor = vendorHyperscan || vendorVectorscan;
buildInputs = [
python3
] ++ optional stdenv.isDarwin libiconv
++ optional vendor boost
++ optional (system == "x86_64-linux") hyperscan
++ optional (system != "x86_64-linux") vectorscan;
src = lib.cleanSourceWith {
src = craneLib.path ./.;
filter = p: t: (pyFilter p t) || (sourceFilter p t);
};
commonArgs = {
inherit src buildInputs;
# python package build will recompile PyO3 when built with maturin
# as there are different build features are used for the extension module
# and the standalone dylib which is used for tests and benchmarks
doNotLinkInheritedArtifacts = true;
};
# Build *just* the cargo dependencies, so we can reuse
# all of that work (e.g. via cachix) when running in CI
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
# Build the actual crate itself, reusing the dependency
# artifacts from above.
libpyperscan = craneLib.buildPackage (commonArgs // {
inherit cargoArtifacts;
nativeBuildInputs = with rustPlatform; [
bindgenHook
];
});
cargo_toml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
drv = python3.pkgs.buildPythonPackage {
pname = "pyperscan"
+ optionalString vendorHyperscan "-hyperscan"
+ optionalString vendorVectorscan "-vectorscan"
+ optionalString coverage "-coverage";
format = "pyproject";
inherit src buildInputs;
inherit (cargo_toml.workspace.package) version;
# python package build will recompile PyO3 when built with maturin
# as there are different build features are used for the extension module
# and the standalone dylib which is used for tests and benchmarks
doNotLinkInheritedArtifacts = true;
dontUseCmakeConfigure = true;
strictDeps = true;
doCheck = false;
cargoDeps = rustPlatform.importCargoLock {
lockFile = ./Cargo.lock;
};
maturinBuildFlags =
(optionals vendorHyperscan [ "-F hyperscan" ])
++ (optionals (vendorVectorscan) [ "-F vectorscan" ]);
nativeBuildInputs =
let
rustHooks = callPackage "${inputs.nixpkgs}/pkgs/build-support/rust/hooks" { };
in
[
rustPlatform.cargoSetupHook
rustPlatform.bindgenHook
(rustHooks.maturinBuildHook.override { pkgsHostTarget = { inherit maturin cargo rustc; }; })
] ++ optional (vendor && stdenv.isLinux) util-linux
++ optional coverage cargo-llvm-cov;
preConfigure = optionalString coverage ''
source <(cargo llvm-cov show-env --export-prefix)
'';
passthru = {
inherit cargoArtifacts craneLib commonArgs libpyperscan;
shared = drv;
hyperscan = drv.override { vendorHyperscan = true; };
vectorscan = drv.override { vendorVectorscan = true; };
tests = import ./tests.nix {
inherit lib stdenv system makeRustPlatform rustPlatform pyFilter testFilter cargo-llvm-cov python3 ruff;
inherit (inputs) fenix;
};
};
};
in
drv