|
| 1 | +{ |
| 2 | + cmake, |
| 3 | + fetchFromGitHub, |
| 4 | + fetchurl, |
| 5 | + lib, |
| 6 | + nix-update-script, |
| 7 | + pkg-config, |
| 8 | + stdenv, |
| 9 | + testers, |
| 10 | + unzip, |
| 11 | +}: |
| 12 | + |
| 13 | +let |
| 14 | + inherit (stdenv.hostPlatform) isStatic isDarwin; |
| 15 | + libName = "libperfetto${if isStatic then ".a" else stdenv.hostPlatform.extensions.sharedLibrary}"; |
| 16 | + |
| 17 | + version = "57.2"; |
| 18 | +in |
| 19 | +stdenv.mkDerivation (finalAttrs: { |
| 20 | + pname = "perfetto-sdk"; |
| 21 | + inherit version; |
| 22 | + |
| 23 | + # The amalgamated SDK sources (a single perfetto.cc / perfetto.h pair) are |
| 24 | + # published as a release artifact, skipping the need for the heavy Google build chain. |
| 25 | + src = fetchurl { |
| 26 | + url = "https://github.com/google/perfetto/releases/download/v${finalAttrs.version}/perfetto-cpp-sdk-src.zip"; |
| 27 | + hash = "sha256-xvo9ia7jD32jlALJzReMny40RUT9pcIQn9hFfjGcOi8="; |
| 28 | + }; |
| 29 | + |
| 30 | + nativeBuildInputs = [ unzip ]; |
| 31 | + |
| 32 | + strictDeps = true; |
| 33 | + sourceRoot = "."; |
| 34 | + |
| 35 | + # The release artifact ships no build system |
| 36 | + buildPhase = '' |
| 37 | + runHook preBuild |
| 38 | +
|
| 39 | + $CXX $CXXFLAGS -std=c++17 -fPIC -O2 -c perfetto.cc -o perfetto.o |
| 40 | + ${ |
| 41 | + if isStatic then |
| 42 | + "$AR rcs libperfetto.a perfetto.o" |
| 43 | + else |
| 44 | + "$CXX $CXXFLAGS $LDFLAGS ${ |
| 45 | + if isDarwin then "-dynamiclib -install_name $out/lib/" else "-shared -lpthread -Wl,-soname," |
| 46 | + }${libName} -o ${libName} perfetto.o" |
| 47 | + } |
| 48 | +
|
| 49 | + runHook postBuild |
| 50 | + ''; |
| 51 | + |
| 52 | + installPhase = '' |
| 53 | + runHook preInstall |
| 54 | +
|
| 55 | + install -Dm${if isStatic then "644" else "755"} ${libName} $out/lib/${libName} |
| 56 | + install -Dm644 perfetto.h $out/include/perfetto.h |
| 57 | +
|
| 58 | + mkdir -p $out/lib/pkgconfig |
| 59 | + cat -> $out/lib/pkgconfig/perfetto.pc << EOF |
| 60 | + prefix=$out |
| 61 | + exec_prefix=\''${prefix} |
| 62 | + libdir=\''${exec_prefix}/lib |
| 63 | + includedir=\''${prefix}/include |
| 64 | +
|
| 65 | + Name: perfetto |
| 66 | + Description: Perfetto tracing SDK (amalgamated C++ distribution) |
| 67 | + Version: ${finalAttrs.version} |
| 68 | + Cflags: -I\''${includedir} |
| 69 | + Libs: -L\''${libdir} -lperfetto |
| 70 | + Libs.private: -lpthread |
| 71 | + EOF |
| 72 | +
|
| 73 | + runHook postInstall |
| 74 | + ''; |
| 75 | + |
| 76 | + passthru = { |
| 77 | + tests = { |
| 78 | + pkg-config = testers.hasPkgConfigModules { |
| 79 | + package = finalAttrs.finalPackage; |
| 80 | + }; |
| 81 | + |
| 82 | + examples = |
| 83 | + let |
| 84 | + src = fetchFromGitHub { |
| 85 | + owner = "google"; |
| 86 | + repo = "perfetto"; |
| 87 | + tag = "v${version}"; |
| 88 | + hash = "sha256-0Syqu43M+XWD15I3qSNaL8Vck6bconRz+6aK4V+0pBA="; |
| 89 | + sparseCheckout = [ "examples/sdk" ]; |
| 90 | + }; |
| 91 | + in |
| 92 | + (stdenv.mkDerivation { |
| 93 | + pname = "perfetto-sdk-examples"; |
| 94 | + inherit version src; |
| 95 | + |
| 96 | + postPatch = '' |
| 97 | + substituteInPlace CMakeLists.txt --replace-fail "add_library(perfetto STATIC ../../sdk/perfetto.cc)" " |
| 98 | + find_package(PkgConfig REQUIRED) |
| 99 | + pkg_check_modules(PERFETTO REQUIRED IMPORTED_TARGET perfetto) |
| 100 | + add_library(perfetto ALIAS PkgConfig::PERFETTO) |
| 101 | + " |
| 102 | + ''; |
| 103 | + |
| 104 | + sourceRoot = "${src.name}/examples/sdk"; |
| 105 | + |
| 106 | + nativeBuildInputs = [ |
| 107 | + cmake |
| 108 | + finalAttrs.finalPackage |
| 109 | + pkg-config |
| 110 | + ]; |
| 111 | + |
| 112 | + # The examples have no install rules. example_system_wide is a long running process, we |
| 113 | + # still build it to ensure it compiles but won't bother trying to run it. |
| 114 | + installPhase = '' |
| 115 | + runHook preInstall |
| 116 | +
|
| 117 | + find . -maxdepth 1 -type f -executable -not -name example_system_wide -exec install -Dt $out/bin {} + |
| 118 | +
|
| 119 | + runHook postInstall |
| 120 | + ''; |
| 121 | + doInstallCheck = true; |
| 122 | + installCheckPhase = '' |
| 123 | + runHook preInstallCheck |
| 124 | +
|
| 125 | + for bin in $out/bin/*; do |
| 126 | + echo "Running $bin" |
| 127 | + "$bin" |
| 128 | + done |
| 129 | +
|
| 130 | + runHook postInstallCheck |
| 131 | + ''; |
| 132 | + }); |
| 133 | + }; |
| 134 | + |
| 135 | + updateScript = nix-update-script { |
| 136 | + extraArgs = [ |
| 137 | + "--subpackage" |
| 138 | + "tests.examples" |
| 139 | + ]; |
| 140 | + }; |
| 141 | + }; |
| 142 | + |
| 143 | + meta = { |
| 144 | + description = "Perfetto tracing SDK, the client library used to emit traces"; |
| 145 | + longDescription = '' |
| 146 | + The amalgamated C++ distribution of the Perfetto SDK, i.e. the library an |
| 147 | + application links against to become a Perfetto producer. Tools such as |
| 148 | + `traced` or `trace_processor` are not part of this package. |
| 149 | + ''; |
| 150 | + homepage = "https://perfetto.dev/"; |
| 151 | + changelog = "https://github.com/google/perfetto/releases/tag/v${finalAttrs.version}"; |
| 152 | + license = lib.licenses.asl20; |
| 153 | + maintainers = with lib.maintainers; [ aduh95 ]; |
| 154 | + pkgConfigModules = [ "perfetto" ]; |
| 155 | + platforms = lib.platforms.unix; |
| 156 | + }; |
| 157 | +}) |
0 commit comments