// SPDX-License-Identifier: LGPL-3.0-only // SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts® import std; import Crafter.Build; // Every dependency is named at a commit: a build runs each one's own project.cpp and links its code into the program // that holds every user's bank keys, so what is built is what was built and tested here, not what a branch has come to // since. Moving one forward is a change to this file, made with the tests run again. See also networkCommit below. #pragma crafter dependency "https://forgejo.catcrafts.net/Catcrafts/Crafter.LintRules.git" commit "7d932892017800b4e1f1a15fe7aa49b3daee9ceb" import Crafter.LintRules; // What puts Crafter.Debug into the app under --debug-api, and into no other build. #pragma crafter dependency "https://forgejo.catcrafts.net/Catcrafts/Crafter.Debug.git" commit "98e92c1976f32c6f9beb6ea38a0522a3bbdabed7" project "tooling/project.cpp" import Crafter.Debug.Build; namespace fs = std::filesystem; using namespace Crafter; // Nostro.Checkout: what a shop app links to have nostrod pay an order, as a library of its own that needs no bank code, // OpenSSL, Crafter.Network or Crafter.DB, only libsystemd. `--product=checkout` builds it alone; nostrod takes its names // from it. static Configuration CheckoutLibrary(std::span args, const std::vector& compileFlags) { Configuration checkout; checkout.path = "./"; checkout.name = "nostro-checkout"; checkout.outputName = "nostro-checkout"; checkout.type = ConfigurationType::LibraryStatic; checkout.linkFlags.push_back("-lsystemd"); ApplyStandardArgs(checkout, args); checkout.compileFlags.insert(checkout.compileFlags.end(), compileFlags.begin(), compileFlags.end()); std::array interfaces = {"interfaces/Nostro.Checkout"}; std::array implementations = {"implementations/Nostro.Checkout"}; checkout.GetInterfacesAndImplementations(interfaces, implementations); LintRules::AddLiteRules(checkout); return checkout; } // Nostro.Ui: the toolkit the app's screens are built with. It imports std alone, so its tests need no window, no bank // and no bus, and it is built only for what depends on it: those tests, and the app. static Configuration UiLibrary(std::span args, const std::vector& compileFlags) { Configuration ui; ui.path = "./"; ui.name = "nostro-ui"; ui.outputName = "nostro-ui"; ui.type = ConfigurationType::LibraryStatic; ApplyStandardArgs(ui, args); ui.compileFlags.insert(ui.compileFlags.end(), compileFlags.begin(), compileFlags.end()); std::array interfaces = { "interfaces/Nostro.Ui", "interfaces/Nostro.Ui-Geometry", "interfaces/Nostro.Ui-Text", "interfaces/Nostro.Ui-Edit", "interfaces/Nostro.Ui-Gesture", "interfaces/Nostro.Ui-Draw", "interfaces/Nostro.Ui-Theme", "interfaces/Nostro.Ui-Input", "interfaces/Nostro.Ui-Context", "interfaces/Nostro.Ui-Layout", "interfaces/Nostro.Ui-Widgets", }; std::array implementations = { "implementations/Nostro.Ui-Text", "implementations/Nostro.Ui-Edit", "implementations/Nostro.Ui-Gesture", "implementations/Nostro.Ui-Draw", "implementations/Nostro.Ui-Theme", "implementations/Nostro.Ui-Context", "implementations/Nostro.Ui-Widgets", }; ui.GetInterfacesAndImplementations(interfaces, implementations); LintRules::AddLiteRules(ui); return ui; } // Nostro.App: the app without its window: what it knows, what is filled in, and its screens, built with the toolkit // over the library's client. Like the toolkit it is built only for what depends on it: its tests, and the app. static Configuration AppLibrary(std::span args, const std::vector& compileFlags, Configuration* library, Configuration* ui) { Configuration app; app.path = "./"; app.name = "nostro-app-core"; app.outputName = "nostro-app-core"; app.type = ConfigurationType::LibraryStatic; app.dependencies = {library, ui}; ApplyStandardArgs(app, args); app.compileFlags.insert(app.compileFlags.end(), compileFlags.begin(), compileFlags.end()); std::array interfaces = { "interfaces/Nostro.App", "interfaces/Nostro.App-Banks", "interfaces/Nostro.App-Format", "interfaces/Nostro.App-Forms", "interfaces/Nostro.App-Errors", "interfaces/Nostro.App-App", }; std::array implementations = { "implementations/Nostro.App-Banks", "implementations/Nostro.App-Format", "implementations/Nostro.App-Forms", "implementations/Nostro.App-Errors", "implementations/Nostro.App-App", "implementations/Nostro.App-Screens", "implementations/Nostro.App-Bunq", }; app.GetInterfacesAndImplementations(interfaces, implementations); LintRules::AddLiteRules(app); return app; } // Nostro.Ui.Shell: what puts the toolkit's screens on a display, on Crafter.Graphics and one sd-event loop. The one part // of the app that needs a compositor and a graphics device, so only the app is built with it and no test is. static Configuration ShellLibrary(std::span args, Configuration* ui, Configuration* graphics) { Configuration shell; shell.path = "./"; shell.name = "nostro-ui-shell"; shell.outputName = "nostro-ui-shell"; shell.type = ConfigurationType::LibraryStatic; shell.linkFlags.push_back("-lsystemd"); shell.dependencies = {ui, graphics}; ApplyStandardArgs(shell, args); std::array interfaces = { "interfaces/Nostro.Ui.Shell", "interfaces/Nostro.Ui.Shell-Loop", "interfaces/Nostro.Ui.Shell-Canvas", "interfaces/Nostro.Ui.Shell-Window", "interfaces/Nostro.Ui.Shell-Portal", }; std::array implementations = { "implementations/Nostro.Ui.Shell-Loop", "implementations/Nostro.Ui.Shell-Canvas", "implementations/Nostro.Ui.Shell-Window", "implementations/Nostro.Ui.Shell-Portal", }; shell.GetInterfacesAndImplementations(interfaces, implementations); LintRules::AddLiteRules(shell); return shell; } // nostro-fake-system: the tests' fake bus and fake bunq with nostrod on them, as a program to run the app against. static Configuration FakeSystem(std::span args, const std::vector& defines, const std::vector& dependencies) { Configuration fake; fake.path = "./"; fake.name = "nostro-fake-system"; fake.outputName = "nostro-fake-system"; fake.defines = defines; ApplyStandardArgs(fake, args); fake.dependencies = dependencies; std::array interfaces = {}; std::array implementations = {"tests/FakeSystem/main"}; fake.GetInterfacesAndImplementations(interfaces, implementations); LintRules::AddLiteRules(fake); return fake; } // `crafter-build … --product=app --debug-api run fake [the fake system's options] [-- the app's options]`: the app on // the made-up system, both as the build before left them. `-r` passes a program no arguments, and the app has a few. static std::int32_t RunOnFakeSystem(ScriptContext& ctx) { const auto harness = std::ranges::find(ctx.project.dependencies, std::string_view("nostro-fake-system"), [](const Configuration* dependency) { return std::string_view(dependency->name); }); if(harness == ctx.project.dependencies.end()) { throw std::runtime_error("the fake system is built with the app under --debug-api: name both before `run`"); } const auto separator = std::ranges::find(ctx.args, std::string_view("--")); std::string command = ShellQuote(((*harness)->BinDir() / (*harness)->outputName).string()); command += std::format(" --dir {}", ShellQuote((ctx.projectDir / "build" / "fake-system").string())); for(const std::string& arg : std::ranges::subrange(ctx.args.begin(), separator)) { command += std::format(" {}", ShellQuote(arg)); } command += std::format(" --run {}", ShellQuote((ctx.project.ProgramDir() / ctx.project.outputName).string())); if(separator != ctx.args.end()) { for(const std::string& arg : std::ranges::subrange(separator + 1, ctx.args.end())) { command += std::format(" {}", ShellQuote(arg)); } } return ctx.Run(command); } extern "C" Configuration CrafterBuildProject(std::span args) { constexpr std::string_view bankArgName = "--banks="; bool lib = false; bool dbusRequested = false; bool bunqEnabled = false; bool coverage = false; std::string profileRuntime; constexpr std::string_view profileRuntimeArgName = "--profile-runtime="; // What a build makes: the CLI by default, "daemon" for nostrod, "app" for the window, "checkout" for the checkout // client library, or "fake-system" for a made-up system to look at the app against. std::string product; constexpr std::string_view productArgName = "--product="; // The app with Crafter.Debug in it, for an agent to drive: nostro's own flag, which no dependency is handed. bool debugApiRequested = false; constexpr std::string_view debugApiArgName = "--debug-api"; std::vector depArgs; Configuration libcfg; for(std::string_view arg : args) { if(arg == "--lib") { lib = true; } else if(arg == "--dbus") { dbusRequested = true; } else if(arg.starts_with(productArgName)) { product = arg.substr(productArgName.size()); } else if(arg == debugApiArgName) { debugApiRequested = true; } else if(arg == "--coverage") { coverage = true; } else if(arg.starts_with(profileRuntimeArgName)) { profileRuntime = arg.substr(profileRuntimeArgName.size()); } else if(arg.starts_with(bankArgName)) { for(std::ranges::subrange part : std::views::split(arg.substr(bankArgName.size()), ',')) { std::string_view name(part.begin(), part.end()); if(name == "bunq") { bunqEnabled = true; libcfg.defines.push_back({"NOSTRO_BUNQ_ENABLED"}); } else { throw std::runtime_error(std::format("unknown connector '{}' in {}", name, bankArgName)); } } } else { depArgs.emplace_back(arg); } } // --coverage builds the library, the CLI and the tests with clang's source-based coverage, and every process writes // its counts where LLVM_PROFILE_FILE says. The flags go to clang's front end so the driver does not link a profile // runtime by itself: --profile-runtime= names compiler-rt's libclang_rt.profile archive for a toolchain without one. std::vector coverageCompileFlags; std::vector coverageLinkFlags; if(coverage) { coverageCompileFlags = {"-Xclang", "-fprofile-instrument=clang", "-Xclang", "-fcoverage-mapping"}; if(profileRuntime.empty()) { coverageLinkFlags = {"-fprofile-instr-generate"}; } else { coverageLinkFlags = {profileRuntime, "-Wl,-u,__llvm_profile_runtime"}; } } libcfg.compileFlags.insert(libcfg.compileFlags.end(), coverageCompileFlags.begin(), coverageCompileFlags.end()); if(product == "checkout") { return CheckoutLibrary(args, coverageCompileFlags); } if(!product.empty() && product != "daemon" && product != "app" && product != "fake-system") { throw std::runtime_error(std::format("unknown product '{}' in {}", product, productArgName)); } if(!bunqEnabled) { throw std::runtime_error("must enable atleast one bank"); } // The crypto partition is only needed by banks that sign their requests. const bool opensslEnabled = bunqEnabled; if(opensslEnabled) { libcfg.defines.push_back({"NOSTRO_OPENSSL_ENABLED"}); } // nostrod and the CLI talk over D-Bus (sd-bus, from libsystemd). A consumer building the library alone gets that part // only when it asks with --dbus, so the library does not make every consumer depend on libsystemd. The wire carries // bunq's listing types, so it needs bunq. const bool dbusEnabled = (!lib || dbusRequested) && bunqEnabled; if(dbusEnabled) { libcfg.defines.push_back({"NOSTRO_DBUS_ENABLED"}); } Configuration* checkout = new Configuration(CheckoutLibrary(args, coverageCompileFlags)); Configuration* ui = new Configuration(UiLibrary(args, coverageCompileFlags)); // nostro uses Crafter.Network's HTTP/1.1 client alone: --no-quic leaves out msquic, its CMake build, and the runpath // into the building user's cache that a binary linked against it carries. Crafter.Debug talks QUIC, and takes // Crafter.Network with the args it is handed: a dependency two paths share gets one list of them, so the app's // debug build has QUIC in. const bool debugApi = debugApiRequested && product == "app"; std::vector networkArgs = depArgs; if(!debugApi) { networkArgs.emplace_back("--no-quic"); } // The commits nostro is built and tested against (see the pragmas at the top). The app's debug build is the one // that follows Crafter.Network's branch: Crafter.Debug names it without a commit, and crafter-build refuses a // program that would hold two builds of one module ("module Crafter.Network is built twice"). That build is for // the made-up system and the sandbox, and is not packaged. Crafter.Thread comes with Crafter.Network, whose own // project file names it without a commit. constexpr std::string_view networkCommit = "79a2f126292755142f22f7d109f38d52067f5449"; constexpr std::string_view dbCommit = "38c9076e1df71d9beebc95deded65d827b802f3d"; Configuration* network = GitProject({ .source = { .url = "https://forgejo.catcrafts.net/Catcrafts/Crafter.Network.git", .commit = debugApi ? std::string() : std::string(networkCommit) }, .args = networkArgs, }); Configuration* db = GitProject({ .source = { .url = "https://forgejo.catcrafts.net/Catcrafts/Crafter.DB.git", .commit = std::string(dbCommit) }, .args = depArgs, }); libcfg.path = "./"; libcfg.name = "nostro"; libcfg.outputName = "nostro"; libcfg.type = ConfigurationType::LibraryStatic; libcfg.dependencies = {network, db}; if(dbusEnabled) { libcfg.dependencies.push_back(checkout); } if(opensslEnabled) { libcfg.linkFlags.push_back("-lssl"); libcfg.linkFlags.push_back("-lcrypto"); } if(dbusEnabled) { libcfg.linkFlags.push_back("-lsystemd"); } ApplyStandardArgs(libcfg, args); std::vector libInterfaces = { "interfaces/Nostro", "interfaces/Nostro-Connector", "interfaces/Nostro-Transaction", "interfaces/Nostro-Account", "interfaces/Nostro-Banks", "interfaces/Nostro-Bunq", "interfaces/Nostro-Crypto", "interfaces/Nostro-Currency", "interfaces/Nostro-File", "interfaces/Nostro-Utils", "interfaces/Nostro-Bus", "interfaces/Nostro-Client", "interfaces/Nostro-Daemon", }; std::vector libImplementations = { "implementations/Nostro-Account", "implementations/Nostro-File", "implementations/Nostro-Connector" }; if(bunqEnabled) { libImplementations.push_back("implementations/Nostro-Bunq"); libImplementations.push_back("implementations/Nostro-Bunq-Payments"); } if(opensslEnabled) { libImplementations.push_back("implementations/Nostro-Crypto"); } if(dbusEnabled) { libImplementations.push_back("implementations/Nostro-Bus"); libImplementations.push_back("implementations/Nostro-Client"); libImplementations.push_back("implementations/Nostro-Daemon"); libImplementations.push_back("implementations/Nostro-Daemon-Worker"); } libcfg.GetInterfacesAndImplementations(libInterfaces, libImplementations); LintRules::AddLiteRules(libcfg); if(lib) { return libcfg; } // Both executables switch on the same bank and D-Bus flags as the library, and share the one library: two // configurations exporting the same module in one build are an error. const auto defines = libcfg.defines; Configuration* library = new Configuration(std::move(libcfg)); Configuration* appCore = new Configuration(AppLibrary(args, coverageCompileFlags, library, ui)); // nostrod: the daemon that holds the connectors and answers the CLI over the system bus. if(product == "daemon") { Configuration daemon; daemon.path = "./"; daemon.name = "nostrod"; daemon.outputName = "nostrod"; daemon.defines = defines; ApplyStandardArgs(daemon, args); daemon.compileFlags.insert(daemon.compileFlags.end(), coverageCompileFlags.begin(), coverageCompileFlags.end()); daemon.linkFlags.insert(daemon.linkFlags.end(), coverageLinkFlags.begin(), coverageLinkFlags.end()); daemon.dependencies = { library }; std::array daemonInterfaces = {}; std::array daemonImplementations = {"implementations/nostrod"}; daemon.GetInterfacesAndImplementations(daemonInterfaces, daemonImplementations); LintRules::AddLiteRules(daemon); return daemon; } if(product == "fake-system") { return FakeSystem(args, defines, { library, network, db, checkout }); } // nostro-app: the window. Its fonts go beside it, where the window library's shaders are put too. if(product == "app") { // The window library, at the commit the window was last looked at against, like networkCommit above: no test // opens a window, so moving this one forward is checked by looking (AGENTS.template.md, "Looking at the app"). // Its own project file names Crafter.Event, Crafter.Math, Crafter.Asset and the Khronos headers without a // commit, so those still follow their branches. constexpr std::string_view graphicsCommit = "a9ce1a02e8a9dbc01ef766483fd9bcb4d9470d6c"; Configuration* graphics = GitProject({ .source = { .url = "https://forgejo.catcrafts.net/Catcrafts/Crafter.Graphics.git", .commit = std::string(graphicsCommit) }, .args = depArgs, }); Configuration* shell = new Configuration(ShellLibrary(args, ui, graphics)); Configuration app; app.path = "./"; app.name = "nostro-app"; app.outputName = "nostro-app"; app.defines = defines; // What the app says its version is: the metainfo's release is the same. app.defines.push_back({"NOSTRO_VERSION", "0.1.0"}); ApplyStandardArgs(app, args); app.dependencies = { library, ui, appCore, shell }; app.files.push_back("assets/NotoSans-Regular.ttf"); app.files.push_back("assets/NotoSans-Medium.ttf"); // What the app is as a Flatpak (--packaging=flatpak, with `install` or `bundle`): the compositor, the graphics // device, and nostrod on the system bus. No network and no files: it talks to no bank itself and keeps // nothing. The desktop's portals, for the look and for opening a browser, need no permission. app.flatpak.appId = "net.catcrafts.Nostro"; app.flatpak.permissions = {"--socket=wayland", "--device=dri", "--system-talk-name=net.catcrafts.Nostro1"}; app.flatpak.desktopFile = "packaging/flatpak/net.catcrafts.Nostro.desktop"; app.flatpak.metainfo = "packaging/flatpak/net.catcrafts.Nostro.metainfo.xml"; app.flatpak.icons = {"packaging/flatpak/net.catcrafts.Nostro.svg"}; // The licences of what it carries; packaging/licenses/NOTICE says what each text covers. app.flatpak.share = { {"LICENSE", "licenses/net.catcrafts.Nostro/LICENSE"}, {"LICENSE.GPL", "licenses/net.catcrafts.Nostro/LICENSE.GPL"}, {"assets/OFL.txt", "licenses/net.catcrafts.Nostro/OFL.txt"}, {"packaging/licenses", "licenses/net.catcrafts.Nostro"}, }; std::vector appInterfaces; std::vector appImplementations = {"implementations/nostro-app"}; // With --debug-api: Crafter.Debug, what an agent drives the app with, and the made-up system to drive it on, // built in the same pass. Any process of the user's can drive and read such a build: it is no build to ship. if(Debug::Use(app, { .enabled = debugApi, .flag = std::string(debugApiArgName), .define = "NOSTRO_DEBUG_API", .args = depArgs })) { appInterfaces.emplace_back("interfaces/Nostro.DebugCommands"); appImplementations.emplace_back("implementations/Nostro.DebugCommands"); app.dependencies.push_back(new Configuration(FakeSystem(args, defines, { library, network, db, checkout }))); app.scripts.push_back({"fake", RunOnFakeSystem}); } app.GetInterfacesAndImplementations(appInterfaces, appImplementations); LintRules::AddLiteRules(app); return app; } Configuration execfg; execfg.path = "./"; execfg.name = "nostro"; execfg.outputName = "nostro"; execfg.defines = defines; ApplyStandardArgs(execfg, args); std::array exeInterfaces = { }; std::array exeImplementations = { "implementations/main" }; execfg.compileFlags.insert(execfg.compileFlags.end(), coverageCompileFlags.begin(), coverageCompileFlags.end()); execfg.linkFlags.insert(execfg.linkFlags.end(), coverageLinkFlags.begin(), coverageLinkFlags.end()); execfg.dependencies = { library }; execfg.GetInterfacesAndImplementations(exeInterfaces, exeImplementations); // `crafter-build test --banks=bunq`: each test is tests//main.cpp, linked against what it tests. The ones that // talk to bunq talk to a fake of it on 127.0.0.1 (tests/Support/FakeBunq.inc), never to bunq itself. const auto addTests = [&execfg, &coverageCompileFlags, &coverageLinkFlags](std::span names, const std::vector& dependencies) { for(const std::string_view name : names) { TestBuilder test = execfg.AddTest(name).Dependencies(dependencies).Timeout(std::chrono::seconds(180)); for(const std::string& flag : coverageCompileFlags) { test.CompileFlag(flag); } for(const std::string& flag : coverageLinkFlags) { test.LinkFlag(flag); } } }; constexpr std::array libraryTests = { "ShouldHandleMoneyAndText", "ShouldSignAndVerify", "ShouldStoreTransactions", "ShouldKeepFilesPrivate", "ShouldSaveConnectors", "ShouldTalkToBunq", "ShouldMoveMoney", "ShouldRunCommands", "ShouldServeEveryUser", "ShouldAnswerAsynchronously", }; addTests(libraryTests, { library, network, db, checkout }); // The toolkit's, which need the toolkit alone. constexpr std::array uiTests = { "ShouldWrapText", "ShouldEditText", "ShouldRecognizeGestures", "ShouldBuildFrames", "ShouldLayOutWidgets", }; addTests(uiTests, { ui }); // The app's, which drive it against a real nostrod on the fake bus. constexpr std::array appTests = { "ShouldValidateForms", "ShouldDriveTheApp", }; addTests(appTests, { appCore, ui, library, network, db, checkout }); LintRules::AddLiteRules(execfg); return execfg; }