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