Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
242 changes: 242 additions & 0 deletions mission-center.be0
Original file line number Diff line number Diff line change
@@ -0,0 +1,242 @@
#!/usr/bin/env beesh

# BEE_VERSION mission-center-1.2.0-0

# Mission Center, a GTK4/libadwaita system monitor for GNOME
# (https://missioncenter.io/, https://gitlab.com/mission-center-devs/mission-center)
#
# This is a deep rabbit hole, built from three separate repositories plus a
# vendored copy of a fourth project's C sources, none of which ship as a tidy
# single release tarball:
#
# * mission-center itself (SRCURL[0]) is the GTK4 app. It needs libadwaita
# (>= 1.9, for the "v1_9" gtk-rs feature) and blueprint-compiler (to turn
# resources/ui/*.blp into *.ui at build time), neither of which is provided
# by this repository.
#
# * Its sensor backend, "magpie" (SRCURL[1]), lives in a separate gitlab
# project (mission-center-devs/gng) and is wired in as a git submodule.
# GitLab's release/archive tarballs never embed submodule content, so the
# pinned commit has to be fetched on its own. Found the pin with:
# curl https://gitlab.com/api/v4/projects/mission-center-devs%2Fmission-center/repository/tree?ref=v1.2.0\&path=subprojects
# (a "type": "commit" entry for path "subprojects/magpie"), then fetched:
# https://gitlab.com/api/v4/projects/mission-center-devs%2Fgng/repository/archive.tar.gz?sha=a5272b3c1d853caa4044b737cf49257bfc4c86f2
#
# * magpie in turn has its own nested submodule, "app-rummage" (SRCURL[2],
# mission-center-devs/app-detection), found and fetched the same way:
# curl https://gitlab.com/api/v4/projects/mission-center-devs%2Fgng/repository/tree?ref=a5272b3c1d853caa4044b737cf49257bfc4c86f2\&path=platform-linux/crates
# https://gitlab.com/api/v4/projects/59887601/repository/archive.tar.gz?sha=26b93b8c6f0de6912f0a17022f7ece76bad87612
#
# * blueprint-compiler (SRCURL[3]) is wired in as a meson wrap-file subproject
# (subprojects/blueprint-compiler.wrap) that meson would otherwise download
# from GitHub at configure time. Pre-placing the extracted tarball at the
# wrap's "directory" is enough for --wrap-mode=nodownload to pick it up
# instead, with no patch needed. It's a build-time-only tool (PyGObject,
# already satisfied by gtk4.be0 + gobject-introspection.be0); see
# mee_install() for the one stray file it installs anyway.
#
# * libadwaita (SRCURL[4]) is built privately and only its shared library is
# installed, into ${PREFIX}/lib/mission-center, exactly like ghostty.be0
# does it (see that file for why, and for the real upstream URL -- this
# reuses the exact same already-mirrored 1.9.4 tarball instead of uploading
# a second copy). Unlike ghostty, blueprint-compiler needs to resolve
# "using Adw 1;" via GObject-Introspection, so, unlike ghostty's copy, this
# one is built with -Dintrospection=enabled.
#
# * Both missioncenter's own Cargo.lock and magpie's (two independent
# workspaces, built by separate `cargo build` invocations under meson) are
# pre-vendored (SRCURL[5], SRCURL[6]) so neither touches the network:
# cd mission-center-1.2.0 && cargo vendor vendor
# cd subprojects/magpie && cargo vendor vendor
# (the magpie vendor also covers its one git dependency, upower_dbus).
#
# * magpie's build.rs fetches a patched copy of upstream nvtop's GPU-metrics
# C sources via plain HTTP (not through cargo, so CARGO_NET_OFFLINE does
# nothing for it), at the commit/hash recorded in
# subprojects/magpie/platform-linux/3rdparty/nvtop/nvtop.json. SRCURL[7]
# mirrors that exact tarball; mee_build() pre-seeds it (patched, with the
# same patches build.rs would apply) at the cache path build.rs computes,
# so its "already there" check short-circuits before any network call.

#SRCURL[0]="https://gitlab.com/mission-center-devs/mission-center/-/archive/v1.2.0/mission-center-v1.2.0.tar.gz"
SRCURL[0]="https://beehive.molgen.mpg.de/4ed03428021bedec7aa69686fb021e46/mission-center-1.2.0.tar.gz"

#SRCURL[1]="https://gitlab.com/api/v4/projects/mission-center-devs%2Fgng/repository/archive.tar.gz?sha=a5272b3c1d853caa4044b737cf49257bfc4c86f2"
SRCURL[1]="https://beehive.molgen.mpg.de/8d4bb7df126d63dbde563bb13ace2c46/magpie.tar.gz"

#SRCURL[2]="https://gitlab.com/api/v4/projects/59887601/repository/archive.tar.gz?sha=26b93b8c6f0de6912f0a17022f7ece76bad87612"
SRCURL[2]="https://beehive.molgen.mpg.de/06eef693c2cee5fa69900ce71adbb395/app-rummage.tar.gz"

#SRCURL[3]="https://github.com/GNOME/blueprint-compiler/archive/refs/tags/0.18.0.tar.gz"
SRCURL[3]="https://beehive.molgen.mpg.de/c51bb52eb3e5e24c1960adc3a276ca87/blueprint-compiler-v0.18.0.tar.gz"

# private libadwaita, see ghostty.be0
SRCURL[4]="https://beehive.molgen.mpg.de/7cabde6b8ca6a4865dde66b09b60240f/libadwaita-1.9.4.tar.xz"

# `cargo vendor` output, see above
SRCURL[5]="https://beehive.molgen.mpg.de/e846bf25e5585587a59fc945f479c4f1/mission-center-1.2.0-cargo-vendor.tar.xz"
SRCURL[6]="https://beehive.molgen.mpg.de/590cfb1f5d2e4f7367be57ae2218f585/magpie-a5272b3c-cargo-vendor.tar.xz"

#SRCURL[7]="https://github.com/Syllo/nvtop/archive/3d4a953da02bc18886734613bb9f60ff80669de7.tar.gz"
SRCURL[7]="https://beehive.molgen.mpg.de/d4534c6a691048bb12425cb169efb651/nvtop-3d4a953da02bc18886734613bb9f60ff80669de7.tar.gz"

# PATCHURL+=()

# build_in_sourcedir

# sourcesubdir_append src

mee_extract() {
# mission-center-1.2.0/... -> ${S}
bee_extract "${1}"

# gng-<rev>/... -> ${S}/subprojects/magpie
mkdir -p ${S}/subprojects/magpie
bee_extract_do_tar "${2}" ${S}/subprojects/magpie --strip-components 1

# app-detection-<rev>/... -> .../magpie/platform-linux/crates/app-rummage
mkdir -p ${S}/subprojects/magpie/platform-linux/crates/app-rummage
bee_extract_do_tar "${3}" ${S}/subprojects/magpie/platform-linux/crates/app-rummage --strip-components 1

# blueprint-compiler-0.18.0/... -> ${S}/subprojects/blueprint-compiler-0.18.0
# (matches the "directory" the .wrap file names; --wrap-mode=nodownload
# uses it as-is instead of fetching)
mkdir -p ${S}/subprojects/blueprint-compiler-0.18.0
bee_extract_do_tar "${4}" ${S}/subprojects/blueprint-compiler-0.18.0 --strip-components 1

# libadwaita-1.9.4/... -> ${B}/libadwaita-src, private, see mee_configure()
mkdir -p ${B}/libadwaita-src
bee_extract_do_tar "${5}" ${B}/libadwaita-src --strip-components 1

# pre-fetched `cargo vendor` trees, one per independent Cargo workspace
bee_extract_do_tar "${6}" ${S}
bee_extract_do_tar "${7}" ${S}/subprojects/magpie

# ${8} (nvtop source) is intentionally left untouched in ${F}; it is
# consumed directly from there by mee_build(), see above.
}

#mee_patch() {
# bee_patch "${@}"
#}

mee_configure() {
p=/pkg/rustc-1.97.0-0/profile; [ -e $p ] && . $p

# private libadwaita, only its shared library is installed (mee_install);
# introspection is required so blueprint-compiler can resolve "using Adw 1"
start_cmd meson setup ${B}/libadwaita-build ${B}/libadwaita-src \
--prefix=${B}/libadwaita \
--libdir=lib \
--buildtype=release \
-Dtests=false \
-Dexamples=false \
-Dvapi=false \
-Dintrospection=enabled \
-Ddocumentation=false
start_cmd ninja -C ${B}/libadwaita-build
start_cmd ninja -C ${B}/libadwaita-build install

export PKG_CONFIG_PATH=${B}/libadwaita/lib/pkgconfig${PKG_CONFIG_PATH:+:${PKG_CONFIG_PATH}}
export GI_TYPELIB_PATH=${B}/libadwaita/lib/girepository-1.0${GI_TYPELIB_PATH:+:${GI_TYPELIB_PATH}}

start_cmd meson setup ${B}/build ${S} \
--prefix=${PREFIX} \
--buildtype=release \
--wrap-mode=nodownload

# Cargo only looks for .cargo/config.toml by walking up from the *cwd*
# ninja runs the cargo-build custom_target in (meson's own build root),
# not from --manifest-path's directory, so a config.toml inside ${S}
# would silently be ignored. Write the vendoring config straight into
# each workspace's CARGO_HOME instead -- the one path both meson's
# src/meson.build (missioncenter itself) and
# subprojects/magpie/meson.build (magpie) actually set, and cargo always
# reads CARGO_HOME/config.toml regardless of cwd.
mkdir -p ${B}/build/cargo-home
cat > ${B}/build/cargo-home/config.toml <<EOF
[source.crates-io]
replace-with = "vendored-sources"

[source.vendored-sources]
directory = "${S}/vendor"
EOF

mkdir -p ${B}/build/subprojects/magpie/cargo-home
cat > ${B}/build/subprojects/magpie/cargo-home/config.toml <<EOF
[source.crates-io]
replace-with = "vendored-sources"

[source."git+https://github.com/pop-os/dbus-settings-bindings.git?rev=87c3c35666b926a24a1e8045fd70be2db1145e34"]
git = "https://github.com/pop-os/dbus-settings-bindings.git"
rev = "87c3c35666b926a24a1e8045fd70be2db1145e34"
replace-with = "vendored-sources"

[source.vendored-sources]
directory = "${S}/subprojects/magpie/vendor"
EOF
}

mee_build() {
export PKG_CONFIG_PATH=${B}/libadwaita/lib/pkgconfig${PKG_CONFIG_PATH:+:${PKG_CONFIG_PATH}}
export GI_TYPELIB_PATH=${B}/libadwaita/lib/girepository-1.0${GI_TYPELIB_PATH:+:${GI_TYPELIB_PATH}}
export CARGO_NET_OFFLINE=true

# pre-seed magpie's vendored-nvtop cache (see the long comment up top).
# This exact path falls out of magpie's platform-linux/build.rs: it takes
# cargo's OUT_DIR for the magpie-platform-linux build script and appends
# "/../../native", which collapses the per-build content hash back down
# to a stable "<cargo target-dir>/<profile>/build/native" -- and meson's
# cargo invocation for the magpie subproject always uses
# "${B}/build/subprojects/magpie/src" as that target-dir.
nvtop_dir=${B}/build/subprojects/magpie/src/release/build/native/nvtop-3d4a953da02bc18886734613bb9f60ff80669de7
mkdir -p ${nvtop_dir}
tar xf ${F}/nvtop-3d4a953da02bc18886734613bb9f60ff80669de7.tar.gz -C ${nvtop_dir} --strip-components 1
(
cd ${nvtop_dir}
patchdir=${S}/subprojects/magpie/platform-linux/3rdparty/nvtop/patches
for p in \
nvtop-amdgpu-h.patch \
nvtop-amdgpu_drm-h.patch \
nvtop-dont-add-gtt-amd-integrated.patch \
nvtop-constructors.patch \
nvtop-dont-require-ncurses.patch \
nvtop-i915-drm-query.patch \
nvtop-kcmp-h.patch \
nvtop-msm_drm-h.patch \
nvtop-no-drmGetDevices2.patch \
nvtop-xf86drm-h.patch \
nvtop-msm-utils-array-size.patch \
; do
# same patch list/order as nvtop.json; build.rs itself ignores
# patch's exit code, one hunk (an unused ncurses debug helper)
# never applies cleanly upstream either
patch -p1 -i ${patchdir}/${p} || :
done
)

start_cmd ninja -C ${B}/build
}

mee_install() {
export PKG_CONFIG_PATH=${B}/libadwaita/lib/pkgconfig${PKG_CONFIG_PATH:+:${PKG_CONFIG_PATH}}
export GI_TYPELIB_PATH=${B}/libadwaita/lib/girepository-1.0${GI_TYPELIB_PATH:+:${GI_TYPELIB_PATH}}
export CARGO_NET_OFFLINE=true

DESTDIR=${D} start_cmd ninja -C ${B}/build install

# blueprint-compiler is a build-time-only tool (see mee_configure() and
# the comment up top); drop the one data file its meson subproject
# installs regardless of that.
rm -f ${D}${PREFIX}/lib/python3*/site-packages/blueprintcompiler/reference_docs.json
rmdir ${D}${PREFIX}/lib/python3*/site-packages/blueprintcompiler 2>/dev/null
rmdir ${D}${PREFIX}/lib/python3*/site-packages 2>/dev/null
rmdir ${D}${PREFIX}/lib/python3* 2>/dev/null

# missioncenter links against libadwaita-1.so.0, not provided by this
# repository (see mee_configure()); ship our private build's shared
# library only, and point the binary at it via rpath.
install -d -m 0755 ${D}${PREFIX}/lib/mission-center
install -m 0755 ${B}/libadwaita/lib/libadwaita-1.so.0 ${D}${PREFIX}/lib/mission-center/
patchelf --set-rpath ${PREFIX}/lib/mission-center ${D}${BINDIR}/missioncenter
}