|
| 1 | +package = { |
| 2 | + spec = "1", |
| 3 | + namespace = "compat", |
| 4 | + name = "libsystemd", |
| 5 | + description = "Public systemd client library for Linux", |
| 6 | + licenses = { "LGPL-2.1-or-later" }, |
| 7 | + repo = "https://github.com/systemd/systemd", |
| 8 | + type = "package", |
| 9 | + extensions = { |
| 10 | + autoupdate = { |
| 11 | + tag = "v${version}", |
| 12 | + url = "https://github.com/systemd/systemd/archive/refs/tags/${tag}.tar.gz", |
| 13 | + }, |
| 14 | + }, |
| 15 | + xpm = { |
| 16 | + linux = { |
| 17 | + ["262.2"] = { |
| 18 | + url = "https://github.com/systemd/systemd/archive/refs/tags/v262.2.tar.gz", |
| 19 | + sha256 = "116432ee9dce9bfef4c7da7963c6de41899ab44197f2876ee99545707a5c7c1f", |
| 20 | + }, |
| 21 | + }, |
| 22 | + }, |
| 23 | + mcpp = { |
| 24 | + language = "c++23", |
| 25 | + import_std = false, |
| 26 | + c_standard = "c11", |
| 27 | + include_dirs = { "include" }, |
| 28 | + license_files = { "LICENSE.LGPL2.1", "LICENSES/*.txt" }, |
| 29 | + generated_files = { |
| 30 | + ["mcpp_generated/libsystemd_anchor.c"] = |
| 31 | + "int mcpp_compat_libsystemd_anchor(void) { return 0; }\n", |
| 32 | + }, |
| 33 | + sources = { "mcpp_generated/libsystemd_anchor.c" }, |
| 34 | + targets = { ["systemd_binding"] = { kind = "lib" } }, |
| 35 | + provides = { "platform-sdk" }, |
| 36 | + ldflags = { "-l:libsystemd.so.0" }, |
| 37 | + runtime = { |
| 38 | + link_library_dirs = { "lib" }, |
| 39 | + runtime_search_dirs = { "lib" }, |
| 40 | + deploy = { |
| 41 | + { from = "lib/libsystemd.so.0", to = "lib" }, |
| 42 | + { from = "LICENSE.LGPL2.1", to = "licenses/libsystemd" }, |
| 43 | + { from = "LICENSES/*", to = "licenses/libsystemd/LICENSES" }, |
| 44 | + }, |
| 45 | + }, |
| 46 | + }, |
| 47 | +} |
| 48 | + |
| 49 | +import("xim.libxpkg.pkginfo") |
| 50 | +import("xim.libxpkg.log") |
| 51 | + |
| 52 | +local function quote(value) |
| 53 | + return "'" .. tostring(value):gsub("'", "'\\''") .. "'" |
| 54 | +end |
| 55 | + |
| 56 | +local function run(command, logfile) |
| 57 | + local ok, success = pcall(os.exec, command .. " >> " .. quote(logfile) .. " 2>&1") |
| 58 | + if ok and success then return true end |
| 59 | + log.error("compat.libsystemd build failed. Install Meson, Ninja, gperf, rsync, Python 3 with Jinja2, and the XZ, LZ4 and Zstandard development packages.\n%s", |
| 60 | + io.readfile(logfile) or logfile) |
| 61 | + return false |
| 62 | +end |
| 63 | + |
| 64 | +function install() |
| 65 | + local source = "systemd-" .. pkginfo.version() |
| 66 | + if not os.isfile(path.join(source, "meson.build")) then |
| 67 | + log.error("compat.libsystemd: source archive is missing meson.build") |
| 68 | + return false |
| 69 | + end |
| 70 | + |
| 71 | + local prefix = pkginfo.install_dir() |
| 72 | + local build = path.join(prefix, "build") |
| 73 | + os.mkdir(prefix) |
| 74 | + local logfile = path.join(prefix, "mcpp_libsystemd_build.log") |
| 75 | + io.writefile(logfile, "") |
| 76 | + |
| 77 | + -- Meson must use the interpreter that owns the system Jinja2 package. |
| 78 | + local native = path.join(prefix, "meson-native.ini") |
| 79 | + io.writefile(native, "[binaries]\npython = '/usr/bin/python3'\n") |
| 80 | + |
| 81 | + local options = " --prefix=/usr --libdir=lib --includedir=include --buildtype=release --auto-features=disabled" |
| 82 | + .. " -Dmode=release -Dlibc=glibc -Dtests=false -Dtranslations=false" |
| 83 | + .. " -Dstatic-libsystemd=false -Dman=disabled -Db_lto=false" |
| 84 | + .. " -Dxz=enabled -Dlz4=enabled -Dzstd=enabled -Ddefault-compression=zstd" |
| 85 | + local setup = "CC=/usr/bin/cc CXX=/usr/bin/c++ meson setup --native-file " .. quote(native) .. " " |
| 86 | + .. quote(build) .. " " .. quote(source) .. options |
| 87 | + if not run(setup, logfile) then return false end |
| 88 | + local jobs = math.max(1, math.min(tonumber(os.getenv("MCPP_JOBS")) or 4, 4)) |
| 89 | + if not run("meson compile -C " .. quote(build) .. " -j " .. jobs .. " libsystemd", logfile) then |
| 90 | + return false |
| 91 | + end |
| 92 | + |
| 93 | + -- Meson's install metadata excludes systemd's internal headers. |
| 94 | + local stage = [==[ |
| 95 | +import json |
| 96 | +import shutil |
| 97 | +import sys |
| 98 | +from pathlib import Path |
| 99 | +
|
| 100 | +build, prefix = map(Path, sys.argv[1:]) |
| 101 | +installed = json.loads((build / "meson-info/intro-installed.json").read_text()) |
| 102 | +headers = prefix / "include/systemd" |
| 103 | +headers.mkdir(parents=True, exist_ok=True) |
| 104 | +for src, dest in installed.items(): |
| 105 | + if isinstance(dest, str) and Path(dest).parent == Path("/usr/include/systemd"): |
| 106 | + shutil.copy2(src, headers / Path(dest).name) |
| 107 | +if not (headers / "sd-daemon.h").is_file(): |
| 108 | + raise RuntimeError("Missing public systemd headers in Meson install metadata") |
| 109 | +lib = prefix / "lib" |
| 110 | +lib.mkdir(exist_ok=True) |
| 111 | +shutil.copy2(build / "libsystemd.so.0", lib / "libsystemd.so.0") |
| 112 | +]==] |
| 113 | + if not run("/usr/bin/python3 -c " .. quote(stage) .. " " .. quote(build) .. " " .. quote(prefix), logfile) then |
| 114 | + return false |
| 115 | + end |
| 116 | + os.cp(path.join(source, "LICENSE.LGPL2.1"), prefix) |
| 117 | + os.cp(path.join(source, "LICENSES"), prefix) |
| 118 | + os.tryrm(build) |
| 119 | + return true |
| 120 | +end |
0 commit comments