nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at devShellTools-shell 205 lines 5.4 kB view raw
1{ 2 lib, 3 stdenv, 4 fetchFromGitHub, 5 fetchpatch2, 6 7 # nativeBuildInputs 8 bison, 9 flex, 10 pkg-config, 11 12 # propagatedBuildInputs 13 libffi, 14 python3, 15 readline, 16 tcl, 17 zlib, 18 19 # tests 20 gtkwave, 21 iverilog, 22 23 # passthru 24 # plugins 25 symlinkJoin, 26 yosys, 27 makeWrapper, 28 yosys-bluespec, 29 yosys-ghdl, 30 yosys-symbiflow, 31 nix-update-script, 32 enablePython ? true, # enable python binding 33}: 34 35# NOTE: as of late 2020, yosys has switched to an automation robot that 36# automatically tags their repository Makefile with a new build number every 37# day when changes are committed. please MAKE SURE that the version number in 38# the 'version' field exactly matches the YOSYS_VER field in the Yosys 39# makefile! 40# 41# if a change in yosys isn't yet available under a build number like this (i.e. 42# it was very recently merged, within an hour), wait a few hours for the 43# automation robot to tag the new version, like so: 44# 45# https://github.com/YosysHQ/yosys/commit/71ca9a825309635511b64b3ec40e5e5e9b6ad49b 46# 47# note that while most nix packages for "unstable versions" use a date-based 48# version scheme, synchronizing the nix package version here with the unstable 49# yosys version number helps users report better bugs upstream, and is 50# ultimately less confusing than using dates. 51 52let 53 54 # Provides a wrapper for creating a yosys with the specified plugins preloaded 55 # 56 # Example: 57 # 58 # my_yosys = yosys.withPlugins (with yosys.allPlugins; [ 59 # fasm 60 # bluespec 61 # ]); 62 withPlugins = 63 plugins: 64 let 65 paths = lib.closePropagation plugins; 66 module_flags = 67 with builtins; 68 concatStringsSep " " (map (n: "--add-flags -m --add-flags ${n.plugin}") plugins); 69 in 70 lib.appendToName "with-plugins" (symlinkJoin { 71 inherit (yosys) name; 72 paths = paths ++ [ yosys ]; 73 nativeBuildInputs = [ makeWrapper ]; 74 postBuild = '' 75 wrapProgram $out/bin/yosys \ 76 --set NIX_YOSYS_PLUGIN_DIRS $out/share/yosys/plugins \ 77 ${module_flags} 78 ''; 79 }); 80 81 allPlugins = { 82 bluespec = yosys-bluespec; 83 ghdl = yosys-ghdl; 84 } 85 // (yosys-symbiflow); 86 87in 88stdenv.mkDerivation (finalAttrs: { 89 pname = "yosys"; 90 version = "0.55"; 91 92 src = fetchFromGitHub { 93 owner = "YosysHQ"; 94 repo = "yosys"; 95 tag = "v${finalAttrs.version}"; 96 hash = "sha256-GddNbAtH5SPm7KTa5kCm/vGq4xOczx+jCnOSQl55gUI="; 97 fetchSubmodules = true; 98 leaveDotGit = true; 99 postFetch = '' 100 # set up git hashes as if we used the tarball 101 102 pushd $out 103 git rev-parse HEAD > .gitcommit 104 cd $out/abc 105 git rev-parse HEAD > .gitcommit 106 popd 107 108 # remove .git now that we are through with it 109 find "$out" -name .git -print0 | xargs -0 rm -rf 110 ''; 111 }; 112 113 enableParallelBuilding = true; 114 nativeBuildInputs = [ 115 bison 116 flex 117 pkg-config 118 ]; 119 120 propagatedBuildInputs = [ 121 libffi 122 readline 123 tcl 124 zlib 125 (python3.withPackages ( 126 pp: with pp; [ 127 click 128 ] 129 )) 130 ] 131 ++ lib.optionals enablePython [ 132 python3.pkgs.boost 133 ]; 134 135 makeFlags = [ "PREFIX=${placeholder "out"}" ]; 136 137 patches = [ 138 # Backport fix amaranth code compilation 139 # TODO remove when updating to 0.56 140 # https://github.com/YosysHQ/yosys/pull/5182 141 (fetchpatch2 { 142 name = "treat-zero-width-constant-as-zero.patch"; 143 url = "https://github.com/YosysHQ/yosys/commit/478b6a2b3fbab0fd4097b841914cbe8bb9f67268.patch"; 144 hash = "sha256-KeLoZfkXMk2KIPN9XBQdqWqohywQONlWUIvrGwgphKs="; 145 }) 146 ./plugin-search-dirs.patch 147 ./fix-clang-build.patch 148 ]; 149 150 postPatch = '' 151 substituteInPlace ./Makefile \ 152 --replace-fail 'echo UNKNOWN' 'echo ${builtins.substring 0 10 finalAttrs.src.rev}' 153 154 patchShebangs tests ./misc/yosys-config.in 155 ''; 156 157 preBuild = '' 158 chmod -R u+w . 159 make config-${if stdenv.cc.isClang or false then "clang" else "gcc"} 160 161 if ! grep -q "YOSYS_VER := $version" Makefile; then 162 echo "ERROR: yosys version in Makefile isn't equivalent to version of the nix package (allegedly ${finalAttrs.version}), failing." 163 exit 1 164 fi 165 '' 166 + lib.optionalString enablePython '' 167 echo "ENABLE_PYOSYS := 1" >> Makefile.conf 168 echo "PYTHON_DESTDIR := $out/${python3.sitePackages}" >> Makefile.conf 169 echo "BOOST_PYTHON_LIB := -lboost_python${lib.versions.major python3.version}${lib.versions.minor python3.version}" >> Makefile.conf 170 ''; 171 172 preCheck = '' 173 # autotest.sh automatically compiles a utility during startup if it's out of date. 174 # having N check jobs race to do that creates spurious codesigning failures on macOS. 175 # run it once without asking it to do anything so that compilation is done before the jobs start. 176 tests/tools/autotest.sh 177 ''; 178 179 checkTarget = "test"; 180 doCheck = true; 181 nativeCheckInputs = [ 182 gtkwave 183 iverilog 184 ]; 185 186 setupHook = ./setup-hook.sh; 187 188 passthru = { 189 inherit withPlugins allPlugins; 190 updateScript = nix-update-script { }; 191 }; 192 193 meta = { 194 description = "Open RTL synthesis framework and tools"; 195 homepage = "https://yosyshq.net/yosys/"; 196 changelog = "https://github.com/YosysHQ/yosys/releases/tag/v${finalAttrs.version}"; 197 license = lib.licenses.isc; 198 platforms = lib.platforms.all; 199 maintainers = with lib.maintainers; [ 200 shell 201 thoughtpolice 202 Luflosi 203 ]; 204 }; 205})