1{ lib
2, stdenv
3, fetchFromGitHub
4, cmake
5, boehmgc
6, bison
7, flex
8, protobuf
9, gmp
10, boost
11, python3
12, doxygen
13, graphviz
14, libbpf
15, libllvm
16, enableDocumentation ? true
17, enableBPF ? true
18, enableDPDK ? true
19, enableBMV2 ? true
20, enableGraphBackend ? true
21, enableP4Tests ? true
22, enableGTests ? true
23, enableMultithreading ? false
24}:
25let
26 toCMakeBoolean = v: if v then "ON" else "OFF";
27in
28stdenv.mkDerivation rec {
29 pname = "p4c";
30 version = "1.2.3.9";
31
32 src = fetchFromGitHub {
33 owner = "p4lang";
34 repo = "p4c";
35 rev = "v${version}";
36 sha256 = "sha256-mnJluusDei95B6LMAwre8FjjxwlpK99tzvzLwroQQsM=";
37 fetchSubmodules = true;
38 };
39
40 postFetch = ''
41 rm -rf backends/ebpf/runtime/contrib/libbpf
42 rm -rf control-plane/p4runtime
43 '';
44
45 cmakeFlags = [
46 "-DENABLE_BMV2=${toCMakeBoolean enableBMV2}"
47 "-DENABLE_EBPF=${toCMakeBoolean enableBPF}"
48 "-DENABLE_UBPF=${toCMakeBoolean enableBPF}"
49 "-DENABLE_DPDK=${toCMakeBoolean enableDPDK}"
50 "-DENABLE_P4C_GRAPHS=${toCMakeBoolean enableGraphBackend}"
51 "-DENABLE_P4TEST=${toCMakeBoolean enableP4Tests}"
52 "-DENABLE_DOCS=${toCMakeBoolean enableDocumentation}"
53 "-DENABLE_GC=ON"
54 "-DENABLE_GTESTS=${toCMakeBoolean enableGTests}"
55 "-DENABLE_PROTOBUF_STATIC=OFF" # static protobuf has been removed since 3.21.6
56 "-DENABLE_MULTITHREAD=${toCMakeBoolean enableMultithreading}"
57 "-DENABLE_GMP=ON"
58 ];
59
60 checkTarget = "check";
61
62 strictDeps = true;
63
64 nativeBuildInputs = [
65 bison
66 flex
67 cmake
68 ]
69 ++ lib.optionals enableDocumentation [ doxygen graphviz ]
70 ++ lib.optionals enableBPF [ libllvm libbpf ];
71
72 buildInputs = [
73 protobuf
74 boost
75 boehmgc
76 gmp
77 flex
78 python3
79 ];
80
81 meta = with lib; {
82 homepage = "https://github.com/p4lang/p4c";
83 changelog = "https://github.com/p4lang/p4c/releases";
84 description = "Reference compiler for the P4 programming language";
85 platforms = platforms.linux;
86 maintainers = with maintainers; [ raitobezarius govanify ];
87 license = licenses.asl20;
88 };
89}