summary refs log tree commit diff
path: root/pkgs/development/compilers/p4c/default.nix
blob: 9233489b06aeb2e4c7e0b063572f6bd4be874516 (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
{ lib
, stdenv
, fetchFromGitHub
, cmake
, boehmgc
, bison
, flex
, protobuf
, gmp
, boost
, python3
, doxygen
, graphviz
, libbpf
, libllvm
, enableDocumentation ? true
, enableBPF ? true
, enableDPDK ? true
, enableBMV2 ? true
, enableGraphBackend ? true
, enableP4Tests ? true
, enableGTests ? true
, enableMultithreading ? false
}:
let
  toCMakeBoolean = v: if v then "ON" else "OFF";
in
stdenv.mkDerivation rec {
  pname = "p4c";
  version = "1.2.3.2";

  src = fetchFromGitHub {
    owner = "p4lang";
    repo = "p4c";
    rev = "v${version}";
    sha256 = "sha256-EeTYH7CsmPPBL05zJ+g4aM677n0NqDD+H40lBuKpY6M=";
    fetchSubmodules = true;
  };

  postFetch = ''
    rm -rf backends/ebpf/runtime/contrib/libbpf
    rm -rf control-plane/p4runtime
  '';

  cmakeFlags = [
    "-DENABLE_BMV2=${toCMakeBoolean enableBMV2}"
    "-DENABLE_EBPF=${toCMakeBoolean enableBPF}"
    "-DENABLE_UBPF=${toCMakeBoolean enableBPF}"
    "-DENABLE_DPDK=${toCMakeBoolean enableDPDK}"
    "-DENABLE_P4C_GRAPHS=${toCMakeBoolean enableGraphBackend}"
    "-DENABLE_P4TEST=${toCMakeBoolean enableP4Tests}"
    "-DENABLE_DOCS=${toCMakeBoolean enableDocumentation}"
    "-DENABLE_GC=ON"
    "-DENABLE_GTESTS=${toCMakeBoolean enableGTests}"
    "-DENABLE_PROTOBUF_STATIC=OFF"  # static protobuf has been removed since 3.21.6
    "-DENABLE_MULTITHREAD=${toCMakeBoolean enableMultithreading}"
    "-DENABLE_GMP=ON"
  ];

  checkTarget = "check";

  strictDeps = true;

  nativeBuildInputs = [
    bison
    flex
    cmake
  ]
  ++ lib.optional enableDocumentation [ doxygen graphviz ]
  ++ lib.optional enableBPF [ libllvm libbpf ];

  buildInputs = [
    protobuf
    boost
    boehmgc
    gmp
    flex
    python3
  ];

  meta = with lib; {
    homepage = "https://github.com/p4lang/p4c";
    description = "Reference compiler for the P4 programming language";
    platforms = platforms.linux;
    maintainers = with maintainers; [ raitobezarius ];
    license = licenses.asl20;
  };
}