1{
2 lib,
3 buildPythonPackage,
4 capstone,
5 stdenv,
6 setuptools,
7 pythonAtLeast,
8}:
9
10buildPythonPackage rec {
11 pname = "capstone";
12 version = lib.getVersion capstone;
13 format = "setuptools";
14
15 # distutils usage
16 disabled = pythonAtLeast "3.12";
17
18 src = capstone.src;
19 sourceRoot = "${src.name}/bindings/python";
20
21 # libcapstone.a is not built with BUILD_SHARED_LIBS. For some reason setup.py
22 # checks if it exists but it is not really needed. Most likely a bug in setup.py.
23 postPatch = ''
24 ln -s ${capstone}/lib/libcapstone${stdenv.targetPlatform.extensions.sharedLibrary} prebuilt/
25 touch prebuilt/libcapstone${stdenv.targetPlatform.extensions.staticLibrary}
26 substituteInPlace setup.py --replace manylinux1 manylinux2014
27 '';
28
29 # aarch64 only available from MacOS SDK 11 onwards, so fix the version tag.
30 # otherwise, bdist_wheel may detect "macosx_10_6_arm64" which doesn't make sense.
31 setupPyBuildFlags = lib.optionals (stdenv.isDarwin && stdenv.isAarch64) [
32 "--plat-name"
33 "macosx_11_0"
34 ];
35
36 propagatedBuildInputs = [ setuptools ];
37
38 checkPhase = ''
39 mv capstone capstone.hidden
40 patchShebangs test_*
41 make check
42 '';
43
44 meta = with lib; {
45 homepage = "http://www.capstone-engine.org/";
46 license = licenses.bsdOriginal;
47 description = "Python bindings for Capstone disassembly engine";
48 maintainers = with maintainers; [
49 bennofs
50 ris
51 ];
52 };
53}