mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-12-29 00:53:57 +00:00
2660037f8c
By default, when yosys looks for plugins with the `-m` flag or `plugin` command, it always looks in `YOSYS_PREFIX/share/yosys/plugins` for a `.so` file, and loads that. By design, this is intended to be a single, global, mutable location such as `/usr/share/yosys/...` on disk, and plugins are supposed to install their `.so` files here after yosys is installed, and they all coexist together. Obviously, this won't work for us, but users might expect these plugins to still work. More importantly, they won't want to add special cases to their build systems. Instead, to allow Nix users to use yosys plugins with the same UX (e.g. natively call `plugin bluespec` or `-m ghdl`), we add a patch to yosys that allows it to search a new `NIX_YOSYS_PLUGIN_DIRS` search path environment variable. In tandem, we add a setup hook that adds to this search path if a package has a `$out/share/yosys/plugins` directory. Thus, it's enough to just include `yosys`, and any package that has a yosys plugin in `$out/share/yosys/plugins`, and you can load it with `-m` or the `plugin` command. We could use a style like the haskellPackages set, where the set of packages are "encased" in a lambda, and we pass packages that are compatible with that version of the compiler: haskell.packages.ghc8102.ghcWithPackages (p: with p; [ ... ]) but, realistically, there will probably only ever be one version of yosys and one set of compatible plugins, so this seems overdone. Signed-off-by: Austin Seipp <aseipp@pobox.com>
110 lines
3.6 KiB
Nix
110 lines
3.6 KiB
Nix
{ stdenv
|
|
, abc-verifier
|
|
, bash
|
|
, bison
|
|
, fetchFromGitHub
|
|
, flex
|
|
, libffi
|
|
, pkgconfig
|
|
, protobuf
|
|
, python3
|
|
, readline
|
|
, tcl
|
|
, verilog
|
|
, zlib
|
|
}:
|
|
|
|
# NOTE: as of late 2020, yosys has switched to an automation robot that
|
|
# automatically tags their repository Makefile with a new build number every
|
|
# day when changes are committed. please MAKE SURE that the version number in
|
|
# the 'version' field exactly matches the YOSYS_VER field in the Yosys
|
|
# makefile!
|
|
#
|
|
# if a change in yosys isn't yet available under a build number like this (i.e.
|
|
# it was very recently merged, within an hour), wait a few hours for the
|
|
# automation robot to tag the new version, like so:
|
|
#
|
|
# https://github.com/YosysHQ/yosys/commit/71ca9a825309635511b64b3ec40e5e5e9b6ad49b
|
|
#
|
|
# note that while most nix packages for "unstable versions" use a date-based
|
|
# version scheme, synchronizing the nix package version here with the unstable
|
|
# yosys version number helps users report better bugs upstream, and is
|
|
# ultimately less confusing than using dates.
|
|
|
|
stdenv.mkDerivation rec {
|
|
pname = "yosys";
|
|
version = "0.9+3830";
|
|
|
|
src = fetchFromGitHub {
|
|
owner = "YosysHQ";
|
|
repo = "yosys";
|
|
rev = "b72c29465392c8d260ddf55def169438f7fb64b2";
|
|
sha256 = "12h3pgj8bjb254q2qaafc3qxwhqdqrx0sxjhgjrfy8cmkdm92dvy";
|
|
};
|
|
|
|
enableParallelBuilding = true;
|
|
nativeBuildInputs = [ pkgconfig ];
|
|
buildInputs = [ tcl readline libffi python3 bison flex protobuf zlib ];
|
|
|
|
makeFlags = [ "ENABLE_PROTOBUF=1" "PREFIX=${placeholder "out"}"];
|
|
|
|
patchPhase = ''
|
|
patch -p1 < ${./plugin-search-dirs.patch}
|
|
substituteInPlace ./Makefile \
|
|
--replace 'CXX = clang' "" \
|
|
--replace 'LD = clang++' 'LD = $(CXX)' \
|
|
--replace 'CXX = gcc' "" \
|
|
--replace 'LD = gcc' 'LD = $(CXX)' \
|
|
--replace 'ABCMKARGS = CC="$(CXX)" CXX="$(CXX)"' 'ABCMKARGS =' \
|
|
--replace 'echo UNKNOWN' 'echo ${builtins.substring 0 10 src.rev}'
|
|
substituteInPlace ./misc/yosys-config.in \
|
|
--replace '/bin/bash' '${bash}/bin/bash'
|
|
patchShebangs tests
|
|
'';
|
|
|
|
preBuild = let
|
|
shortAbcRev = builtins.substring 0 7 abc-verifier.rev;
|
|
in ''
|
|
chmod -R u+w .
|
|
make config-${if stdenv.cc.isClang or false then "clang" else "gcc"}
|
|
echo 'ABCEXTERNAL = ${abc-verifier}/bin/abc' >> Makefile.conf
|
|
|
|
# we have to do this ourselves for some reason...
|
|
(cd misc && ${protobuf}/bin/protoc --cpp_out ../backends/protobuf/ ./yosys.proto)
|
|
|
|
if ! grep -q "ABCREV = ${shortAbcRev}" Makefile; then
|
|
echo "ERROR: yosys isn't compatible with the provided abc (${shortAbcRev}), failing."
|
|
exit 1
|
|
fi
|
|
|
|
if ! grep -q "YOSYS_VER := ${version}" Makefile; then
|
|
echo "ERROR: yosys version in Makefile isn't equivalent to version of the nix package (${version}), failing."
|
|
exit 1
|
|
fi
|
|
'';
|
|
|
|
checkTarget = "test";
|
|
doCheck = true;
|
|
checkInputs = [ verilog ];
|
|
|
|
# Internally, yosys knows to use the specified hardcoded ABCEXTERNAL binary.
|
|
# But other tools (like mcy or symbiyosys) can't know how yosys was built, so
|
|
# they just assume that 'yosys-abc' is available -- but it's not installed
|
|
# when using ABCEXTERNAL
|
|
#
|
|
# add a symlink to fake things so that both variants work the same way. this
|
|
# is also needed at build time for the test suite.
|
|
postBuild = "ln -sfv ${abc-verifier}/bin/abc ./yosys-abc";
|
|
postInstall = "ln -sfv ${abc-verifier}/bin/abc $out/bin/yosys-abc";
|
|
|
|
setupHook = ./setup-hook.sh;
|
|
|
|
meta = with stdenv.lib; {
|
|
description = "Open RTL synthesis framework and tools";
|
|
homepage = "http://www.clifford.at/yosys/";
|
|
license = licenses.isc;
|
|
platforms = platforms.all;
|
|
maintainers = with maintainers; [ shell thoughtpolice emily ];
|
|
};
|
|
}
|