|
| 1 | +# Copyright 2025 Ciel 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 | + stdenv, |
| 39 | + fetchFromGitHub, |
| 40 | + fetchpatch, |
| 41 | + autoconf, |
| 42 | + bison, |
| 43 | + bzip2, |
| 44 | + flex, |
| 45 | + gperf, |
| 46 | + ncurses, |
| 47 | + perl, |
| 48 | + python3, |
| 49 | + readline, |
| 50 | + zlib, |
| 51 | + buildPackages, |
| 52 | + version ? "s20250103-60-gdb82380ce", |
| 53 | + rev ? "db82380cecf9943fcc397818e6899b7146442127", |
| 54 | + sha256 ? "sha256-0WA/SrHINtwv0UKX7Jjb8sjnXBfRIBoErK+MrdBwErg=", |
| 55 | +}: |
| 56 | + |
| 57 | +stdenv.mkDerivation rec { |
| 58 | + pname = "iverilog"; |
| 59 | + inherit version; |
| 60 | + |
| 61 | + src = fetchFromGitHub { |
| 62 | + owner = "steveicarus"; |
| 63 | + repo = "iverilog"; |
| 64 | + rev = |
| 65 | + if rev == null |
| 66 | + then "v${lib.replaceStrings [ "." ] [ "_" ] version}" |
| 67 | + else rev; |
| 68 | + inherit sha256; |
| 69 | + }; |
| 70 | + |
| 71 | + nativeBuildInputs = [ |
| 72 | + autoconf |
| 73 | + bison |
| 74 | + flex |
| 75 | + gperf |
| 76 | + ]; |
| 77 | + |
| 78 | + CC_FOR_BUILD = "${buildPackages.stdenv.cc}/bin/cc"; |
| 79 | + CXX_FOR_BUILD = "${buildPackages.stdenv.cc}/bin/c++"; |
| 80 | + |
| 81 | + patches = [ |
| 82 | + ]; |
| 83 | + |
| 84 | + buildInputs = [ |
| 85 | + bzip2 |
| 86 | + ncurses |
| 87 | + readline |
| 88 | + zlib |
| 89 | + ]; |
| 90 | + |
| 91 | + preConfigure = "sh autoconf.sh"; |
| 92 | + |
| 93 | + enableParallelBuilding = true; |
| 94 | + |
| 95 | + env = lib.optionalAttrs stdenv.hostPlatform.isDarwin { |
| 96 | + NIX_CFLAGS_COMPILE = "-Wno-error=implicit-function-declaration"; |
| 97 | + }; |
| 98 | + |
| 99 | + # NOTE(jleightcap): the `make check` target only runs a "Hello, World"-esque sanity check. |
| 100 | + # the tests in the doInstallCheck phase run a full regression test suite. |
| 101 | + # however, these tests currently fail upstream on aarch64 |
| 102 | + # (see https://github.com/steveicarus/iverilog/issues/917) |
| 103 | + # so disable the full suite for now. |
| 104 | + doCheck = true; |
| 105 | + doInstallCheck = !stdenv.hostPlatform.isAarch64; |
| 106 | + |
| 107 | + nativeInstallCheckInputs = [ |
| 108 | + perl |
| 109 | + (python3.withPackages ( |
| 110 | + pp: with pp; [ |
| 111 | + docopt |
| 112 | + ] |
| 113 | + )) |
| 114 | + ]; |
| 115 | + |
| 116 | + installCheckPhase = '' |
| 117 | + runHook preInstallCheck |
| 118 | + export PATH="$PATH:$out/bin" |
| 119 | + sh .github/test.sh |
| 120 | + runHook postInstallCheck |
| 121 | + ''; |
| 122 | + |
| 123 | + meta = with lib; { |
| 124 | + description = "Icarus Verilog compiler"; |
| 125 | + homepage = "https://steveicarus.github.io/iverilog"; |
| 126 | + license = with licenses; [ |
| 127 | + gpl2Plus |
| 128 | + lgpl21Plus |
| 129 | + ]; |
| 130 | + maintainers = with maintainers; [ thoughtpolice ]; |
| 131 | + platforms = platforms.all; |
| 132 | + }; |
| 133 | +} |
0 commit comments