Skip to content

Commit

Permalink
Allow systemd libs to be built from source
Browse files Browse the repository at this point in the history
Summary:
X-link: facebookincubator/zstrong#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
  • Loading branch information
paulcruz74 authored and facebook-github-bot committed Nov 18, 2024
1 parent 4e0f677 commit cdf8628
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
55 changes: 55 additions & 0 deletions build/fbcode_builder/getdeps/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
13 changes: 13 additions & 0 deletions build/fbcode_builder/getdeps/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
NopBuilder,
OpenSSLBuilder,
SqliteBuilder,
SystemdBuilder,
)
from .cargo import CargoBuilder
from .expr import parse_expr
Expand Down Expand Up @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions build/fbcode_builder/manifests/systemd
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit cdf8628

Please sign in to comment.