summary refs log tree commit diff
path: root/pkgs/development/compilers/yosys/plugins/synlig.nix
blob: cc4ce429b3113afb5dd817eee1acf98ad56e1caf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
{ stdenv
, lib
, fetchFromGitHub
, pkg-config
, antlr4
, capnproto
, readline
, surelog
, uhdm
, yosys
}:

stdenv.mkDerivation (finalAttrs: {
  pname = "yosys-synlig";
  plugin = "synlig";

  # The module has automatic regular releases, with date + short git hash
  GIT_VERSION = "2023-10-26-f0252f6";

  # Derive our package version from GIT_VERSION, remove hash, just keep date.
  version = builtins.concatStringsSep "-" (
    lib.take 3 (builtins.splitVersion finalAttrs.GIT_VERSION));

  src = fetchFromGitHub {
    owner = "chipsalliance";
    repo  = "synlig";
    rev   = "${finalAttrs.GIT_VERSION}";
    hash  = "sha256-BGZQbUcIImpz3SjFvMq3Pr1lseNLZnsMvpHy0IsICe4=";
    fetchSubmodules = false;  # we use all dependencies from nix
  };

  nativeBuildInputs = [
    pkg-config
  ];

  buildInputs = [
    antlr4.runtime.cpp
    capnproto
    readline
    surelog
    uhdm
    yosys
  ];

  buildPhase = ''
    runHook preBuild

    # Remove assumptions that submodules are available.
    rm -f third_party/Build.*.mk

    # Create a stub makefile include that delegates the parameter-gathering
    # to yosys-config
    cat > third_party/Build.yosys.mk << "EOF"
    t  := yosys
    ts := ''$(call GetTargetStructName,''${t})

    ''${ts}.src_dir   := ''$(shell yosys-config --datdir/include)
    ''${ts}.mod_dir   := ''${TOP_DIR}third_party/yosys_mod/
    EOF

    make -j $NIX_BUILD_CORES build@systemverilog-plugin \
            LDFLAGS="''$(yosys-config --ldflags --ldlibs)"
    runHook postBuild
  '';

  # Check that the plugin can be loaded successfully and parse simple file.
  doCheck = true;
  checkPhase = ''
     runHook preCheck
     echo "module litmustest(); endmodule;" > litmustest.sv
     yosys -p "plugin -i build/release/systemverilog-plugin/systemverilog.so;\
               read_systemverilog litmustest.sv"
     runHook postCheck
  '';

  installPhase = ''
    runHook preInstall
    mkdir -p $out/share/yosys/plugins
    cp ./build/release/systemverilog-plugin/systemverilog.so \
           $out/share/yosys/plugins/systemverilog.so
    runHook postInstall
  '';

  meta = with lib; {
    description = "SystemVerilog support plugin for Yosys";
    homepage    = "https://github.com/chipsalliance/synlig";
    license     = licenses.asl20;
    maintainers = with maintainers; [ hzeller ];
    platforms   = platforms.all;
  };
})