1{ lib 2, fetchPypi 3, rustPlatform 4, stdenv 5, Security 6, writeShellScriptBin 7, buildPythonPackage 8, setuptools-scm 9, appdirs 10, milksnake 11, pyyaml 12, hypothesis 13, jinja2 14, mock 15, pytestCheckHook 16}: 17let 18 pname = "cmsis-pack-manager"; 19 version = "0.4.0"; 20 21 src = fetchPypi { 22 inherit pname version; 23 sha256 = "sha256-NeUG6PFI2eTwq5SNtAB6ZMA1M3z1JmMND29V9/O5sgw="; 24 }; 25 26 native = rustPlatform.buildRustPackage { 27 name = "${pname}-${version}-native"; 28 29 inherit src; 30 31 buildInputs = lib.optionals stdenv.isDarwin [ 32 Security 33 ]; 34 35 sourceRoot = "${pname}-${version}/rust"; 36 cargoLock.lockFile = ./Cargo.lock; 37 38 postPatch = '' 39 cp ${./Cargo.lock} Cargo.lock 40 ''; 41 42 cargoBuildFlags = [ "--lib" ]; 43 }; 44in 45buildPythonPackage rec { 46 inherit pname version src; 47 48 # The cargo build is already run in a separate derivation 49 postPatch = '' 50 substituteInPlace setup.py \ 51 --replace "'cargo', 'build'," "'true'," 52 ''; 53 54 nativeBuildInputs = [ setuptools-scm ]; 55 propagatedBuildInputs = [ appdirs milksnake pyyaml ]; 56 57 checkInputs = [ hypothesis jinja2 mock pytestCheckHook ]; 58 59 preBuild = '' 60 mkdir -p rust/target/release/deps 61 ln -s ${native}/lib/libcmsis_cffi${stdenv.hostPlatform.extensions.sharedLibrary} rust/target/release/deps/ 62 ''; 63 64 preCheck = '' 65 # Otherwise the test uses a dummy library (missing all symbols) 66 ln -sf ../build/lib/cmsis_pack_manager/_native__lib${stdenv.hostPlatform.extensions.sharedLibrary} cmsis_pack_manager/_native__lib${stdenv.hostPlatform.extensions.sharedLibrary} 67 ''; 68 69 pythonImportsCheck = [ "cmsis_pack_manager" ]; 70 71 meta = with lib; { 72 description = "A Rust and Python module for handling CMSIS Pack files"; 73 homepage = "https://github.com/pyocd/cmsis-pack-manager"; 74 license = licenses.asl20; 75 maintainers = with maintainers; [ frogamic sbruder ]; 76 }; 77}