2021-03-31 21:11:34 +00:00
|
|
|
{
|
|
|
|
stdenv,
|
|
|
|
lib,
|
2020-01-07 15:06:23 +00:00
|
|
|
bison,
|
2023-11-30 16:59:28 +00:00
|
|
|
boost,
|
2020-01-07 15:06:23 +00:00
|
|
|
fetchFromGitHub,
|
|
|
|
flex,
|
|
|
|
libffi,
|
2022-01-07 14:10:18 +00:00
|
|
|
makeWrapper,
|
2021-01-15 16:26:16 +00:00
|
|
|
pkg-config,
|
2020-01-07 15:06:23 +00:00
|
|
|
python3,
|
|
|
|
readline,
|
2022-01-07 14:10:18 +00:00
|
|
|
symlinkJoin,
|
2020-01-07 15:06:23 +00:00
|
|
|
tcl,
|
2024-07-14 00:39:19 +00:00
|
|
|
iverilog,
|
2020-01-07 15:06:23 +00:00
|
|
|
zlib,
|
2022-01-07 14:10:18 +00:00
|
|
|
yosys,
|
|
|
|
yosys-bluespec,
|
|
|
|
yosys-ghdl,
|
|
|
|
yosys-symbiflow,
|
2023-12-01 07:03:31 +00:00
|
|
|
enablePython ? true, # enable python binding
|
2017-10-16 07:34:04 +00:00
|
|
|
}:
|
2015-12-29 16:31:18 +00:00
|
|
|
|
2020-11-12 20:14:08 +00:00
|
|
|
# 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.
|
|
|
|
|
2022-01-07 14:10:18 +00:00
|
|
|
let
|
|
|
|
|
|
|
|
# Provides a wrapper for creating a yosys with the specifed plugins preloaded
|
|
|
|
#
|
|
|
|
# Example:
|
|
|
|
#
|
|
|
|
# my_yosys = yosys.withPlugins (with yosys.allPlugins; [
|
|
|
|
# fasm
|
|
|
|
# bluespec
|
|
|
|
# ]);
|
|
|
|
withPlugins =
|
|
|
|
plugins:
|
|
|
|
let
|
|
|
|
paths = lib.closePropagation plugins;
|
|
|
|
module_flags =
|
|
|
|
with builtins;
|
|
|
|
concatStringsSep " " (map (n: "--add-flags -m --add-flags ${n.plugin}") plugins);
|
|
|
|
in
|
|
|
|
lib.appendToName "with-plugins" (symlinkJoin {
|
|
|
|
inherit (yosys) name;
|
|
|
|
paths = paths ++ [ yosys ];
|
2022-08-15 03:40:21 +00:00
|
|
|
nativeBuildInputs = [ makeWrapper ];
|
2022-01-07 14:10:18 +00:00
|
|
|
postBuild = ''
|
|
|
|
wrapProgram $out/bin/yosys \
|
|
|
|
--set NIX_YOSYS_PLUGIN_DIRS $out/share/yosys/plugins \
|
|
|
|
${module_flags}
|
|
|
|
'';
|
|
|
|
});
|
|
|
|
|
|
|
|
allPlugins = {
|
|
|
|
bluespec = yosys-bluespec;
|
|
|
|
ghdl = yosys-ghdl;
|
|
|
|
} // (yosys-symbiflow);
|
|
|
|
|
2023-11-30 16:59:28 +00:00
|
|
|
boost_python = boost.override {
|
|
|
|
enablePython = true;
|
|
|
|
python = python3;
|
|
|
|
};
|
2022-01-07 14:10:18 +00:00
|
|
|
|
2023-11-08 13:39:42 +00:00
|
|
|
in
|
|
|
|
stdenv.mkDerivation (finalAttrs: {
|
2020-03-17 10:26:27 +00:00
|
|
|
pname = "yosys";
|
2024-11-06 10:03:03 +00:00
|
|
|
version = "0.47";
|
2015-12-29 16:31:18 +00:00
|
|
|
|
2020-01-07 15:09:08 +00:00
|
|
|
src = fetchFromGitHub {
|
2021-12-02 20:04:44 +00:00
|
|
|
owner = "YosysHQ";
|
|
|
|
repo = "yosys";
|
2024-09-10 10:29:37 +00:00
|
|
|
rev = "refs/tags/${finalAttrs.version}";
|
2024-11-06 10:03:03 +00:00
|
|
|
hash = "sha256-9u9aAPTZyt9vzZwryor3GRCGzs/mu2/XtM0XzV7uHfk=";
|
2024-06-25 00:13:01 +00:00
|
|
|
fetchSubmodules = true;
|
|
|
|
leaveDotGit = true;
|
|
|
|
postFetch = ''
|
|
|
|
# set up git hashes as if we used the tarball
|
|
|
|
|
|
|
|
pushd $out
|
|
|
|
git rev-parse HEAD > .gitcommit
|
|
|
|
cd $out/abc
|
|
|
|
git rev-parse HEAD > .gitcommit
|
|
|
|
popd
|
|
|
|
|
|
|
|
# remove .git now that we are through with it
|
|
|
|
find "$out" -name .git -print0 | xargs -0 rm -rf
|
|
|
|
'';
|
2020-01-07 15:09:08 +00:00
|
|
|
};
|
2015-12-29 16:31:18 +00:00
|
|
|
|
2017-10-16 07:34:04 +00:00
|
|
|
enableParallelBuilding = true;
|
2021-01-15 22:07:53 +00:00
|
|
|
nativeBuildInputs = [
|
|
|
|
pkg-config
|
|
|
|
bison
|
|
|
|
flex
|
|
|
|
];
|
2023-12-04 13:03:58 +00:00
|
|
|
propagatedBuildInputs = [
|
2022-10-05 11:58:46 +00:00
|
|
|
tcl
|
|
|
|
readline
|
|
|
|
libffi
|
|
|
|
zlib
|
|
|
|
(python3.withPackages (
|
|
|
|
pp: with pp; [
|
|
|
|
click
|
|
|
|
]
|
|
|
|
))
|
2023-11-30 16:59:28 +00:00
|
|
|
] ++ lib.optional enablePython boost_python;
|
2018-08-09 00:28:18 +00:00
|
|
|
|
2022-11-08 09:49:14 +00:00
|
|
|
makeFlags = [ "PREFIX=${placeholder "out"}" ];
|
2018-02-14 06:15:48 +00:00
|
|
|
|
2021-01-15 22:07:53 +00:00
|
|
|
patches = [
|
|
|
|
./plugin-search-dirs.patch
|
2021-11-09 13:10:19 +00:00
|
|
|
./fix-clang-build.patch # see https://github.com/YosysHQ/yosys/issues/2011
|
2021-01-15 22:07:53 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
postPatch = ''
|
2018-02-14 06:15:48 +00:00
|
|
|
substituteInPlace ./Makefile \
|
2024-02-10 21:59:32 +00:00
|
|
|
--replace-fail 'echo UNKNOWN' 'echo ${builtins.substring 0 10 finalAttrs.src.rev}'
|
|
|
|
|
2021-01-15 16:26:16 +00:00
|
|
|
patchShebangs tests ./misc/yosys-config.in
|
2018-02-14 06:15:48 +00:00
|
|
|
'';
|
|
|
|
|
2024-06-25 00:13:01 +00:00
|
|
|
preBuild =
|
|
|
|
''
|
2020-01-07 15:09:08 +00:00
|
|
|
chmod -R u+w .
|
2018-04-11 20:08:51 +00:00
|
|
|
make config-${if stdenv.cc.isClang or false then "clang" else "gcc"}
|
2024-12-10 19:26:33 +00:00
|
|
|
|
2021-01-15 16:26:16 +00:00
|
|
|
if ! grep -q "YOSYS_VER := $version" Makefile; then
|
2023-11-08 13:39:42 +00:00
|
|
|
echo "ERROR: yosys version in Makefile isn't equivalent to version of the nix package (allegedly ${finalAttrs.version}), failing."
|
2020-02-01 11:34:30 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
2023-11-30 16:59:28 +00:00
|
|
|
''
|
|
|
|
+ lib.optionalString enablePython ''
|
|
|
|
echo "ENABLE_PYOSYS := 1" >> Makefile.conf
|
|
|
|
echo "PYTHON_DESTDIR := $out/${python3.sitePackages}" >> Makefile.conf
|
|
|
|
echo "BOOST_PYTHON_LIB := -lboost_python${lib.versions.major python3.version}${lib.versions.minor python3.version}" >> Makefile.conf
|
2015-12-29 16:31:18 +00:00
|
|
|
'';
|
|
|
|
|
2024-02-10 21:59:32 +00:00
|
|
|
preCheck = ''
|
|
|
|
# autotest.sh automatically compiles a utility during startup if it's out of date.
|
|
|
|
# having N check jobs race to do that creates spurious codesigning failures on macOS.
|
|
|
|
# run it once without asking it to do anything so that compilation is done before the jobs start.
|
|
|
|
tests/tools/autotest.sh
|
|
|
|
'';
|
|
|
|
|
2020-11-12 20:14:08 +00:00
|
|
|
checkTarget = "test";
|
2019-09-27 14:06:42 +00:00
|
|
|
doCheck = true;
|
2024-07-14 00:39:19 +00:00
|
|
|
nativeCheckInputs = [ iverilog ];
|
2019-09-27 14:06:42 +00:00
|
|
|
|
yosys: enable loading "out of band" plugins
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>
2021-01-15 05:52:23 +00:00
|
|
|
setupHook = ./setup-hook.sh;
|
|
|
|
|
2022-01-07 14:10:18 +00:00
|
|
|
passthru = {
|
|
|
|
inherit withPlugins allPlugins;
|
|
|
|
};
|
|
|
|
|
2021-01-15 22:07:53 +00:00
|
|
|
meta = with lib; {
|
2020-03-17 10:26:27 +00:00
|
|
|
description = "Open RTL synthesis framework and tools";
|
2022-02-16 13:28:28 +00:00
|
|
|
homepage = "https://yosyshq.net/yosys/";
|
2020-03-17 10:26:27 +00:00
|
|
|
license = licenses.isc;
|
|
|
|
platforms = platforms.all;
|
2024-06-15 11:37:52 +00:00
|
|
|
maintainers = with maintainers; [
|
|
|
|
shell
|
|
|
|
thoughtpolice
|
|
|
|
Luflosi
|
|
|
|
];
|
2015-12-29 16:31:18 +00:00
|
|
|
};
|
2023-11-08 13:39:42 +00:00
|
|
|
})
|