nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at 22.05 151 lines 4.5 kB view raw
1{ stdenv 2, lib 3, abc-verifier 4, bash 5, bison 6, fetchFromGitHub 7, flex 8, libffi 9, makeWrapper 10, pkg-config 11, protobuf 12, python3 13, readline 14, symlinkJoin 15, tcl 16, verilog 17, zlib 18, yosys 19, yosys-bluespec 20, yosys-ghdl 21, yosys-symbiflow 22}: 23 24# NOTE: as of late 2020, yosys has switched to an automation robot that 25# automatically tags their repository Makefile with a new build number every 26# day when changes are committed. please MAKE SURE that the version number in 27# the 'version' field exactly matches the YOSYS_VER field in the Yosys 28# makefile! 29# 30# if a change in yosys isn't yet available under a build number like this (i.e. 31# it was very recently merged, within an hour), wait a few hours for the 32# automation robot to tag the new version, like so: 33# 34# https://github.com/YosysHQ/yosys/commit/71ca9a825309635511b64b3ec40e5e5e9b6ad49b 35# 36# note that while most nix packages for "unstable versions" use a date-based 37# version scheme, synchronizing the nix package version here with the unstable 38# yosys version number helps users report better bugs upstream, and is 39# ultimately less confusing than using dates. 40 41let 42 43 # Provides a wrapper for creating a yosys with the specifed plugins preloaded 44 # 45 # Example: 46 # 47 # my_yosys = yosys.withPlugins (with yosys.allPlugins; [ 48 # fasm 49 # bluespec 50 # ]); 51 withPlugins = plugins: 52 let 53 paths = lib.closePropagation plugins; 54 module_flags = with builtins; concatStringsSep " " 55 (map (n: "--add-flags -m --add-flags ${n.plugin}") plugins); 56 in lib.appendToName "with-plugins" ( symlinkJoin { 57 inherit (yosys) name; 58 paths = paths ++ [ yosys ] ; 59 buildInputs = [ makeWrapper ]; 60 postBuild = '' 61 wrapProgram $out/bin/yosys \ 62 --set NIX_YOSYS_PLUGIN_DIRS $out/share/yosys/plugins \ 63 ${module_flags} 64 ''; 65 }); 66 67 allPlugins = { 68 bluespec = yosys-bluespec; 69 ghdl = yosys-ghdl; 70 } // (yosys-symbiflow); 71 72 73in stdenv.mkDerivation rec { 74 pname = "yosys"; 75 version = "0.16"; 76 77 src = fetchFromGitHub { 78 owner = "YosysHQ"; 79 repo = "yosys"; 80 rev = "${pname}-${version}"; 81 hash = "sha256-X1yygoat6ezJt9jLO+W528ryf381nKGDQ3cfrG1ZbIk="; 82 }; 83 84 enableParallelBuilding = true; 85 nativeBuildInputs = [ pkg-config bison flex ]; 86 buildInputs = [ tcl readline libffi python3 protobuf zlib ]; 87 88 makeFlags = [ "ENABLE_PROTOBUF=1" "PREFIX=${placeholder "out"}"]; 89 90 patches = [ 91 ./plugin-search-dirs.patch 92 ./fix-clang-build.patch # see https://github.com/YosysHQ/yosys/issues/2011 93 ]; 94 95 postPatch = '' 96 substituteInPlace ./Makefile \ 97 --replace 'echo UNKNOWN' 'echo ${builtins.substring 0 10 src.rev}' 98 99 chmod +x ./misc/yosys-config.in 100 patchShebangs tests ./misc/yosys-config.in 101 ''; 102 103 preBuild = let 104 shortAbcRev = builtins.substring 0 7 abc-verifier.rev; 105 in '' 106 chmod -R u+w . 107 make config-${if stdenv.cc.isClang or false then "clang" else "gcc"} 108 echo 'ABCEXTERNAL = ${abc-verifier}/bin/abc' >> Makefile.conf 109 110 # we have to do this ourselves for some reason... 111 (cd misc && ${protobuf}/bin/protoc --cpp_out ../backends/protobuf/ ./yosys.proto) 112 113 if ! grep -q "ABCREV = ${shortAbcRev}" Makefile; then 114 echo "ERROR: yosys isn't compatible with the provided abc (${shortAbcRev}), failing." 115 exit 1 116 fi 117 118 if ! grep -q "YOSYS_VER := $version" Makefile; then 119 echo "ERROR: yosys version in Makefile isn't equivalent to version of the nix package (allegedly ${version}), failing." 120 exit 1 121 fi 122 ''; 123 124 checkTarget = "test"; 125 doCheck = true; 126 checkInputs = [ verilog ]; 127 128 # Internally, yosys knows to use the specified hardcoded ABCEXTERNAL binary. 129 # But other tools (like mcy or symbiyosys) can't know how yosys was built, so 130 # they just assume that 'yosys-abc' is available -- but it's not installed 131 # when using ABCEXTERNAL 132 # 133 # add a symlink to fake things so that both variants work the same way. this 134 # is also needed at build time for the test suite. 135 postBuild = "ln -sfv ${abc-verifier}/bin/abc ./yosys-abc"; 136 postInstall = "ln -sfv ${abc-verifier}/bin/abc $out/bin/yosys-abc"; 137 138 setupHook = ./setup-hook.sh; 139 140 passthru = { 141 inherit withPlugins allPlugins; 142 }; 143 144 meta = with lib; { 145 description = "Open RTL synthesis framework and tools"; 146 homepage = "https://yosyshq.net/yosys/"; 147 license = licenses.isc; 148 platforms = platforms.all; 149 maintainers = with maintainers; [ shell thoughtpolice emily ]; 150 }; 151}