summary refs log tree commit diff
path: root/pkgs/development/compilers/yosys
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/development/compilers/yosys')
-rw-r--r--pkgs/development/compilers/yosys/default.nix74
-rw-r--r--pkgs/development/compilers/yosys/plugin-search-dirs.patch34
-rw-r--r--pkgs/development/compilers/yosys/plugins/bluespec.nix32
-rw-r--r--pkgs/development/compilers/yosys/plugins/ghdl.nix31
-rw-r--r--pkgs/development/compilers/yosys/setup-hook.sh5
5 files changed, 155 insertions, 21 deletions
diff --git a/pkgs/development/compilers/yosys/default.nix b/pkgs/development/compilers/yosys/default.nix
index c3185ca4e0e..a0c02e26db0 100644
--- a/pkgs/development/compilers/yosys/default.nix
+++ b/pkgs/development/compilers/yosys/default.nix
@@ -1,11 +1,12 @@
 { stdenv
+, lib
 , abc-verifier
 , bash
 , bison
 , fetchFromGitHub
 , flex
 , libffi
-, pkgconfig
+, pkg-config
 , protobuf
 , python3
 , readline
@@ -14,34 +15,50 @@
 , 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 = "2020.08.22";
+  version = "0.9+4052";
 
   src = fetchFromGitHub {
     owner  = "YosysHQ";
     repo   = "yosys";
-    rev    = "12132b6850747aec99715fdfa3184fe3ebefa015";
-    sha256 = "1v6x1y2f3r8vi7pnkgx374rrv02xgmg9yg23f61n7d1v2rd6y5cc";
+    rev    = "687f381b6985d9dda7e11535628e2fafff267af5";
+    sha256 = "15lcj798ckh9zwvdqb5gnvicilsxjyxv01gcviijg310hq62n7vf";
   };
 
   enableParallelBuilding = true;
-  nativeBuildInputs = [ pkgconfig ];
-  buildInputs = [ tcl readline libffi python3 bison flex protobuf zlib ];
+  nativeBuildInputs = [ pkg-config bison flex ];
+  buildInputs = [ tcl readline libffi python3 protobuf zlib ];
 
   makeFlags = [ "ENABLE_PROTOBUF=1" "PREFIX=${placeholder "out"}"];
 
-  patchPhase = ''
+  patches = [
+    ./plugin-search-dirs.patch
+  ];
+
+  postPatch = ''
     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
+
+    chmod +x ./misc/yosys-config.in
+    patchShebangs tests ./misc/yosys-config.in
   '';
 
   preBuild = let
@@ -55,11 +72,17 @@ stdenv.mkDerivation rec {
     (cd misc && ${protobuf}/bin/protoc --cpp_out ../backends/protobuf/ ./yosys.proto)
 
     if ! grep -q "ABCREV = ${shortAbcRev}" Makefile; then
-      echo "yosys isn't compatible with the provided abc (${shortAbcRev}), failing."
+      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 ];
 
@@ -68,16 +91,25 @@ stdenv.mkDerivation rec {
   # 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.
-  postInstall = ''
-    ln -sfv ${abc-verifier}/bin/abc $out/bin/yosys-abc
-  '';
+  # 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";
 
-  meta = with stdenv.lib; {
+  setupHook = ./setup-hook.sh;
+
+  meta = with 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 ];
+    #In file included from kernel/driver.cc:20:
+    #./kernel/yosys.h:42:10: fatal error: 'map' file not found
+    ##include <map>
+
+    #https://github.com/YosysHQ/yosys/issues/681
+    #https://github.com/YosysHQ/yosys/issues/2011
+    broken = stdenv.isDarwin;
   };
 }
diff --git a/pkgs/development/compilers/yosys/plugin-search-dirs.patch b/pkgs/development/compilers/yosys/plugin-search-dirs.patch
new file mode 100644
index 00000000000..0cb0aee9c7e
--- /dev/null
+++ b/pkgs/development/compilers/yosys/plugin-search-dirs.patch
@@ -0,0 +1,34 @@
+diff --git a/passes/cmds/plugin.cc b/passes/cmds/plugin.cc
+index 3ed19497..f9534bd0 100644
+--- a/passes/cmds/plugin.cc
++++ b/passes/cmds/plugin.cc
+@@ -75,8 +75,27 @@ void load_plugin(std::string filename, std::vector<std::string> aliases)
+ 		#endif
+ 
+ 		void *hdl = dlopen(filename.c_str(), RTLD_LAZY|RTLD_LOCAL);
+-		if (hdl == NULL && orig_filename.find('/') == std::string::npos)
+-			hdl = dlopen((proc_share_dirname() + "plugins/" + orig_filename + ".so").c_str(), RTLD_LAZY|RTLD_LOCAL);
++		if (hdl == NULL && orig_filename.find('/') == std::string::npos) {
++			std::string install_dir = proc_share_dirname() + "plugins";
++
++			vector<string> all_dirs;
++			all_dirs.push_back(install_dir);
++
++			char* plugin_dirs = getenv("NIX_YOSYS_PLUGIN_DIRS");
++			if (plugin_dirs != NULL) {
++				std::string p(plugin_dirs), t;
++				std::stringstream ss(p);
++
++				while(std::getline(ss, t, ':')) {
++					all_dirs.push_back(t);
++				}
++			}
++
++			for (auto dir : all_dirs) {
++				hdl = dlopen((dir + "/" + orig_filename + ".so").c_str(), RTLD_LAZY|RTLD_LOCAL);
++				if (hdl != NULL) break;
++			}
++		}
+ 		if (hdl == NULL)
+ 			log_cmd_error("Can't load module `%s': %s\n", filename.c_str(), dlerror());
+ 		loaded_plugins[orig_filename] = hdl;
diff --git a/pkgs/development/compilers/yosys/plugins/bluespec.nix b/pkgs/development/compilers/yosys/plugins/bluespec.nix
new file mode 100644
index 00000000000..58fef968e46
--- /dev/null
+++ b/pkgs/development/compilers/yosys/plugins/bluespec.nix
@@ -0,0 +1,32 @@
+{ stdenv, lib, fetchFromGitHub, pkg-config
+, yosys, readline, zlib, bluespec
+}:
+
+stdenv.mkDerivation {
+  pname = "yosys-bluespec";
+  version = "2021.01.17";
+
+  src = fetchFromGitHub {
+    owner  = "thoughtpolice";
+    repo   = "yosys-bluespec";
+    rev    = "3cfa22c2810b840f406610efe3d7657477c1b0ed";
+    sha256 = "1r48128yisw5lpziaj3hq88acghwi94pvm4735xajx8dl79jkcng";
+  };
+
+  buildInputs = [ yosys readline zlib bluespec ];
+  nativeBuildInputs = [ pkg-config ];
+
+  doCheck = true;
+  makeFlags = [
+    "PREFIX=$(out)/share/yosys/plugins"
+    "STATIC_BSC_PATH=${bluespec}/bin/bsc"
+    "STATIC_BSC_LIBDIR=${bluespec}/lib"
+  ];
+
+  meta = with lib; {
+    description = "Bluespec plugin for Yosys";
+    license     = licenses.isc;
+    platforms   = platforms.all;
+    maintainers = with maintainers; [ thoughtpolice ];
+  };
+}
diff --git a/pkgs/development/compilers/yosys/plugins/ghdl.nix b/pkgs/development/compilers/yosys/plugins/ghdl.nix
new file mode 100644
index 00000000000..35f3ef2bcc8
--- /dev/null
+++ b/pkgs/development/compilers/yosys/plugins/ghdl.nix
@@ -0,0 +1,31 @@
+{ stdenv, lib, fetchFromGitHub, pkg-config
+, yosys, readline, zlib, ghdl
+}:
+
+stdenv.mkDerivation {
+  pname = "yosys-ghdl";
+  version = "2021.01.25";
+
+  src = fetchFromGitHub {
+    owner  = "ghdl";
+    repo   = "ghdl-yosys-plugin";
+    rev    = "cba859cacf8c6631146dbdaa0f297c060b5a68cd";
+    sha256 = "01d9wb7sqkmkf2y9bnn3pmhy08khzs5m1d06whxsiwgwnjzfk9mx";
+  };
+
+  buildInputs = [ yosys readline zlib ghdl ];
+  nativeBuildInputs = [ pkg-config ];
+
+  doCheck = true;
+  installPhase = ''
+    mkdir -p $out/share/yosys/plugins
+    cp ghdl.so $out/share/yosys/plugins/ghdl.so
+  '';
+
+  meta = with lib; {
+    description = "GHDL plugin for Yosys";
+    license     = licenses.isc;
+    platforms   = platforms.all;
+    maintainers = with maintainers; [ thoughtpolice ];
+  };
+}
diff --git a/pkgs/development/compilers/yosys/setup-hook.sh b/pkgs/development/compilers/yosys/setup-hook.sh
new file mode 100644
index 00000000000..d01bbdd1a8c
--- /dev/null
+++ b/pkgs/development/compilers/yosys/setup-hook.sh
@@ -0,0 +1,5 @@
+addYosysPluginPath() {
+  addToSearchPath NIX_YOSYS_PLUGIN_DIRS "$1/share/yosys/plugins"
+}
+
+addEnvHooks "$targetOffset" addYosysPluginPath