|
| 1 | +# Copyright 2025 nix-eda Contributors |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | +# Code adapated from nixpkgs, original license follows |
| 15 | +# --- |
| 16 | +# Copyright (c) 2003-2025 Eelco Dolstra and the Nixpkgs/NixOS contributors |
| 17 | +# |
| 18 | +# Permission is hereby granted, free of charge, to any person obtaining |
| 19 | +# a copy of this software and associated documentation files (the |
| 20 | +# "Software"), to deal in the Software without restriction, including |
| 21 | +# without limitation the rights to use, copy, modify, merge, publish, |
| 22 | +# distribute, sublicense, and/or sell copies of the Software, and to |
| 23 | +# permit persons to whom the Software is furnished to do so, subject to |
| 24 | +# the following conditions: |
| 25 | +# |
| 26 | +# The above copyright notice and this permission notice shall be |
| 27 | +# included in all copies or substantial portions of the Software. |
| 28 | +# |
| 29 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 30 | +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 31 | +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 32 | +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
| 33 | +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
| 34 | +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
| 35 | +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 36 | +{ |
| 37 | + lib, |
| 38 | + buildPythonPackage, |
| 39 | + fetchFromGitHub, |
| 40 | + setuptools, |
| 41 | + setuptools-scm, |
| 42 | + cocotb-bus, |
| 43 | + find-libpython, |
| 44 | + pytestCheckHook, |
| 45 | + swig, |
| 46 | + iverilog, |
| 47 | + ghdl, |
| 48 | + stdenv, |
| 49 | + # Metadata |
| 50 | + version ? "1.9.2", |
| 51 | + sha256 ? "sha256-7KCo7g2I1rfm8QDHRm3ZKloHwjDIICnJCF8KhaFdvqY=", |
| 52 | +}: |
| 53 | +let |
| 54 | + self = buildPythonPackage rec { |
| 55 | + pname = "cocotb"; |
| 56 | + inherit version; |
| 57 | + format = "setuptools"; |
| 58 | + |
| 59 | + # pypi source doesn't include tests |
| 60 | + src = fetchFromGitHub { |
| 61 | + owner = "cocotb"; |
| 62 | + repo = "cocotb"; |
| 63 | + tag = "v${version}"; |
| 64 | + inherit sha256; |
| 65 | + }; |
| 66 | + |
| 67 | + nativeBuildInputs = [ setuptools-scm ]; |
| 68 | + |
| 69 | + buildInputs = [ setuptools ]; |
| 70 | + propagatedBuildInputs = [ find-libpython ]; |
| 71 | + |
| 72 | + postPatch = '' |
| 73 | + patchShebangs bin/*.py |
| 74 | +
|
| 75 | + # POSIX portability (TODO: upstream this) |
| 76 | + for f in \ |
| 77 | + cocotb/share/makefiles/Makefile.* \ |
| 78 | + cocotb/share/makefiles/simulators/Makefile.* |
| 79 | + do |
| 80 | + substituteInPlace $f --replace 'shell which' 'shell command -v' |
| 81 | + done |
| 82 | +
|
| 83 | + # remove circular dependency cocotb-bus from setup.py |
| 84 | + substituteInPlace setup.py --replace "'cocotb-bus<1.0'" "" |
| 85 | + ''; |
| 86 | + |
| 87 | + disabledTests = [ |
| 88 | + # https://github.com/cocotb/cocotb/commit/425e1edb8e7133f4a891f2f87552aa2748cd8d2c#diff-4df986cbc2b1a3f22172caea94f959d8fcb4a128105979e6e99c68139469960cL33 |
| 89 | + "test_cocotb" |
| 90 | + "test_cocotb_parallel" |
| 91 | + ]; |
| 92 | + |
| 93 | + nativeCheckInputs = [ |
| 94 | + cocotb-bus |
| 95 | + pytestCheckHook |
| 96 | + swig |
| 97 | + iverilog |
| 98 | + ghdl |
| 99 | + ]; |
| 100 | + |
| 101 | + preCheck = '' |
| 102 | + export PATH=$out/bin:$PATH |
| 103 | + mv cocotb cocotb.hidden |
| 104 | + ''; |
| 105 | + |
| 106 | + pythonImportsCheck = [ "cocotb" ]; |
| 107 | + |
| 108 | + meta = { |
| 109 | + changelog = "https://github.com/cocotb/cocotb/releases/tag/v${version}"; |
| 110 | + description = "Coroutine based cosimulation library for writing VHDL and Verilog testbenches in Python"; |
| 111 | + mainProgram = "cocotb-config"; |
| 112 | + homepage = "https://github.com/cocotb/cocotb"; |
| 113 | + license = lib.licenses.bsd3; |
| 114 | + broken = stdenv.hostPlatform.isDarwin; |
| 115 | + }; |
| 116 | + }; |
| 117 | +in |
| 118 | +self |
0 commit comments