From 07bf05a7869c88c27912833c1db942f8fc849f4d Mon Sep 17 00:00:00 2001 From: Alejandro Soto Date: Sun, 11 Jun 2023 20:12:29 -0600 Subject: pkgs: add existing derivations written for other projects --- flake.nix | 8 ++- pkgs/cocotb/default.nix | 15 +++++ pkgs/cocotb/exts/wishbone.nix | 18 ++++++ pkgs/default.nix | 12 ++++ pkgs/find-libpython.nix | 13 +++++ pkgs/force-riscv/default.nix | 67 ++++++++++++++++++++++ pkgs/force-riscv/imageio-include-string.patch | 12 ++++ pkgs/force-riscv/remove-pyeval-initthreads.patch | 12 ++++ pkgs/force-riscv/testio-include-string.patch | 12 ++++ .../urbg-static-constexpr-min-max.patch | 15 +++++ .../wno-error-range-loop-construct.patch | 13 +++++ ...to.verilog-fix-always_ff-sensitivity-list.patch | 25 ++++++++ .../0002-to.hdl_ast_-visit-sensitivity-lists.patch | 39 +++++++++++++ pkgs/hdl-convertor/ast.nix | 18 ++++++ pkgs/hdl-convertor/default.nix | 44 ++++++++++++++ 15 files changed, 320 insertions(+), 3 deletions(-) create mode 100644 pkgs/cocotb/default.nix create mode 100644 pkgs/cocotb/exts/wishbone.nix create mode 100644 pkgs/find-libpython.nix create mode 100644 pkgs/force-riscv/default.nix create mode 100644 pkgs/force-riscv/imageio-include-string.patch create mode 100644 pkgs/force-riscv/remove-pyeval-initthreads.patch create mode 100644 pkgs/force-riscv/testio-include-string.patch create mode 100644 pkgs/force-riscv/urbg-static-constexpr-min-max.patch create mode 100644 pkgs/force-riscv/wno-error-range-loop-construct.patch create mode 100644 pkgs/hdl-convertor/0001-to.verilog-fix-always_ff-sensitivity-list.patch create mode 100644 pkgs/hdl-convertor/0002-to.hdl_ast_-visit-sensitivity-lists.patch create mode 100644 pkgs/hdl-convertor/ast.nix create mode 100644 pkgs/hdl-convertor/default.nix diff --git a/flake.nix b/flake.nix index 32d9669..0698666 100644 --- a/flake.nix +++ b/flake.nix @@ -37,10 +37,12 @@ formatter.${system} = pkgs.nixpkgs-fmt; packages.${system} = local pkgs pkgsNoLocal; - overlays.default = final: prev: { - local = local final prev; + overlays.default = final: prev: let + locals = local final prev; + in { + local = locals; unstable = (importPkgs unstable).extend self.overlays.default; - }; + } // locals.override; nixosConfigurations = let diff --git a/pkgs/cocotb/default.nix b/pkgs/cocotb/default.nix new file mode 100644 index 0000000..1fe3d98 --- /dev/null +++ b/pkgs/cocotb/default.nix @@ -0,0 +1,15 @@ +{ cocotb, fetchFromGitHub, find-libpython }: +cocotb.overridePythonAttrs (prev: { + version = "master-2023-03-16"; + + src = fetchFromGitHub { + repo = "cocotb"; + owner = "cocotb"; + + rev = "7b33df04866ce1e74ff4ebc33ced8e30f59970de"; + sha256 = "sha256-7IlEaGSnd47tTxRu8QGW9mExCCZe47S41tlQatACLxU="; + }; + + propagatedBuildInputs = [ find-libpython ]; + doCheck = false; +}) diff --git a/pkgs/cocotb/exts/wishbone.nix b/pkgs/cocotb/exts/wishbone.nix new file mode 100644 index 0000000..5dd375b --- /dev/null +++ b/pkgs/cocotb/exts/wishbone.nix @@ -0,0 +1,18 @@ +{ buildPythonPackage, cocotb, cocotb-bus, fetchFromGitHub, git, setuptools-scm }: +buildPythonPackage { + pname = "cocotbext-wishbone"; + version = "master-2022-04-26"; + + src = fetchFromGitHub { + repo = "cocotbext-wishbone"; + owner = "wallento"; + + rev = "3c667834f41c3c40dd4647b5a7b9e4e71e1302c4"; + sha256 = "sha256-vden1hZ9V1aqxFWu/vKmOfWfzINAopJRKTPKOpOiNkU="; + + leaveDotGit = true; + }; + + nativeBuildInputs = [ git setuptools-scm ]; + propagatedBuildInputs = [ cocotb cocotb-bus setuptools-scm ]; +} diff --git a/pkgs/default.nix b/pkgs/default.nix index 2a40577..97fff36 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -24,4 +24,16 @@ in }) ]; }; + + override = { + python3 = prev.python3.override { + packageOverrides = nextPy: prevPy: { + cocotb = nextPy.callPackage ./cocotb { inherit (prevPy) cocotb; }; + cocotbext-wishbone = nextPy.callPackage ./cocotb/exts/wishbone.nix { }; + find-libpython = nextPy.callPackage ./find-libpython.nix { }; + hdl-convertor = nextPy.callPackage ./hdl-convertor { }; + hdl-convertor-ast = nextPy.callPackage ./hdl-convertor/ast.nix { }; + }; + }; + }; } diff --git a/pkgs/find-libpython.nix b/pkgs/find-libpython.nix new file mode 100644 index 0000000..80da67f --- /dev/null +++ b/pkgs/find-libpython.nix @@ -0,0 +1,13 @@ +{ buildPythonPackage, fetchPypi }: +let + pname = "find_libpython"; + version = "0.3.0"; +in +buildPythonPackage { + inherit pname version; + + src = fetchPypi { + inherit pname version; + sha256 = "sha256-bn/l2a9/rW3AZstVFaDpyQpx8f6yuy+OTNu0+DJ26eU="; + }; +} diff --git a/pkgs/force-riscv/default.nix b/pkgs/force-riscv/default.nix new file mode 100644 index 0000000..35907ce --- /dev/null +++ b/pkgs/force-riscv/default.nix @@ -0,0 +1,67 @@ +{ fetchFromGitHub, lib, makeWrapper, python3, stdenv }: +with lib; stdenv.mkDerivation { + pname = "force-riscv"; + version = "master-2023-01-31"; + + src = fetchFromGitHub { + repo = "force-riscv"; + owner = "openhwgroup"; + + rev = "192bcc15e0dde8aaf25621da4317569b3f374047"; + sha256 = "sha256-Eol973IMGRVAuw/rsYiK61+KVYkmbqq9yudaNbMCzJ0="; + }; + + buildInputs = [ python3 ]; + nativeBuildInputs = [ makeWrapper ]; + + patches = [ + ./remove-pyeval-initthreads.patch + ./wno-error-range-loop-construct.patch + ./imageio-include-string.patch + ./testio-include-string.patch + ./urbg-static-constexpr-min-max.patch + ]; + + postPatch = '' + patchShebangs utils/ fpix/utils/ + ''; + + makeFlags = [ + "FORCE_CC=${stdenv.cc.targetPrefix}c++" + "FORCE_PYTHON_LIB=${python3}/lib" + "FORCE_PYTHON_INC=${python3}/include/${python3.libPrefix}" + ]; + + # Ver setenv.bash + installPhase = + let + paths = [ + "3rd_party/py" + "utils" + "utils/builder" + "utils/builder/test_builder" + "utils/builder/shared" + "utils/regression" + ]; + + pythonPath = concatStringsSep ":" (map (p: "$out/${p}") paths); + in + '' + mkdir -p $out/ $out/fpix/ $out/riscv/ $out/3rd_party/ + + # SimApiHANDCAR.so queda en bin (?), al parecer es así + cp -r bin/ py/ $out/ + cp -r fpix/bin/ $out/fpix/ + + for BIN in $out/bin/friscv $out/fpix/bin/fpix_riscv; do + wrapProgram $BIN \ + --prefix PYTHONPATH : ${pythonPath} + done + + rm -r utils/handcar/make_area + + cp -r 3rd_party/py/ $out/3rd_party/ + cp -r config/ utils/ $out/ + cp -r riscv/arch_data/ $out/riscv/ + ''; +} diff --git a/pkgs/force-riscv/imageio-include-string.patch b/pkgs/force-riscv/imageio-include-string.patch new file mode 100644 index 0000000..90417c1 --- /dev/null +++ b/pkgs/force-riscv/imageio-include-string.patch @@ -0,0 +1,12 @@ +diff --git a/base/inc/ImageIO.h b/base/inc/ImageIO.h +index f93866c..046dacb 100644 +--- a/base/inc/ImageIO.h ++++ b/base/inc/ImageIO.h +@@ -17,6 +17,7 @@ + #define Force_ImageIO_H + + #include ++#include + + #include "Defines.h" + diff --git a/pkgs/force-riscv/remove-pyeval-initthreads.patch b/pkgs/force-riscv/remove-pyeval-initthreads.patch new file mode 100644 index 0000000..b31f0e2 --- /dev/null +++ b/pkgs/force-riscv/remove-pyeval-initthreads.patch @@ -0,0 +1,12 @@ +diff --git a/3rd_party/inc/pybind11/detail/internals.h b/3rd_party/inc/pybind11/detail/internals.h +index 86fbe92..31ff371 100644 +--- a/3rd_party/inc/pybind11/detail/internals.h ++++ b/3rd_party/inc/pybind11/detail/internals.h +@@ -265,7 +265,6 @@ PYBIND11_NOINLINE inline internals &get_internals() { + auto *&internals_ptr = *internals_pp; + internals_ptr = new internals(); + #if defined(WITH_THREAD) +- PyEval_InitThreads(); + PyThreadState *tstate = PyThreadState_Get(); + #if PY_VERSION_HEX >= 0x03070000 + internals_ptr->tstate = PyThread_tss_alloc(); diff --git a/pkgs/force-riscv/testio-include-string.patch b/pkgs/force-riscv/testio-include-string.patch new file mode 100644 index 0000000..5b36d9f --- /dev/null +++ b/pkgs/force-riscv/testio-include-string.patch @@ -0,0 +1,12 @@ +diff --git a/base/inc/TestIO.h b/base/inc/TestIO.h +index 7d28c32..08a9167 100644 +--- a/base/inc/TestIO.h ++++ b/base/inc/TestIO.h +@@ -17,6 +17,7 @@ + #define Force_TestIO_H + + #include ++#include + + #include "Defines.h" + diff --git a/pkgs/force-riscv/urbg-static-constexpr-min-max.patch b/pkgs/force-riscv/urbg-static-constexpr-min-max.patch new file mode 100644 index 0000000..a047fd0 --- /dev/null +++ b/pkgs/force-riscv/urbg-static-constexpr-min-max.patch @@ -0,0 +1,15 @@ +diff --git a/base/inc/Random.h b/base/inc/Random.h +index 6354dee..21660a9 100644 +--- a/base/inc/Random.h ++++ b/base/inc/Random.h +@@ -56,8 +56,8 @@ namespace Force { + class RandomURBG32 { + public: + typedef uint32 result_type; //!< Type define required by STL +- uint32 min() const { return 0; } //!< min function required by STL +- uint32 max() const { return MAX_UINT32; } //!< max function required by STL ++ static constexpr uint32 min() { return 0; } //!< min function required by STL ++ static constexpr uint32 max() { return MAX_UINT32; } //!< max function required by STL + uint32 operator () () const { return mpRandomInstance->Random32(min(), max()); } + + explicit RandomURBG32(const Random* randomInstance) : mpRandomInstance(randomInstance) { } //!< Constructor with pointer to a Random object provieded. diff --git a/pkgs/force-riscv/wno-error-range-loop-construct.patch b/pkgs/force-riscv/wno-error-range-loop-construct.patch new file mode 100644 index 0000000..034d522 --- /dev/null +++ b/pkgs/force-riscv/wno-error-range-loop-construct.patch @@ -0,0 +1,13 @@ +diff --git a/utils/make/Makefile.common b/utils/make/Makefile.common +index d0c96d3..422f6eb 100644 +--- a/utils/make/Makefile.common ++++ b/utils/make/Makefile.common +@@ -60,7 +60,7 @@ else + PYTHON_LIB_TYPE= + endif + +-CFLAGS = -Wall -std=c++11 -gdwarf-3 -m64 -Werror $(OPTIMIZATION) $(PICKY_FLAGS) $(VISIBILITY) -D $(ARCH_ENUM_HEADER) ++CFLAGS = -Wall -std=c++11 -gdwarf-3 -m64 -Werror $(OPTIMIZATION) $(PICKY_FLAGS) $(VISIBILITY) -D $(ARCH_ENUM_HEADER) -Wno-error=range-loop-construct + LFLAGS = -lpthread -static-libstdc++ -static-libgcc -L$(PYTHON_LIB) -lpython$(PYTHON_VER)$(PYTHON_LIB_TYPE) -lutil -ldl -rdynamic + + ALL_OBJS := $(ALL_SRCS:%.cc=$(OBJ_DIR)/%.o) diff --git a/pkgs/hdl-convertor/0001-to.verilog-fix-always_ff-sensitivity-list.patch b/pkgs/hdl-convertor/0001-to.verilog-fix-always_ff-sensitivity-list.patch new file mode 100644 index 0000000..876751a --- /dev/null +++ b/pkgs/hdl-convertor/0001-to.verilog-fix-always_ff-sensitivity-list.patch @@ -0,0 +1,25 @@ +From 6fa92c4aab7b212de79c023ef8320a9cc6fd45c3 Mon Sep 17 00:00:00 2001 +From: Alejandro Soto +Date: Sun, 2 Apr 2023 00:00:44 -0600 +Subject: [PATCH] to.verilog: fix always_ff sensitivity list + +--- + hdlConvertorAst/to/verilog/stm.py | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/hdlConvertorAst/to/verilog/stm.py b/hdlConvertorAst/to/verilog/stm.py +index 28f3676..7b7dd99 100644 +--- a/hdlConvertorAst/to/verilog/stm.py ++++ b/hdlConvertorAst/to/verilog/stm.py +@@ -92,7 +92,7 @@ class ToVerilog2005Stm(ToVerilog2005Expr): + w("always_latch ") + else: + raise ValueError(proc.trigger_constrain) +- if tr is None: ++ if tr in (None, HdlStmProcessTriggerConstrain.FF): + w("@(") + for last, item in iter_with_last(sens): + self.visit_iHdlExpr(item) +-- +2.38.4 + diff --git a/pkgs/hdl-convertor/0002-to.hdl_ast_-visit-sensitivity-lists.patch b/pkgs/hdl-convertor/0002-to.hdl_ast_-visit-sensitivity-lists.patch new file mode 100644 index 0000000..9e97551 --- /dev/null +++ b/pkgs/hdl-convertor/0002-to.hdl_ast_-visit-sensitivity-lists.patch @@ -0,0 +1,39 @@ +From 495dd2b13abe4aa1f3fb8cd40f6d81706e5c8943 Mon Sep 17 00:00:00 2001 +From: Alejandro Soto +Date: Wed, 5 Apr 2023 13:47:35 -0600 +Subject: [PATCH 2/2] to.hdl_ast_*: visit sensitivity lists + +--- + hdlConvertorAst/to/hdl_ast_modifier.py | 2 ++ + hdlConvertorAst/to/hdl_ast_visitor.py | 2 ++ + 2 files changed, 4 insertions(+) + +diff --git a/hdlConvertorAst/to/hdl_ast_modifier.py b/hdlConvertorAst/to/hdl_ast_modifier.py +index 7431ab9..9289475 100644 +--- a/hdlConvertorAst/to/hdl_ast_modifier.py ++++ b/hdlConvertorAst/to/hdl_ast_modifier.py +@@ -163,6 +163,8 @@ class HdlAstModifier(HdlAstVisitor): + """ + self.visit_doc(o) + o.body = self.visit_iHdlStatement(o.body) ++ if o.sensitivity: ++ self.visit_iHdlObj_list(o.sensitivity, self.visit_iHdlExpr) + return o + + def visit_HdlStmBlock(self, o): +diff --git a/hdlConvertorAst/to/hdl_ast_visitor.py b/hdlConvertorAst/to/hdl_ast_visitor.py +index 5258b74..1441c39 100644 +--- a/hdlConvertorAst/to/hdl_ast_visitor.py ++++ b/hdlConvertorAst/to/hdl_ast_visitor.py +@@ -224,6 +224,8 @@ class HdlAstVisitor(object): + """ + self.visit_doc(o) + self.visit_iHdlStatement(o.body) ++ for expr in o.sensitivity or (): ++ self.visit_iHdlExpr(expr) + return o + + def visit_HdlStmBlock(self, o): +-- +2.38.4 + diff --git a/pkgs/hdl-convertor/ast.nix b/pkgs/hdl-convertor/ast.nix new file mode 100644 index 0000000..52bd656 --- /dev/null +++ b/pkgs/hdl-convertor/ast.nix @@ -0,0 +1,18 @@ +{ lib, buildPythonPackage, fetchFromGitHub }: +buildPythonPackage { + pname = "hdl-convertor-ast"; + version = "master-2022-07-25"; + + src = fetchFromGitHub { + repo = "hdlConvertorAst"; + owner = "Nic30"; + + rev = "d2670f0374bd7a303a4bd8ce60da7206c45e8ac3"; + sha256 = "sha256-u0lBzltM/6l3EuW0ppAVAGWhU7QEx0Cx6mTgaZKdHkg="; + }; + + patches = [ + ./0001-to.verilog-fix-always_ff-sensitivity-list.patch + ./0002-to.hdl_ast_-visit-sensitivity-lists.patch + ]; +} diff --git a/pkgs/hdl-convertor/default.nix b/pkgs/hdl-convertor/default.nix new file mode 100644 index 0000000..08e16d6 --- /dev/null +++ b/pkgs/hdl-convertor/default.nix @@ -0,0 +1,44 @@ +{ antlr +, buildPythonPackage +, cmake +, cython +, fetchFromGitHub +, hdl-convertor-ast +, jre +, python3 +, scikit-build +}: +buildPythonPackage { + pname = "hdl-convertor"; + version = "master-2023-03-21"; + + src = fetchFromGitHub { + repo = "hdlConvertor"; + owner = "Nic30"; + + rev = "b6ba0f4e61adf776cad8ed08760f8d232a4fc663"; + sha256 = "sha256-Ketz5r7Z8kjshr7mjfdqF+QAOHGM/iTDpT6TMbYl6QU="; + }; + + nativeBuildInputs = [ antlr cmake jre cython ]; + propagatedBuildInputs = [ antlr.runtime.cpp hdl-convertor-ast ]; + propagatedNativeBuildInputs = [ scikit-build ]; + + postPatch = '' + sed -i 's/antlr4\(-complete\)/${antlr.name}\1/g' src/CMake_antlr4.txt + ''; + + doCheck = false; + dontUseCmakeConfigure = true; + + # src/CMake_antlr4.txt espera una env var, no hay otra forma + ANTLR_COMPLETE_PATH = "${antlr}/share/java"; + + # No usamos cmakeArgs ya que esto lo interpreta skbuild y no el cmake hook de nixpkgs + CMAKE_ARGS = [ + "-DHDLCONVERTOR_PYTHON=true" + "-DANTLR_COMPLETE_PATH=${antlr}/share/java" + "-DANTLR4CPP_LIBRARIES=${antlr.runtime.cpp}/lib/libantlr4-runtime.so" + "-DANTLR4CPP_INCLUDE_DIRS=${antlr.runtime.cpp.dev}/include/antlr4-runtime" + ]; +} -- cgit v1.2.3