1{
2 lib,
3 buildPythonPackage,
4 capstone_4,
5 stdenv,
6 setuptools,
7 fetchpatch,
8}:
9
10buildPythonPackage {
11 pname = "capstone";
12 inherit (capstone_4) version src;
13
14 sourceRoot = "${capstone_4.src.name}/bindings/python";
15 patches = [
16 # Drop distutils in python binding (PR 2271)
17 (fetchpatch {
18 name = "drop-distutils-in-python-binding.patch";
19 url = "https://github.com/capstone-engine/capstone/commit/d63211e3acb64fceb8b1c4a0d804b4b027f4ef71.patch";
20 hash = "sha256-zUGeFmm3xH5dzfPJE8nnHwqwFBrsZ7w8LBJAy20/3RI=";
21 stripLen = 2;
22 })
23 ];
24
25 postPatch = ''
26 ln -s ${capstone_4}/lib/libcapstone${stdenv.targetPlatform.extensions.sharedLibrary} prebuilt/
27 ln -s ${capstone_4}/lib/libcapstone${stdenv.targetPlatform.extensions.staticLibrary} prebuilt/
28 substituteInPlace setup.py --replace manylinux1 manylinux2014
29 '';
30
31 # aarch64 only available from MacOS SDK 11 onwards, so fix the version tag.
32 # otherwise, bdist_wheel may detect "macosx_10_6_arm64" which doesn't make sense.
33 setupPyBuildFlags = lib.optionals (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64) [
34 "--plat-name"
35 "macosx_11_0"
36 ];
37
38 propagatedBuildInputs = [ setuptools ];
39
40 checkPhase = ''
41 mv capstone capstone.hidden
42 patchShebangs test_*
43 make check
44 '';
45
46 meta = with lib; {
47 homepage = "http://www.capstone-engine.org/";
48 license = licenses.bsdOriginal;
49 description = "Python bindings for Capstone disassembly engine";
50 maintainers = with maintainers; [
51 bennofs
52 ris
53 ];
54 };
55}