project: the repository skeleton
The SMS app for imsd's net.catcrafts.IMS1.Messaging interface starts
here: the licence (GPL-3.0-only), FUNDING.yml, README and AGENTS, a
project.cpp with the three build products (imsd-messages-core: std and
Crafter.DB; imsd-messages-bus: GLib; the imsd-messages executable),
their module units as stubs, the version constant, the bundled Noto Sans
font with its OFL text, and the first test. This commit is the base every
later range is reviewed against.
Tested: crafter-build builds the three products and --version answers,
crafter-build test passes the one test, lint and format --check are clean
on every text rule and on the AST rules for the eleven files without a
global module fragment; the four files that include gio/gio.h are not
parsed by the lint driver's libclang (no C++ standard library on its
include path: 'type_traits' file not found), which is a Crafter.Build
matter.
2026-10-17 23:14:00 +02:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
|
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
|
|
|
|
|
|
|
|
|
|
// lint-disable-file no-char-pointer
|
|
|
|
|
import std;
|
|
|
|
|
import Crafter.Build;
|
|
|
|
|
#pragma crafter dependency "https://forgejo.catcrafts.net/Catcrafts/Crafter.LintRules.git" commit "e906f797da2cd0b1776dd1b420f9b04d3cd24baf"
|
|
|
|
|
import Crafter.LintRules;
|
|
|
|
|
namespace fs = std::filesystem;
|
|
|
|
|
using namespace Crafter;
|
|
|
|
|
|
|
|
|
|
// pkg-config wrapper (std-only: no popen in import std). Returns the flags
|
|
|
|
|
// split on whitespace, or empty if pkg-config is unavailable — callers
|
|
|
|
|
// provide a fallback for that case.
|
|
|
|
|
static std::vector<std::string> PkgConfig(std::string_view args) {
|
|
|
|
|
fs::path tmp = fs::temp_directory_path() /
|
|
|
|
|
std::format("imsd-messages-pkgconfig-{}.txt", std::hash<std::string_view>{}(args));
|
|
|
|
|
std::string cmd = std::format("pkg-config {} > {} 2>/dev/null", args, tmp.string());
|
|
|
|
|
std::vector<std::string> flags;
|
|
|
|
|
if (std::system(cmd.c_str()) == 0) {
|
|
|
|
|
std::ifstream f(tmp);
|
|
|
|
|
std::string flag;
|
|
|
|
|
while (f >> flag)
|
|
|
|
|
flags.push_back(flag);
|
|
|
|
|
}
|
|
|
|
|
std::error_code ec;
|
|
|
|
|
fs::remove(tmp, ec);
|
|
|
|
|
return flags;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GDBus (gio-2.0) — bus layer for the two daemons; chosen over sd-bus because
|
|
|
|
|
// the platform stack (ModemManager, libqmi for the future direct-AKA port) is
|
|
|
|
|
// GLib, so they want a GMainLoop regardless.
|
|
|
|
|
static void ApplyGioFlags(Configuration& cfg) {
|
|
|
|
|
if (!cfg.sysroot.empty()) {
|
|
|
|
|
// cross build (e.g. --target=aarch64-alpine-linux-musl
|
|
|
|
|
// --sysroot=<packaging/make-sysroot.sh output>): the host's
|
|
|
|
|
// pkg-config would answer for the wrong architecture. glib's
|
|
|
|
|
// include layout is stable across distros; the `-I=` form makes
|
|
|
|
|
// clang resolve the paths inside the sysroot.
|
|
|
|
|
cfg.compileFlags.push_back("-I=/usr/include/glib-2.0");
|
|
|
|
|
cfg.compileFlags.push_back("-I=/usr/lib/glib-2.0/include");
|
|
|
|
|
for (const char* l : { "-lgio-2.0", "-lgobject-2.0", "-lglib-2.0" })
|
|
|
|
|
cfg.linkFlags.push_back(l);
|
|
|
|
|
} else {
|
|
|
|
|
// native build: ask pkg-config. Only -I/-D flags pass through:
|
|
|
|
|
// pkg-config also emits -pthread, which would config-mismatch the
|
|
|
|
|
// shared prebuilt std.pcm (and pthread lives in libc on every
|
|
|
|
|
// platform we target).
|
|
|
|
|
for (std::string& f : PkgConfig("--cflags gio-2.0"))
|
|
|
|
|
if (f.starts_with("-I") || f.starts_with("-D")) cfg.compileFlags.push_back(std::move(f));
|
|
|
|
|
std::vector<std::string> libs;
|
|
|
|
|
for (std::string& f : PkgConfig("--libs gio-2.0"))
|
|
|
|
|
if (f.starts_with("-l") || f.starts_with("-L")) libs.push_back(std::move(f));
|
|
|
|
|
if (libs.empty()) libs = { "-lgio-2.0", "-lgobject-2.0", "-lglib-2.0" };
|
|
|
|
|
for (std::string& f : libs)
|
|
|
|
|
cfg.linkFlags.push_back(std::move(f));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
extern "C" Configuration CrafterBuildProject(std::span<const std::string_view> args) {
|
|
|
|
|
// --local builds Crafter.DB from the sibling checkout under ~/repos/Crafter
|
|
|
|
|
// instead of the forge, for work on both sides at once. The flag is this
|
|
|
|
|
// project's: it is removed before the arguments are forwarded, so a
|
|
|
|
|
// dependency's project.cpp never sees it.
|
|
|
|
|
std::vector<std::string> depArgs(args.begin(), args.end());
|
|
|
|
|
const bool local = std::erase(depArgs, "--local") > 0;
|
|
|
|
|
|
|
|
|
|
Configuration* db = local
|
|
|
|
|
? LocalProject({ .projectFile = "../Crafter/Crafter.DB/project.cpp", .args = depArgs })
|
|
|
|
|
: GitProject({ .source = { .url = "https://forgejo.catcrafts.net/Catcrafts/Crafter.DB.git" }, .args = depArgs });
|
|
|
|
|
|
|
|
|
|
// imsd-messages-core — numbers, time, the model, word wrap, the store and
|
|
|
|
|
// the sync logic: std + Crafter.DB, no GLib, so every test runs with no
|
|
|
|
|
// bus, no phone and no GPU.
|
|
|
|
|
static auto Core = std::make_unique<Configuration>();
|
|
|
|
|
Core->path = "./";
|
|
|
|
|
Core->name = "imsd-messages-core";
|
|
|
|
|
Core->outputName = "imsd-messages-core";
|
|
|
|
|
ApplyStandardArgs(*Core, args);
|
|
|
|
|
Core->type = ConfigurationType::LibraryStatic;
|
|
|
|
|
Core->dependencies = { db };
|
|
|
|
|
{
|
|
|
|
|
std::array<fs::path, 7> ifaces = {
|
|
|
|
|
"interfaces/ImsdMessages",
|
|
|
|
|
"interfaces/ImsdMessages-Number",
|
|
|
|
|
"interfaces/ImsdMessages-Time",
|
|
|
|
|
"interfaces/ImsdMessages-Model",
|
|
|
|
|
"interfaces/ImsdMessages-Wrap",
|
|
|
|
|
"interfaces/ImsdMessages-Store",
|
|
|
|
|
"interfaces/ImsdMessages-Sync",
|
|
|
|
|
};
|
|
|
|
|
std::array<fs::path, 0> impls = {};
|
|
|
|
|
Core->GetInterfacesAndImplementations(ifaces, impls);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// imsd-messages-bus — the GLib side: imsd's dictionaries, the GDBus client
|
|
|
|
|
// of net.catcrafts.IMS1.Messaging, the desktop notifications and the app's
|
|
|
|
|
// own session-bus name. No window.
|
|
|
|
|
static auto Bus = std::make_unique<Configuration>();
|
|
|
|
|
Bus->path = "./";
|
|
|
|
|
Bus->name = "imsd-messages-bus";
|
|
|
|
|
Bus->outputName = "imsd-messages-bus";
|
|
|
|
|
ApplyStandardArgs(*Bus, args);
|
|
|
|
|
Bus->type = ConfigurationType::LibraryStatic;
|
|
|
|
|
Bus->dependencies = { Core.get() };
|
|
|
|
|
{
|
|
|
|
|
std::array<fs::path, 5> ifaces = {
|
|
|
|
|
"interfaces/ImsdMessages.Bus",
|
|
|
|
|
"interfaces/ImsdMessages.Bus-Variant",
|
|
|
|
|
"interfaces/ImsdMessages.Bus-Client",
|
|
|
|
|
"interfaces/ImsdMessages.Bus-Notifier",
|
|
|
|
|
"interfaces/ImsdMessages.Bus-Instance",
|
|
|
|
|
};
|
|
|
|
|
std::array<fs::path, 0> impls = {};
|
|
|
|
|
Bus->GetInterfacesAndImplementations(ifaces, impls);
|
|
|
|
|
}
|
|
|
|
|
ApplyGioFlags(*Bus);
|
|
|
|
|
|
|
|
|
|
// imsd-messages — the executable: the command line, the window and the
|
|
|
|
|
// wiring between the bus layer and the UI.
|
|
|
|
|
Configuration cfg;
|
|
|
|
|
cfg.path = "./";
|
|
|
|
|
cfg.name = "imsd-messages";
|
|
|
|
|
cfg.outputName = "imsd-messages";
|
|
|
|
|
ApplyStandardArgs(cfg, args);
|
|
|
|
|
cfg.type = ConfigurationType::Executable;
|
|
|
|
|
cfg.dependencies = { Core.get(), Bus.get() };
|
|
|
|
|
{
|
|
|
|
|
std::array<fs::path, 0> ifaces = {};
|
|
|
|
|
std::array<fs::path, 1> impls = { "implementations/main" };
|
|
|
|
|
cfg.GetInterfacesAndImplementations(ifaces, impls);
|
|
|
|
|
}
|
|
|
|
|
ApplyGioFlags(cfg);
|
|
|
|
|
|
|
|
|
|
cfg.AddTest("Number").Dependencies({ Core.get() });
|
2026-10-17 23:25:38 +02:00
|
|
|
cfg.AddTest("Time").Dependencies({ Core.get() });
|
Wrap: word wrap and ellipsis over a measure function
Crafter.Graphics shapes one line at a time and drops newlines, so the app
breaks text itself: a greedy wrap with breaks after spaces and hyphens
(a space that itself overflows ends the line after the words that fit,
and opens no line of its own when it ends the text or a newline
follows; one at a line's start is no break at all, nor is a run of
them: a break is recorded only once the line holds a word, and a run of
spaces wider than the line splits like a word, with the same rule at the
text's end and before a newline), hard breaks at
newlines, over-long words split between code points, and
the run of spaces where a line wraps left out of both lines. Results are
cached per (text, width, size). The measure is a function, so the caller
supplies the advances; the tests use a constant ten-pixel advance.
Tested: tests/Wrap on a ten-pixel monospace measure, a leading run of
spaces among the cases.
2026-10-17 23:25:41 +02:00
|
|
|
cfg.AddTest("Wrap").Dependencies({ Core.get() });
|
Model: messages, conversations and the banner
The GLib-free shape of what the app shows: imsd's state words (each
applies as it comes: imsd gives a message's words in order, the
submission's first and a status report's after sent, its AGENTS.md
section 8.4); a received text (the dictionary of imsd's AGENTS.md
section 8.4) becoming a message keyed by the sender's address completed
with the code of the number it arrived for (imsd's `to`, the
subscriber's own number at receipt — the record's: a text imsd kept
across a SIM change would otherwise take the new SIM's code) or, lacking
one, of the service centre that delivered it, the own number's code —
none where the centre's stood in, which names no SIM's country — and the
operator of the SIM it arrived under (imsd's `operator`) its plan
(Number's SimPlan), and whose sort time is the service centre's stamp,
else its arrival; the short message type 0, which a phone acknowledges
and discards (IsType0, TS 23.040 9.2.3.9); the grouping into
conversations newest first, unread counting incoming unread only; and
the one-line banner from what the app knows about imsd: absent,
connecting (GetStatus has not answered since imsd appeared), off,
subscribe refused, unregistered, the store refusing a write (its disk
full: texts wait; a send still goes), subscribe failed otherwise — what
blocks sending before what only costs live updates — messages it may not
delete.
Tested: tests/Model.
2026-10-17 23:25:45 +02:00
|
|
|
cfg.AddTest("Model").Dependencies({ Core.get() });
|
project: the repository skeleton
The SMS app for imsd's net.catcrafts.IMS1.Messaging interface starts
here: the licence (GPL-3.0-only), FUNDING.yml, README and AGENTS, a
project.cpp with the three build products (imsd-messages-core: std and
Crafter.DB; imsd-messages-bus: GLib; the imsd-messages executable),
their module units as stubs, the version constant, the bundled Noto Sans
font with its OFL text, and the first test. This commit is the base every
later range is reviewed against.
Tested: crafter-build builds the three products and --version answers,
crafter-build test passes the one test, lint and format --check are clean
on every text rule and on the AST rules for the eleven files without a
global module fragment; the four files that include gio/gio.h are not
parsed by the lint driver's libclang (no C++ standard library on its
include path: 'type_traits' file not found), which is a Crafter.Build
matter.
2026-10-17 23:14:00 +02:00
|
|
|
|
|
|
|
|
LintRules::AddRules(cfg);
|
|
|
|
|
return cfg;
|
|
|
|
|
}
|