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