~ruther/vhdl-fir-filters

3ab43dbb8068ef8cf499866ea304c02109c8cded — Rutherther 1 year, 1 month ago
chore: environment setup
5 files changed, 145 insertions(+), 0 deletions(-)

A .envrc
A .gitignore
A flake.lock
A flake.nix
A run.py
A  => .envrc +1 -0
@@ 1,1 @@
use flake

A  => .gitignore +12 -0
@@ 1,12 @@
.DS_Store
.idea
*.log
tmp/

work/
out/
sim/
.direnv/

__pycache__/
vunit_out/

A  => flake.lock +27 -0
@@ 1,27 @@
{
  "nodes": {
    "nixpkgs": {
      "locked": {
        "lastModified": 1707588924,
        "narHash": "sha256-0e1ce6X5ghapv6cAF9rxLZKeNyFHHXsLbGxN2cQQE8U=",
        "owner": "NixOS",
        "repo": "nixpkgs",
        "rev": "10b813040df67c4039086db0f6eaf65c536886c6",
        "type": "github"
      },
      "original": {
        "owner": "NixOS",
        "ref": "nixpkgs-unstable",
        "repo": "nixpkgs",
        "type": "github"
      }
    },
    "root": {
      "inputs": {
        "nixpkgs": "nixpkgs"
      }
    }
  },
  "root": "root",
  "version": 7
}

A  => flake.nix +88 -0
@@ 1,88 @@
{
  description = "FIR filter in VHDL";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
  };

  outputs = { self, nixpkgs }:
    let
      system = "x86_64-linux";
      pkgs = import nixpkgs {
        system = "${system}";
      };

      python-env = pkgs.python311.withPackages(ps: [
        (ps.buildPythonPackage rec {
          pname = "vunit-hdl";
          version = "4.7.0";
          src = pkgs.fetchFromGitHub {
            owner = "VUnit";
            repo = "vunit";
            rev = "v4.7.0";
            hash = "sha256-xhCPPnUXUdLg5kElbyJKW0tJOZMUoM1bV2siOsoz3Zs=";
          };

          doCheck = false;

          nativeBuildInputs = [
            ps.setuptoolsBuildHook
            ps.setuptools
            ps.pythonImportsCheckHook

            pkgs.ghdl # VHDL simulator needed for build/testing
            ps.pytest
          ];

          propagatedBuildInputs = [
            ps.colorama
          ];
        })
      ]);
      vhdl-toolchain = pkgs.symlinkJoin {
        name = "vhdl-toolchain";
        meta.mainProgram = "ghdl";
        paths = [
          pkgs.ghdl
          python-env
          pkgs.gtkwave
        ];
      };
    in {
      packages.${system}.default = vhdl-toolchain;

      devShells.${system} = {
        default = pkgs.mkShell {
          packages = [
            vhdl-toolchain

            (pkgs.rustPlatform.buildRustPackage rec {
                pname = "vhdl-ls";
                version = "0.77.0-patched";

                src = pkgs.fetchFromGitHub {
                  owner = "Rutherther";
                  repo = "rust_hdl";
                  rev = "return-new-line";
                  hash = "sha256-EYG6Rycnq9unTTVk9Iy6ivnbr8sT1U7vnNGnnZefSqk=";
                };

                cargoHash = "sha256-YkeepkJLq95e9X2v+1AxMBmT0q4ARJXA1WB89/KmTcY=";

                postPatch = ''
                  substituteInPlace vhdl_lang/src/config.rs \
                    --replace /usr/lib $out/lib
                '';

                postInstall = ''
                  mkdir -p $out/lib/rust_hdl
                  cp -r vhdl_libraries $out/lib/rust_hdl
                '';
            })
          ];

          VUNIT_SIMULATOR = "ghdl";
        };
      };
    };
}

A  => run.py +17 -0
@@ 1,17 @@
#!/usr/bin/env python3

from vunit import VUnit
from pathlib import Path

vu = VUnit.from_argv(compile_builtins = False)

vu.add_vhdl_builtins()
vu.add_com()

filter_tb_lib = vu.add_library('filter_tb')
filter_tb_lib.add_source_files(Path(__file__).parent / 'tb/**/*.vhd')

filter_lib = vu.add_library('filter')
filter_lib.add_source_files(Path(__file__).parent / 'src/**/*.vhd')

vu.main()

Do not follow this link