1{ lib
2, stdenv
3, buildPythonPackage
4, fetchFromGitHub
5, setuptools
6, setuptools-scm
7, cocotb-bus
8, find-libpython
9, pytestCheckHook
10, swig
11, verilog
12}:
13
14buildPythonPackage rec {
15 pname = "cocotb";
16 version = "1.7.2";
17
18 # pypi source doesn't include tests
19 src = fetchFromGitHub {
20 owner = "cocotb";
21 repo = "cocotb";
22 rev = "refs/tags/v${version}";
23 hash = "sha256-gLOYwljqnYkGsdbny7+f93QgroLBaLLnDBRpoCe8uEg=";
24 };
25
26 nativeBuildInputs = [ setuptools-scm ];
27
28 buildInputs = [ setuptools find-libpython ];
29
30 postPatch = ''
31 patchShebangs bin/*.py
32
33 # POSIX portability (TODO: upstream this)
34 for f in \
35 cocotb/share/makefiles/Makefile.* \
36 cocotb/share/makefiles/simulators/Makefile.*
37 do
38 substituteInPlace $f --replace 'shell which' 'shell command -v'
39 done
40
41 # remove circular dependency cocotb-bus from setup.py
42 substituteInPlace setup.py --replace "'cocotb-bus<1.0'" ""
43 '' + lib.optionalString stdenv.isDarwin ''
44 # disable lto on darwin
45 # https://github.com/NixOS/nixpkgs/issues/19098
46 substituteInPlace cocotb_build_libs.py --replace "-flto" ""
47 '';
48
49 patches = [
50 # Fix "can't link with bundle (MH_BUNDLE) only dylibs (MH_DYLIB) file" error
51 ./0001-Patch-LDCXXSHARED-for-macOS-along-with-LDSHARED.patch
52 ];
53
54 nativeCheckInputs = [ cocotb-bus pytestCheckHook swig verilog ];
55 preCheck = ''
56 export PATH=$out/bin:$PATH
57 mv cocotb cocotb.hidden
58 '';
59
60 pythonImportsCheck = [ "cocotb" ];
61
62 meta = with lib; {
63 description = "Coroutine based cosimulation library for writing VHDL and Verilog testbenches in Python";
64 homepage = "https://github.com/cocotb/cocotb";
65 license = licenses.bsd3;
66 maintainers = with maintainers; [ matthuszagh ];
67 };
68}