summary refs log tree commit diff
path: root/pkgs/development/python-modules/cmsis-pack-manager/default.nix
blob: 92ed4362ece85f1e1f535c2ab92693d140c3c3bf (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
{ lib
, fetchPypi
, rustPlatform
, stdenv
, Security
, writeShellScriptBin
, buildPythonPackage
, setuptools-scm
, appdirs
, milksnake
, pyyaml
, hypothesis
, jinja2
, mock
, pytestCheckHook
}:
let
  pname = "cmsis-pack-manager";
  version = "0.4.0";

  src = fetchPypi {
    inherit pname version;
    hash = "sha256-NeUG6PFI2eTwq5SNtAB6ZMA1M3z1JmMND29V9/O5sgw=";
  };

  native = rustPlatform.buildRustPackage {
    name = "${pname}-${version}-native";

    inherit src;

    buildInputs = lib.optionals stdenv.isDarwin [
      Security
    ];

    sourceRoot = "${pname}-${version}/rust";
    cargoLock.lockFile = ./Cargo.lock;

    postPatch = ''
      cp ${./Cargo.lock} Cargo.lock
    '';

    cargoBuildFlags = [ "--lib" ];
  };
in
buildPythonPackage rec {
  inherit pname version src;

  # The cargo build is already run in a separate derivation
  postPatch = ''
    substituteInPlace setup.py \
        --replace "'cargo', 'build'," "'true',"
  '';

  nativeBuildInputs = [ setuptools-scm ];
  propagatedBuildInputs = [ appdirs milksnake pyyaml ];

  nativeCheckInputs = [ hypothesis jinja2 mock pytestCheckHook ];

  preBuild = ''
    mkdir -p rust/target/release/deps
    ln -s ${native}/lib/libcmsis_cffi${stdenv.hostPlatform.extensions.sharedLibrary} rust/target/release/deps/
  '';

  preCheck = ''
    # Otherwise the test uses a dummy library (missing all symbols)
    ln -sf ../build/lib/cmsis_pack_manager/_native__lib${stdenv.hostPlatform.extensions.sharedLibrary} cmsis_pack_manager/_native__lib${stdenv.hostPlatform.extensions.sharedLibrary}
  '';

  pythonImportsCheck = [ "cmsis_pack_manager" ];

  meta = with lib; {
    description = "A Rust and Python module for handling CMSIS Pack files";
    homepage = "https://github.com/pyocd/cmsis-pack-manager";
    license = licenses.asl20;
    maintainers = with maintainers; [ frogamic sbruder ];
    broken = stdenv.isDarwin;
  };
}