diff mbox series

[meta-oe] libperfetto-c: Add recipe

Message ID 20261126185627.1255223-1-ecordonnier@snap.com
State Under Review
Headers show
Series [meta-oe] libperfetto-c: Add recipe | expand

Commit Message

Etienne Cordonnier Nov. 26, 2026, 6:56 p.m. UTC
From: Heinrich Fink <hfink@snap.com>

Upstream only provides the C++ SDK as a static library or amalgamated
source, and strongly discourages building it as a shared library [0].
libperfetto does so anyway. The C SDK is designed as a shared library
[1], so system components may prefer it.

Based on the v59.1 release. The ABI may still break with future
upgrades until officially frozen, so the major SDK version determines
the SO version (libperfetto_c.so.59).

The amalgamated perfetto_c.cc and perfetto_c.h are not part of the
perfetto git tree and are only shipped as a GitHub release asset, so
fetch that tarball and build it with an added meson.build.

Tested by building the recipe with poky master and capturing a trace in
qemux86-64 with tracebox and the upstream C SDK track event example.

[0] https://github.com/google/perfetto/blob/1e9c61e9844affd7dccd3d42d9ea9f3a3d10cf6d/docs/design-docs/api-and-abi.md#L491-L501
[1] https://github.com/google/perfetto/blob/1e9c61e9844affd7dccd3d42d9ea9f3a3d10cf6d/examples/shared_lib/example_shlib_track_event.c

Signed-off-by: Heinrich Fink <hfink@snap.com>
AI-Generated: Uses Claude Code (commit message, file move)
Signed-off-by: Etienne Cordonnier <ecordonnier@snap.com>
---
 .../perfetto/libperfetto-c/libperfetto_c.map  |  8 +++
 .../perfetto/libperfetto-c/meson.build        | 62 +++++++++++++++++++
 .../perfetto/libperfetto-c_59.1.bb            | 22 +++++++
 3 files changed, 92 insertions(+)
 create mode 100644 meta-oe/recipes-devtools/perfetto/libperfetto-c/libperfetto_c.map
 create mode 100644 meta-oe/recipes-devtools/perfetto/libperfetto-c/meson.build
 create mode 100644 meta-oe/recipes-devtools/perfetto/libperfetto-c_59.1.bb
diff mbox series

Patch

diff --git a/meta-oe/recipes-devtools/perfetto/libperfetto-c/libperfetto_c.map b/meta-oe/recipes-devtools/perfetto/libperfetto-c/libperfetto_c.map
new file mode 100644
index 0000000000..62771847df
--- /dev/null
+++ b/meta-oe/recipes-devtools/perfetto/libperfetto-c/libperfetto_c.map
@@ -0,0 +1,8 @@ 
+{
+  global:
+    perfetto_*;
+    Perfetto*;
+
+  local:
+    *;
+};
diff --git a/meta-oe/recipes-devtools/perfetto/libperfetto-c/meson.build b/meta-oe/recipes-devtools/perfetto/libperfetto-c/meson.build
new file mode 100644
index 0000000000..6e367ed1a1
--- /dev/null
+++ b/meta-oe/recipes-devtools/perfetto/libperfetto-c/meson.build
@@ -0,0 +1,62 @@ 
+project(
+  'libperfetto-c',
+  ['cpp'],
+  version : files('VERSION'),
+  license : 'Apache-2.0',
+  default_options : [
+    'cpp_std=c++17',
+    'warning_level=1',
+  ],
+)
+
+mapfile = join_paths(meson.current_source_dir(), 'libperfetto_c.map')
+
+thread_dep = dependency('threads')
+
+cpp = meson.get_compiler('cpp')
+
+perfetto_c_cpp_args = []
+perfetto_c_cpp_args += cpp.get_supported_arguments([
+  '-ffunction-sections',
+  '-fdata-sections',
+  '-fno-exceptions',
+  '-fno-rtti',
+])
+
+perfetto_c_link_args = []
+perfetto_c_link_args += cpp.get_supported_link_arguments([
+  '-static-libstdc++',
+  '-Wl,--exclude-libs,ALL',
+  '-Wl,--gc-sections',
+  '-Wl,--icf=all',
+])
+
+perfetto_c = shared_library(
+  'perfetto_c',
+  'perfetto_c.cc',
+  dependencies : [thread_dep],
+  install : true,
+  version : meson.project_version(),
+  gnu_symbol_visibility : 'inlineshidden',
+  cpp_args : [
+    perfetto_c_cpp_args,
+    '-DPERFETTO_SDK_SHLIB_IMPLEMENTATION',
+  ],
+  link_args: [
+    perfetto_c_link_args,
+    '-Wl,--version-script=' + mapfile,
+  ],
+  link_depends : mapfile,
+)
+
+install_headers('perfetto_c.h')
+
+pkg = import('pkgconfig')
+pkg.generate(
+  perfetto_c,
+  name : 'libperfetto_c',
+  filebase : 'libperfetto_c',
+  description : 'Perfetto C SDK shared library',
+  version : meson.project_version(),
+  extra_cflags : ['-DPERFETTO_SDK_SHLIB'],
+)
diff --git a/meta-oe/recipes-devtools/perfetto/libperfetto-c_59.1.bb b/meta-oe/recipes-devtools/perfetto/libperfetto-c_59.1.bb
new file mode 100644
index 0000000000..b4ba9be850
--- /dev/null
+++ b/meta-oe/recipes-devtools/perfetto/libperfetto-c_59.1.bb
@@ -0,0 +1,22 @@ 
+SUMMARY = "Perfetto C SDK shared library"
+DESCRIPTION = "Shared library built from the amalgamated Perfetto C SDK sources"
+HOMEPAGE = "https://perfetto.dev"
+LICENSE = "Apache-2.0"
+
+LIC_FILES_CHKSUM = "file://LICENSE;md5=0b17e8eda713c18363c16102cacd41f3"
+
+SRC_URI = "\
+    https://github.com/google/perfetto/releases/download/v${PV}/perfetto-c-sdk-src.zip;downloadfilename=${BPN}-${PV}.zip;subdir=${BP} \
+    file://meson.build;subdir=${BP} \
+    file://libperfetto_c.map;subdir=${BP} \
+"
+
+SRC_URI[sha256sum] = "28d497a5b01c7517b2084c4b4768a1fdbbac587242775af50f5219936056361f"
+
+S = "${UNPACKDIR}/${BP}"
+
+inherit meson
+
+do_configure:prepend() {
+    echo "${PV}" > ${S}/VERSION
+}