about summary refs log tree commit diff
path: root/pkgs/development/python-modules/unicorn/default.nix
blob: de3a0f6a3040845429c8db782e9e36b105f3af13 (plain) (blame)
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
{
  lib,
  stdenv,
  buildPythonPackage,
  setuptools,
  unicorn-emu,
}:

buildPythonPackage rec {
  pname = "unicorn";
  version = lib.getVersion unicorn-emu;
  format = "setuptools";

  src = unicorn-emu.src;

  sourceRoot = "${src.name}/bindings/python";

  patches = [
    # Python 3.12 compatibility: Drop removed `distutils` import in favor of `sysconfig`
    ./avoid-distutils-python312.patch
  ];

  prePatch = ''
    ln -s ${unicorn-emu}/lib/libunicorn.* prebuilt/
  '';

  # needed on non-x86 linux
  setupPyBuildFlags =
    lib.optionals stdenv.isLinux [
      "--plat-name"
      "linux"
    ]
    # aarch64 only available from MacOS SDK 11 onwards, so fix the version tag.
    # otherwise, bdist_wheel may detect "macosx_10_6_arm64" which doesn't make sense.
    ++ lib.optionals (stdenv.isDarwin && stdenv.isAarch64) [
      "--plat-name"
      "macosx_11_0"
    ];

  propagatedBuildInputs = [ setuptools ];

  checkPhase = ''
    runHook preCheck

    mv unicorn unicorn.hidden
    patchShebangs sample_*.py shellcode.py
    sh -e sample_all.sh

    runHook postCheck
  '';

  pythonImportsCheck = [ "unicorn" ];

  meta = with lib; {
    description = "Python bindings for Unicorn CPU emulator engine";
    homepage = "https://www.unicorn-engine.org/";
    license = licenses.gpl2Plus;
    maintainers = with maintainers; [
      bennofs
      ris
    ];
  };
}