From cdf8628b1fe75175ba7f6efc4f5b6e3b680ef5a2 Mon Sep 17 00:00:00 2001 From: Paul Cruz Date: Mon, 18 Nov 2024 10:53:53 -0800 Subject: [PATCH] Allow systemd libs to be built from source Summary: X-link: https://github.com/facebookincubator/zstrong/pull/1066 Changes to enable building systemd libs from source (rather than relying on system packages i.e. systemd, systemd-devel). From the FBOSS perspective, this is desirable because statically linking the dependencies into the binaries makes them easier to package without relying on similar state between build and runtime environments. Reviewed By: somasun Differential Revision: D65827936 Privacy Context Container: L1125642 fbshipit-source-id: c0ba2f0690466a969bb4d9a4db664b9a5b3d3d79 --- build/fbcode_builder/getdeps/builder.py | 55 ++++++++++++++++++++++++ build/fbcode_builder/getdeps/manifest.py | 13 ++++++ build/fbcode_builder/manifests/systemd | 9 ++++ 3 files changed, 77 insertions(+) diff --git a/build/fbcode_builder/getdeps/builder.py b/build/fbcode_builder/getdeps/builder.py index 65bca2692..10bd2a62a 100644 --- a/build/fbcode_builder/getdeps/builder.py +++ b/build/fbcode_builder/getdeps/builder.py @@ -487,6 +487,61 @@ def _build(self, reconfigure) -> None: self._run_cmd(install_cmd, env=env) +class SystemdBuilder(BuilderBase): + # SystemdBuilder assumes that meson build tool has already been installed on + # the machine. + def __init__( + self, + loader, + dep_manifests, + build_opts, + ctx, + manifest, + src_dir, + build_dir, + inst_dir, + ) -> None: + super(SystemdBuilder, self).__init__( + loader, + dep_manifests, + build_opts, + ctx, + manifest, + src_dir, + build_dir, + inst_dir, + ) + + def _build(self, reconfigure) -> None: + env = self._compute_env() + meson = path_search(env, "meson") + if meson is None: + raise Exception("Failed to find Meson") + + # Meson builds typically require setup, compile, and install steps. + # During this setup step we ensure that the static library is built and + # the prefix is empty. + self._run_cmd( + [ + meson, + "setup", + "-Dstatic-libsystemd=true", + "-Dprefix=/", + self.build_dir, + self.src_dir, + ] + ) + + # Compile step needs to satisfy the build directory that was previously + # prepared during setup. + self._run_cmd([meson, "compile", "-C", self.build_dir]) + + # Install step + self._run_cmd( + [meson, "install", "-C", self.build_dir, "--destdir", self.inst_dir] + ) + + class CMakeBuilder(BuilderBase): MANUAL_BUILD_SCRIPT = """\ #!{sys.executable} diff --git a/build/fbcode_builder/getdeps/manifest.py b/build/fbcode_builder/getdeps/manifest.py index d02cfe83f..e329da1ee 100644 --- a/build/fbcode_builder/getdeps/manifest.py +++ b/build/fbcode_builder/getdeps/manifest.py @@ -22,6 +22,7 @@ NopBuilder, OpenSSLBuilder, SqliteBuilder, + SystemdBuilder, ) from .cargo import CargoBuilder from .expr import parse_expr @@ -661,6 +662,18 @@ def create_builder( # noqa:C901 inst_dir, ) + if builder == "systemd": + return SystemdBuilder( + loader, + dep_manifests, + build_options, + ctx, + self, + src_dir, + build_dir, + inst_dir, + ) + if builder == "cargo": return self.create_cargo_builder( loader, diff --git a/build/fbcode_builder/manifests/systemd b/build/fbcode_builder/manifests/systemd index 40564970d..0fb2a6f5a 100644 --- a/build/fbcode_builder/manifests/systemd +++ b/build/fbcode_builder/manifests/systemd @@ -4,3 +4,12 @@ name = systemd [rpms] systemd systemd-devel + +[download] +url = https://github.com/systemd/systemd/archive/refs/tags/v256.7.tar.gz +sha256 = 896d76ff65c88f5fd9e42f90d152b0579049158a163431dd77cdc57748b1d7b0 + + +[build] +builder = systemd +subdir = systemd-256.7