feat: lay an executable out as the files/ of a Flatpak

A Linux executable built by the Flatpak crafter-build links the libc++,
libc++abi and libunwind in its /app/lib and the Sdk's glibc, so it runs
inside crafter-build's sandbox and practically nowhere else: a host
needs glibc 2.38 or newer and all three LLVM libraries, which not even
Arch has. A program built here is meant to run in a Flatpak, so it can
now be laid out as one: with cfg.packaging = Packaging::Flatpak, or
--packaging=flatpak where the project.cpp crafter-build was pointed at
calls ApplyStandardArgs, its BinDir() holds files/, what becomes /app in
the app's sandbox, and -r runs the program there against the libraries
the app carries.

The program is linked into files/bin, where its shaders, files and
assets land too (ProgramDir()), with $ORIGIN/../lib as its one run path,
and the new :Flatpak partition writes the rest of files/: files/lib with
the LLVM runtime libraries, located one by one through clang, and
whatever else the program needs, read with llvm-readelf, that the
directories of the shared libraries it is built on hold, the ones an
unpackaged link records as run paths, or the toolchain's own lib dir,
/app/lib in crafter-build's Flatpak, which the link searches too; and
the desktop entry, metainfo and icons under the app-id in files/share,
the entry refused when its Icon= is not the app-id or
desktop-file-validate, where there is one, rejects it, and an icon that
is not an .svg or a square .png. The metadata and export/ of a build
directory are flatpak build-finish's to write, and crafter-build keeps
no copy of its rules: what a permission means and what the host sees of
an app change with flatpak's releases, and a copy would have to follow
every one. The writer copies a file only when its content differs,
compared a block at a time so that a large file costs no more memory
than a small one, and writes one only when what it would write differs,
never deciding by an mtime, which ostree sets to 0 for every file of
/app, and works the program's libraries out on every write, which reads
only their dynamic sections, since a library replaced in place, as by a
toolchain update, can need others, which FlatpakLibraryChange checks; it
prunes from files/bin each top-level entry an earlier build put there
and this one does not, reporting those the program wrote there itself.

What cannot be a Flatpak is refused before anything is built, saying
why: a Windows or wasm executable, a build against a sysroot or for
musl, another architecture than the runtime's, a build against
CRAFTER_BUILD_LIBCXX_DIR, whose libc++ the Flatpak would not carry, and
a build by a native crafter-build, which links the host's glibc: a
native process knows no Flatpak runtime, from /.flatpak-info, unless
CRAFTER_BUILD_FLATPAK_INFO, the tests' hook, names a file with one.
Default stays the executable as linked for now, RunTests runs every test
as linked, whatever its Configuration asks for, and RunLint works out
its compile command so, and a forwarded --packaging= leaves a
dependency's executables alone, since consumers run them by path. A
dependency that packages its own executable gets its desktop file,
metainfo and icons rebased by the loader as its cfg.files are, so they
are its own whatever directory the consumer builds from. Only a Flatpak
is keyed into VariantId, so every other configuration keeps its
directory, but for one given --packaging=, which was a project arg,
hashed into VariantId, and is a standard arg now, a dependency's
included. The app-id and what a Flatpak is installed as are not keyed:
they change files/share, never what is compiled. The asset name map,
kept three times, twice in Build() and once for the browser runtime's
files.json, is one function now, CompressedAssetName; CompressAsset, in
Crafter.Build-Asset.cpp, keeps the list of the extensions it loads,
which has to agree with it. Each copy a Flatpak build makes into the
program's directory, of its shaders, assets, cfg.files and what its
dependencies forward, records the top-level name it places there, the
names of what a directory holds for one copied into it itself ("data/",
"data/."), and those are what the writer keeps in files/bin; a build
that fails after copying adds them to the writer's record all the same,
so the next write removes what no build places any more.

SharedLibraryRuns now also packages its program as a Flatpak, whose
files/lib has to carry libgreet.so for it to start.
This commit is contained in:
Jorijn van der Graaf 2026-11-01 19:20:55 +01:00
commit 27031ed8e3
Signed by: jorijnvdgraaf
GPG key ID: 2937E59CDCC1BCFB
56 changed files with 2314 additions and 74 deletions

View file

@ -0,0 +1,23 @@
// SPDX-License-Identifier: LGPL-3.0-only
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
import std;
import Crafter.Build;
using namespace Crafter;
// The project crafter-build is pointed at: an executable, with two sibling
// projects whose executables it depends on, loaded with this file's args.
// The second packages its own as a Flatpak.
extern "C" Configuration CrafterBuildProject(std::span<const std::string_view> args) {
Configuration* tool = LocalProject({ .projectFile = "../tool/project.cpp" });
Configuration* packaged = LocalProject({ .projectFile = "../packaged/project.cpp" });
Configuration cfg;
cfg.path = "./";
cfg.name = "app";
cfg.outputName = "app";
cfg.type = ConfigurationType::Executable;
ApplyStandardArgs(cfg, args);
cfg.dependencies = { tool, packaged };
return cfg;
}

View file

@ -0,0 +1,9 @@
// SPDX-License-Identifier: LGPL-3.0-only
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
import std;
int main() {
std::println("packaged");
return 0;
}

View file

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"><rect width="16" height="16"/></svg>

After

Width:  |  Height:  |  Size: 100 B

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<component type="desktop-application">
<id>net.example.Packaged</id>
<name>Packaged</name>
<summary>A fixture for crafter-build's tests</summary>
<metadata_license>CC0-1.0</metadata_license>
</component>

View file

@ -0,0 +1,27 @@
// SPDX-License-Identifier: LGPL-3.0-only
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
import std;
import Crafter.Build;
namespace fs = std::filesystem;
using namespace Crafter;
// A sibling that packages its own executable as a Flatpak, in its own
// project.cpp, naming the files it is installed with relative to its own
// directory, as it would its cfg.files.
extern "C" Configuration CrafterBuildProject(std::span<const std::string_view> args) {
Configuration cfg;
cfg.path = "./";
cfg.name = "packaged";
cfg.outputName = "packaged";
cfg.type = ConfigurationType::Executable;
ApplyStandardArgs(cfg, args);
cfg.packaging = Packaging::Flatpak;
cfg.flatpak.appId = "net.example.Packaged";
cfg.flatpak.metainfo = "packaging/packaged.metainfo.xml";
cfg.flatpak.icons = { "packaging/icon.svg" };
std::array<fs::path, 0> ifaces = {};
std::array<fs::path, 1> impls = { "main" };
cfg.GetInterfacesAndImplementations(ifaces, impls);
return cfg;
}

View file

@ -0,0 +1,18 @@
// SPDX-License-Identifier: LGPL-3.0-only
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
import std;
import Crafter.Build;
using namespace Crafter;
// A sibling's executable, which its consumers run by path, loaded with the
// consumer's args.
extern "C" Configuration CrafterBuildProject(std::span<const std::string_view> args) {
Configuration cfg;
cfg.path = "./";
cfg.name = "tool";
cfg.outputName = "tool";
cfg.type = ConfigurationType::Executable;
ApplyStandardArgs(cfg, args);
return cfg;
}

View file

@ -0,0 +1,100 @@
// SPDX-License-Identifier: LGPL-3.0-only
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
#include <stdlib.h>
import std;
import Crafter.Build;
namespace fs = std::filesystem;
using namespace Crafter;
// --packaging=flatpak packages the executable of the project crafter-build
// was pointed at, and no other. The args reach every sibling project the
// project loads (a GitProject's or LocalProject's args default to them),
// and a sibling's executable is run by path by its consumers, as
// Crafter.Debug's client is: packaged, it would move into files/bin and
// out of their reach. A sibling that packages its own executable in its
// own project.cpp gets a Flatpak, with the files it is installed with
// found in its own directory, as its cfg.files are, wherever the consumer
// builds it from: before the loader rebased them, they resolved against the
// consumer's directory, so it shipped the consumer's file of that name or
// failed for want of one. The fixture is an app with two executable
// siblings loaded with its args, of which the second packages itself.
namespace {
std::int32_t Failures = 0;
void Check(bool cond, std::string_view msg) {
if (!cond) {
std::println(std::cerr, "FAIL: {}", msg);
++Failures;
}
}
std::string ReadFile(const fs::path& path) {
std::ifstream in(path, std::ios::binary);
return std::string(std::istreambuf_iterator<char>(in), std::istreambuf_iterator<char>());
}
}
int main() {
const fs::path scratch = fs::temp_directory_path() / "crafter-build-flatpak-dependency-executable";
std::error_code ec;
fs::remove_all(scratch, ec);
fs::create_directories(scratch);
const fs::path info = scratch / "flatpak-info";
std::ofstream(info) << "[Application]\nname=net.catcrafts.CrafterBuild\nruntime=runtime/org.freedesktop.Sdk/x86_64/26.08\n";
setenv("CRAFTER_BUILD_FLATPAK_INFO", info.string().c_str(), 1);
const fs::path installedHome = GetCrafterBuildHome();
if (!fs::exists(installedHome / "Crafter.Build.cppm")) {
std::println(std::cerr, "SKIP: no module sources at {}", installedHome.string());
return 77;
}
// Staged because LoadProject drops a build/ tree next to every project
// file it compiles.
const fs::path fixture = fs::current_path() / "tests" / "FlatpakDependencyExecutable" / "fixture";
fs::copy(fixture, scratch, fs::copy_options::recursive);
// From the project's own directory, as crafter-build runs it: the
// fixture's LocalProject paths are relative to the working directory.
const fs::path cwd = fs::current_path();
fs::current_path(scratch / "app");
try {
std::array<std::string_view, 1> args = { "--packaging=flatpak" };
const Configuration cfg = LoadProject("project.cpp", args);
Check(cfg.packaging == Packaging::Flatpak, "the executable of the project crafter-build was pointed at is packaged");
Check(cfg.dependencies.size() == 2, std::format("the app declared its siblings (got {})", cfg.dependencies.size()));
if (cfg.dependencies.size() == 2) {
const Configuration& tool = *cfg.dependencies[0];
Check(tool.name == "tool", std::format("the first sibling is the fixture's tool (got '{}')", tool.name));
Check(tool.packaging == Packaging::Default && tool.ResolvedPackaging() == Packaging::None, "the sibling's executable stays as linked");
Check(tool.ProgramDir() == tool.BinDir(), "and lands in its bin dir, where its consumers look");
Check(tool.projectArgs.empty(), std::format("the sibling took --packaging= as a standard arg, not one of its own (projectArgs {})", tool.projectArgs));
// Built from the consumer's directory, as the consumer's build
// builds it.
Configuration& packaged = *cfg.dependencies[1];
Check(packaged.packaging == Packaging::Flatpak, "the sibling that packages itself is a Flatpak");
if (NormalizeTarget(GetToolchain().hostTriple) == "x86_64-linux-gnu" && GetToolchain().libcxxDir.empty()) {
std::unordered_map<fs::path, std::shared_future<BuildResult>> depResults;
std::mutex depMutex;
const BuildResult built = Build(packaged, depResults, depMutex);
Check(built.result.empty(), std::format("it builds from the consumer's directory: {}", built.result));
const fs::path share = packaged.BinDir() / "files" / "share";
const fs::path own = scratch / "packaged" / "packaging";
Check(ReadFile(share / "metainfo" / "net.example.Packaged.metainfo.xml") == ReadFile(own / "packaged.metainfo.xml"), "its metainfo is its own");
Check(ReadFile(share / "icons" / "hicolor" / "scalable" / "apps" / "net.example.Packaged.svg") == ReadFile(own / "icon.svg"), "and so is its icon");
}
}
} catch (const std::exception& e) {
Check(false, std::format("LoadProject threw: {}", e.what()));
}
fs::current_path(cwd);
fs::remove_all(scratch, ec);
if (Failures > 0) {
std::println(std::cerr, "{} assertions failed", Failures);
return 1;
}
return 0;
}

View file

@ -0,0 +1,6 @@
[Desktop Entry]
Type=Application
Name=Desktop
Exec=desktop
Icon=net.example.Desktop
Categories=Utility;

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<component type="desktop-application">
<id>net.example.Desktop</id>
<name>Desktop</name>
<summary>A fixture for crafter-build's tests</summary>
<metadata_license>CC0-1.0</metadata_license>
</component>

View file

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"><rect width="16" height="16"/></svg>

After

Width:  |  Height:  |  Size: 100 B

View file

@ -0,0 +1,5 @@
[Desktop Entry]
Type=Bogus
Name=Desktop
Exec=desktop
Icon=net.example.Desktop

View file

@ -0,0 +1,9 @@
// SPDX-License-Identifier: LGPL-3.0-only
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
import std;
int main() {
std::println("desktop");
return 0;
}

View file

@ -0,0 +1,6 @@
[Desktop Entry]
Type=Application
Name=Desktop
Exec=desktop
Icon=desktop
Categories=Utility;

View file

@ -0,0 +1,157 @@
// SPDX-License-Identifier: LGPL-3.0-only
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
#include <stdlib.h>
import std;
import Crafter.Build;
namespace fs = std::filesystem;
using namespace Crafter;
namespace {
std::int32_t Failures = 0;
void Check(bool cond, std::string_view msg) {
if (!cond) {
std::println(std::cerr, "FAIL: {}", msg);
++Failures;
}
}
std::string ReadFile(const fs::path& path) {
std::ifstream in(path, std::ios::binary);
return std::string(std::istreambuf_iterator<char>(in), std::istreambuf_iterator<char>());
}
std::string BuildIt(Configuration& cfg) {
std::unordered_map<fs::path, std::shared_future<BuildResult>> depResults;
std::mutex depMutex;
return Build(cfg, depResults, depMutex).result;
}
// A PNG's signature and IHDR, which is all the size is read from.
void WritePng(const fs::path& path, std::uint32_t width, std::uint32_t height) {
std::string bytes = "\x89PNG\r\n\x1a\n";
const auto bigEndian = [&](std::uint32_t value) {
for (std::int32_t shift = 24; shift >= 0; shift -= 8) bytes.push_back(static_cast<char>((value >> shift) & 0xff));
};
bigEndian(13);
bytes += "IHDR";
bigEndian(width);
bigEndian(height);
bytes += std::string("\x08\x06\x00\x00\x00", 5);
std::ofstream(path, std::ios::binary) << bytes;
}
}
// A desktop entry, AppStream metainfo and icons are installed under the
// app-id in files/share, where flatpak build-finish finds them to export
// to the host: the entry as share/applications/<app-id>.desktop, the
// metainfo as share/metainfo/<app-id>.metainfo.xml, an .svg as the
// scalable icon and a .png in the directory of its own size. What would
// make the app fail to install, or show no icon, is refused at build time:
// an Icon= other than the app-id, spelled with spaces around '=' or not, a
// png that is not square, an icon that is neither format, an entry
// desktop-file-validate rejects (where it exists), on the write after a
// failed one as well, an app-id flatpak does not accept. A project that
// names no app-id gets local.crafterbuild.<name>.
int main() {
const fs::path scratch = fs::temp_directory_path() / "crafter-build-flatpak-desktop";
std::error_code ec;
fs::remove_all(scratch, ec);
fs::create_directories(scratch);
const fs::path info = scratch / "flatpak-info";
std::ofstream(info) << "[Application]\nname=net.catcrafts.CrafterBuild\nruntime=runtime/org.freedesktop.Sdk/x86_64/26.08\n";
setenv("CRAFTER_BUILD_FLATPAK_INFO", info.string().c_str(), 1);
Check(DefaultFlatpakAppId("hello") == "local.crafterbuild.hello", "the default app-id");
Check(DefaultFlatpakAppId("my-app") == "local.crafterbuild.my-app", "a dash may stay in the last segment");
Check(DefaultFlatpakAppId("3d.viewer") == "local.crafterbuild._3d_viewer", std::format("a dot and a leading digit are made safe: {}", DefaultFlatpakAppId("3d.viewer")));
Check(FlatpakAppIdError(DefaultFlatpakAppId("3d.viewer")).empty(), "and the result is valid");
Check(FlatpakAppIdError("org.example.My-App").empty(), "a valid app-id");
for (const std::string_view bad : {"org.example", "org.3d.App", "org.my-company.App", "org..App", "org.example.App!", ""}) {
Check(!FlatpakAppIdError(bad).empty(), std::format("'{}' is refused", bad));
}
Check(!FlatpakAppIdError(std::format("org.example.{}", std::string(250, 'a'))).empty(), "an app-id over 255 characters is refused");
if (NormalizeTarget(GetToolchain().hostTriple) != "x86_64-linux-gnu") {
// A skip must never cover for a failure above.
if (Failures > 0) return 1;
std::println(std::cerr, "SKIP: the staged runtime is x86_64 and the host is {}", GetToolchain().hostTriple);
return 77;
}
if (!GetToolchain().libcxxDir.empty()) {
// A skip must never cover for a failure above.
if (Failures > 0) return 1;
std::println(std::cerr, "SKIP: CRAFTER_BUILD_LIBCXX_DIR is set, and a build against it is no Flatpak");
return 77;
}
const fs::path fixture = fs::current_path() / "tests" / "FlatpakDesktop" / "fixture";
fs::remove_all(fixture / "bin", ec);
fs::remove_all(fixture / "build", ec);
WritePng(scratch / "icon-512.png", 512, 512);
WritePng(scratch / "wide.png", 512, 256);
Configuration app;
app.path = fixture;
app.name = "desktop-app";
app.outputName = "desktop";
app.target = HostTarget();
app.packaging = Packaging::Flatpak;
app.flatpak.appId = "net.example.Desktop";
app.flatpak.desktopFile = fixture / "app.desktop";
app.flatpak.metainfo = fixture / "app.metainfo.xml";
app.flatpak.icons = { fixture / "icon.svg", scratch / "icon-512.png" };
{
std::array<fs::path, 0> ifaces = {};
std::array<fs::path, 1> impls = { "main" };
app.GetInterfacesAndImplementations(ifaces, impls);
}
if (const std::string failed = BuildIt(app); !failed.empty()) {
std::println(std::cerr, "FAIL: build failed: {}", failed);
return 1;
}
const fs::path root = app.BinDir();
const fs::path share = root / "files" / "share";
Check(ReadFile(share / "applications" / "net.example.Desktop.desktop") == ReadFile(fixture / "app.desktop"), "the desktop entry is installed under the app-id");
Check(ReadFile(share / "metainfo" / "net.example.Desktop.metainfo.xml") == ReadFile(fixture / "app.metainfo.xml"), "the metainfo is installed under the app-id");
Check(fs::exists(share / "icons" / "hicolor" / "scalable" / "apps" / "net.example.Desktop.svg"), "an .svg is the scalable icon");
Check(fs::exists(share / "icons" / "hicolor" / "512x512" / "apps" / "net.example.Desktop.png"), "a .png goes under its own size");
app.flatpak.desktopFile = fixture / "wrong-icon.desktop";
Check(BuildIt(app).contains("has to be the app-id"), "an Icon= other than the app-id is refused");
// Spelled with spaces around '=', which the Desktop Entry spec allows and
// every reader of the entry ignores.
std::ofstream(scratch / "spaced-icon.desktop") << "[Desktop Entry]\nType=Application\nName=Desktop\nExec=desktop\nIcon = desktop\n";
app.flatpak.desktopFile = scratch / "spaced-icon.desktop";
Check(BuildIt(app).contains("has to be the app-id"), "so is one spelled 'Icon = desktop'");
app.flatpak.desktopFile = fixture / "app.desktop";
app.flatpak.icons = { scratch / "wide.png" };
Check(BuildIt(app).contains("has to be square"), "a png that is not square is refused");
app.flatpak.icons = { fixture / "app.desktop" };
Check(BuildIt(app).contains("has to be an .svg or a .png"), "an icon that is neither is refused");
app.flatpak.icons = { fixture / "icon.svg" };
if (std::system("command -v desktop-file-validate > /dev/null 2>&1") == 0) {
app.flatpak.desktopFile = fixture / "invalid.desktop";
Check(BuildIt(app).contains("does not pass desktop-file-validate"), "an entry desktop-file-validate rejects is refused");
// A write that copies the entry and then fails, here for a metainfo
// that does not exist, leaves it in files/share unchanged for the
// next write, which copies nothing and has to check it all the same.
app.flatpak.metainfo = scratch / "missing.metainfo.xml";
Check(BuildIt(app).contains("missing.metainfo.xml"), "a write that copies the entry and then fails is refused for what failed");
app.flatpak.metainfo = fixture / "app.metainfo.xml";
Check(BuildIt(app).contains("does not pass desktop-file-validate"), "and the next build refuses the entry it left unchecked");
app.flatpak.desktopFile = fixture / "app.desktop";
}
app.flatpak.appId = "Desktop";
Check(BuildIt(app).contains("is not a Flatpak application ID"), "an invalid app-id is refused");
fs::remove_all(scratch, ec);
if (Failures > 0) {
std::println(std::cerr, "{} assertions failed", Failures);
return 1;
}
return 0;
}

View file

@ -0,0 +1,5 @@
[Desktop Entry]
Type=Application
Name=Incremental
Exec=incremental
Categories=Utility;

View file

@ -0,0 +1 @@
dropped later

View file

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"><rect width="16" height="16"/></svg>

After

Width:  |  Height:  |  Size: 100 B

View file

@ -0,0 +1 @@
kept

View file

@ -0,0 +1,9 @@
// SPDX-License-Identifier: LGPL-3.0-only
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
import std;
int main() {
std::println("incremental");
return 0;
}

View file

@ -0,0 +1,162 @@
// SPDX-License-Identifier: LGPL-3.0-only
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
#include <stdlib.h>
import std;
import Crafter.Build;
namespace fs = std::filesystem;
using namespace Crafter;
namespace {
std::int32_t Failures = 0;
void Check(bool cond, std::string_view msg) {
if (!cond) {
std::println(std::cerr, "FAIL: {}", msg);
++Failures;
}
}
std::string ReadFile(const fs::path& path) {
std::ifstream in(path, std::ios::binary);
return std::string(std::istreambuf_iterator<char>(in), std::istreambuf_iterator<char>());
}
std::string BuildIt(Configuration& cfg) {
std::unordered_map<fs::path, std::shared_future<BuildResult>> depResults;
std::mutex depMutex;
return Build(cfg, depResults, depMutex).result;
}
}
// What a Flatpak's files/ holds is what the build puts there, and it is
// kept so without rewriting what did not change. A cfg.files entry
// dropped since goes from files/bin, which ships; a file the program wrote
// there itself stays, since the build cannot know what it is (the build
// reports it instead). A renamed app-id leaves no desktop entry or icon
// under the old name behind in files/share. What a directory
// written with a trailing separator or as "dir/." held, which the build
// copies flat, goes with the entry, and so does a program renamed in place,
// under its old name: neither may stay, taken for files the program wrote,
// nor may what a build that then failed copied there. And a library is
// copied again when its copy no longer matches the source, whatever the
// mtimes say: every file of an ostree deployment, the Flatpak's /app among
// them, has mtime 0, so a newer libc++ never looks newer than its copy.
int main() {
const fs::path scratch = fs::temp_directory_path() / "crafter-build-flatpak-incremental";
std::error_code ec;
fs::remove_all(scratch, ec);
fs::create_directories(scratch);
const fs::path info = scratch / "flatpak-info";
std::ofstream(info) << "[Application]\nname=net.catcrafts.CrafterBuild\nruntime=runtime/org.freedesktop.Sdk/x86_64/26.08\n";
setenv("CRAFTER_BUILD_FLATPAK_INFO", info.string().c_str(), 1);
if (NormalizeTarget(GetToolchain().hostTriple) != "x86_64-linux-gnu") {
std::println(std::cerr, "SKIP: the staged runtime is x86_64 and the host is {}", GetToolchain().hostTriple);
return 77;
}
if (!GetToolchain().libcxxDir.empty()) {
std::println(std::cerr, "SKIP: CRAFTER_BUILD_LIBCXX_DIR is set, and a build against it is no Flatpak");
return 77;
}
const fs::path fixture = fs::current_path() / "tests" / "FlatpakIncremental" / "fixture";
fs::remove_all(fixture / "bin", ec);
fs::remove_all(fixture / "build", ec);
Configuration app;
app.path = fixture;
app.name = "incremental-app";
app.outputName = "incremental";
app.target = HostTarget();
app.packaging = Packaging::Flatpak;
app.files = { fixture / "kept.txt", fixture / "dropped.txt" };
app.flatpak.appId = "net.example.Incremental";
app.flatpak.desktopFile = fixture / "app.desktop";
app.flatpak.icons = { fixture / "icon.svg" };
{
std::array<fs::path, 0> ifaces = {};
std::array<fs::path, 1> impls = { "main" };
app.GetInterfacesAndImplementations(ifaces, impls);
}
if (const std::string failed = BuildIt(app); !failed.empty()) {
std::println(std::cerr, "FAIL: build failed: {}", failed);
return 1;
}
const fs::path root = app.BinDir();
const fs::path bin = root / "files" / "bin";
Check(fs::exists(bin / "kept.txt") && fs::exists(bin / "dropped.txt"), "both files are placed");
app.files = { fixture / "kept.txt" };
Check(BuildIt(app).empty(), "the build without dropped.txt succeeds");
Check(!fs::exists(bin / "dropped.txt"), "a dropped cfg.files entry goes from files/bin");
Check(fs::exists(bin / "kept.txt") && fs::exists(bin / "incremental"), "what is still placed stays");
std::ofstream(bin / "written.bin") << "written by the program";
Check(BuildIt(app).empty(), "the build after the program wrote a file succeeds");
Check(fs::exists(bin / "written.bin"), "a file the program wrote stays");
app.flatpak.appId = "net.example.Renamed";
Check(BuildIt(app).empty(), "the build under the new app-id succeeds");
const fs::path share = root / "files" / "share";
Check(fs::exists(share / "applications" / "net.example.Renamed.desktop") && !fs::exists(share / "applications" / "net.example.Incremental.desktop"), "the desktop entry is renamed");
Check(fs::exists(share / "icons" / "hicolor" / "scalable" / "apps" / "net.example.Renamed.svg") && !fs::exists(share / "icons" / "hicolor" / "scalable" / "apps" / "net.example.Incremental.svg"), "the icon is renamed");
// A directory written with a trailing separator, "flat/", or as
// "flat/.", has no filename() of its own, and the build copies what it
// holds straight into files/bin, an asset directory's files as they
// are: those are the names it placed, and once the entries are dropped
// they go, rather than stay as files the program wrote.
const fs::path flat = scratch / "flat";
fs::create_directories(flat / "inner");
std::ofstream(flat / "flat.txt") << "flat\n";
std::ofstream(flat / "inner" / "nested.txt") << "nested\n";
const fs::path flatAssets = scratch / "flat-assets";
fs::create_directories(flatAssets);
std::ofstream(flatAssets / "mod.json") << "{}\n";
for (const fs::path& spelling : { fs::path(""), fs::path(".") }) {
app.files = { fixture / "kept.txt", flat / spelling };
app.assets = { flatAssets / spelling };
const std::string written = (flat / spelling).string();
Check(BuildIt(app).empty(), std::format("the build with directories written as {} succeeds", written));
Check(fs::exists(bin / "flat.txt") && fs::exists(bin / "inner" / "nested.txt") && fs::exists(bin / "mod.json"), std::format("what they hold is placed straight in files/bin, written as {}", written));
app.files = { fixture / "kept.txt" };
app.assets = {};
Check(BuildIt(app).empty(), "the build without them succeeds");
Check(!fs::exists(bin / "flat.txt") && !fs::exists(bin / "inner") && !fs::exists(bin / "mod.json"), std::format("and what they placed goes, written as {}", written));
}
// A program renamed in place: outputName is not in VariantId(), so the
// bin dir stays, and the old program goes as one the last build
// placed, rather than stay as a file the program wrote.
app.outputName = "renamed";
Check(BuildIt(app).empty(), "the build of the renamed program succeeds");
Check(fs::exists(bin / "renamed") && !fs::exists(bin / "incremental"), "files/bin holds the program under its new name, and not under the old");
// A build that fails after copying into files/bin, here at its link,
// placed what it copied all the same: once a build places it no more, it
// goes, rather than stay as a file the program wrote.
std::ofstream(scratch / "failed.txt") << "failed\n";
app.files = { fixture / "kept.txt", scratch / "failed.txt" };
app.linkFlags = { "-lcrafter-build-missing" };
Check(!BuildIt(app).empty(), "a build whose link fails fails");
Check(fs::exists(bin / "failed.txt"), "after copying its files into files/bin");
app.files = { fixture / "kept.txt" };
app.linkFlags = {};
Check(BuildIt(app).empty(), "the build after it succeeds");
Check(!fs::exists(bin / "failed.txt"), "and what the failed build placed goes");
// A copy that no longer matches its source, under the mtime it had.
const fs::path copy = root / "files" / "lib" / "libc++.so.1";
const std::string good = ReadFile(copy);
const fs::file_time_type stamp = fs::last_write_time(copy);
std::ofstream(copy, std::ios::binary | std::ios::trunc) << std::string(good.size(), 'x');
fs::last_write_time(copy, stamp);
Check(BuildIt(app).empty(), "the build after the copy went stale succeeds");
Check(ReadFile(copy) == good, "a library whose copy differs from its source is copied again, mtimes unchanged or not");
fs::remove_all(scratch, ec);
if (Failures > 0) {
std::println(std::cerr, "{} assertions failed", Failures);
return 1;
}
return 0;
}

View file

@ -0,0 +1,9 @@
// SPDX-License-Identifier: LGPL-3.0-only
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
import std;
int main() {
std::println("native");
return 0;
}

View file

@ -0,0 +1,72 @@
// SPDX-License-Identifier: LGPL-3.0-only
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
#include <stdlib.h>
import std;
import Crafter.Build;
namespace fs = std::filesystem;
using namespace Crafter;
namespace {
std::int32_t Failures = 0;
void Check(bool cond, std::string_view msg) {
if (!cond) {
std::println(std::cerr, "FAIL: {}", msg);
++Failures;
}
}
}
// A build against CRAFTER_BUILD_LIBCXX_DIR is refused as a Flatpak, before
// anything is built, saying why. Such a build compiles and links against
// that libc++, while the Flatpak's files/lib carries the toolchain's own,
// which is built against the runtime's glibc, so the app would load a
// libc++ it was not built against; bundling the other one instead would
// carry a library nothing says the runtime can load. The override is read
// once per process, so this test is a process of its own; its libc++
// directory is empty, since nothing is compiled against it.
int main() {
const fs::path scratch = fs::temp_directory_path() / "crafter-build-flatpak-libcxx-dir";
std::error_code ec;
fs::remove_all(scratch, ec);
fs::create_directories(scratch / "libcxx");
const fs::path info = scratch / "flatpak-info";
std::ofstream(info) << "[Application]\nname=net.catcrafts.CrafterBuild\nruntime=runtime/org.freedesktop.Sdk/x86_64/26.08\n";
setenv("CRAFTER_BUILD_FLATPAK_INFO", info.string().c_str(), 1);
setenv("CRAFTER_BUILD_LIBCXX_DIR", (scratch / "libcxx").string().c_str(), 1);
Check(GetToolchain().libcxxDir == scratch / "libcxx", std::format("the override is read: '{}'", GetToolchain().libcxxDir.string()));
if (NormalizeTarget(GetToolchain().hostTriple) != "x86_64-linux-gnu") {
// A skip must never cover for a failure above.
if (Failures > 0) return 1;
std::println(std::cerr, "SKIP: the staged runtime is x86_64 and the host is {}", GetToolchain().hostTriple);
return 77;
}
const fs::path fixture = fs::current_path() / "tests" / "FlatpakLibcxxDir" / "fixture";
fs::remove_all(fixture / "bin", ec);
fs::remove_all(fixture / "build", ec);
Configuration app;
app.path = fixture;
app.name = "libcxx-app";
app.outputName = "libcxx";
app.target = HostTarget();
app.packaging = Packaging::Flatpak;
{
std::array<fs::path, 0> ifaces = {};
std::array<fs::path, 1> impls = { "main" };
app.GetInterfacesAndImplementations(ifaces, impls);
}
std::unordered_map<fs::path, std::shared_future<BuildResult>> depResults;
std::mutex depMutex;
const BuildResult r = Build(app, depResults, depMutex);
Check(r.result.contains("CRAFTER_BUILD_LIBCXX_DIR") && r.result.contains("libcxx-app") && r.result.contains((scratch / "libcxx").string()), std::format("the Flatpak is refused, naming the override, its directory and the configuration: {}", r.result));
Check(!fs::exists(app.BinDir()) && !fs::exists(app.BuildDir()), "refusing it leaves nothing behind");
fs::remove_all(scratch, ec);
if (Failures > 0) {
std::println(std::cerr, "{} assertions failed", Failures);
return 1;
}
return 0;
}

View file

@ -0,0 +1,88 @@
// SPDX-License-Identifier: LGPL-3.0-only
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
import std;
import Crafter.Build;
namespace fs = std::filesystem;
using namespace Crafter;
namespace {
std::int32_t Failures = 0;
void Check(bool cond, std::string_view msg) {
if (!cond) {
std::println(std::cerr, "FAIL: {}", msg);
++Failures;
}
}
// Compiles C `source`, written to `dir`/`name`, with the toolchain's
// clang and `arguments`; empty when it compiled, else what clang said.
std::string Cc(const fs::path& dir, std::string_view name, std::string_view source, std::string_view arguments) {
std::ofstream(dir / name) << source;
const fs::path log = dir / std::format("{}.log", name);
const std::string command = std::format("{} {} {} > {} 2>&1", ShellQuote(GetToolchain().clang.string()), ShellQuote((dir / name).string()), arguments, ShellQuote(log.string()));
if (std::system(command.c_str()) == 0) return "";
std::ifstream in(log);
return std::string(std::istreambuf_iterator<char>(in), std::istreambuf_iterator<char>());
}
}
// A packaged program carries in files/lib the shared libraries it needs that
// the runtime does not have, worked out from its NEEDED entries and theirs.
// A library replaced in place can need another, as a toolchain update can
// bring, while the program stays as it was: the writer once reused what it
// had worked out for that program, so the new library's contents were
// copied and the library it needs was left out, and -r still ran the
// program, in crafter-build's sandbox, while the installed app did not
// start. It works the libraries out on every write now. A program built on
// libA.so is written, then libA.so is built again on libB.so, the program
// left as it was, and the next write has to carry libB.so as well. The
// writer is called directly, with the libraries' directory as the one it
// takes libraries from.
int main() {
const fs::path scratch = fs::temp_directory_path() / "crafter-build-flatpak-library-change";
std::error_code ec;
fs::remove_all(scratch, ec);
const fs::path libs = scratch / "libs";
const fs::path bin = scratch / "app" / "files" / "bin";
fs::create_directories(libs);
fs::create_directories(bin);
fs::create_directories(scratch / "build");
const std::string quoted = ShellQuote(libs.string());
std::string failed = Cc(scratch, "a1.c", "int a(void) { return 1; }\n", std::format("-shared -fPIC -o {}/libA.so", quoted));
Check(failed.empty(), std::format("libA.so builds: {}", failed));
failed = Cc(scratch, "main.c", "int a(void);\nint main(void) { return a(); }\n", std::format("-o {} -L{} -lA", ShellQuote((bin / "needs").string()), quoted));
Check(failed.empty(), std::format("the program builds on it: {}", failed));
if (Failures > 0) return 1;
const Toolchain& tc = GetToolchain();
FlatpakFiles d;
d.root = scratch / "app";
d.record = scratch / "build" / "flatpak-record";
d.appId = "net.example.LibraryChange";
d.command = "needs";
d.clangxx = tc.clangxx;
d.readelf = tc.llvmReadelf;
d.libraryDirs = {libs};
d.programEntries = {"needs"};
const fs::path lib = d.root / "files" / "lib";
const std::string first = WriteFlatpakFiles(d);
Check(first.empty() && fs::is_regular_file(lib / "libA.so") && !fs::exists(lib / "libB.so"), std::format("the program's library is carried, and nothing else of the directory: {}", first));
failed = Cc(scratch, "b.c", "int b(void) { return 2; }\n", std::format("-shared -fPIC -o {}/libB.so", quoted));
Check(failed.empty(), std::format("libB.so builds: {}", failed));
failed = Cc(scratch, "a2.c", "int b(void);\nint a(void) { return b(); }\n", std::format("-shared -fPIC -o {}/libA.so -L{} -lB", quoted, quoted));
Check(failed.empty(), std::format("libA.so is built again, on libB.so: {}", failed));
const std::string second = WriteFlatpakFiles(d);
Check(second.empty() && fs::is_regular_file(lib / "libA.so") && fs::is_regular_file(lib / "libB.so"), std::format("the next write carries the library the new libA.so needs: {}", second));
fs::remove_all(scratch, ec);
if (Failures > 0) {
std::println(std::cerr, "{} assertions failed", Failures);
return 1;
}
return 0;
}

View file

@ -0,0 +1,9 @@
// SPDX-License-Identifier: LGPL-3.0-only
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
import std;
int main() {
std::println("native");
return 0;
}

View file

@ -0,0 +1,76 @@
// SPDX-License-Identifier: LGPL-3.0-only
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
#include <stdlib.h>
import std;
import Crafter.Build;
namespace fs = std::filesystem;
using namespace Crafter;
namespace {
std::int32_t Failures = 0;
void Check(bool cond, std::string_view msg) {
if (!cond) {
std::println(std::cerr, "FAIL: {}", msg);
++Failures;
}
}
BuildResult BuildIt(Configuration& cfg) {
std::unordered_map<fs::path, std::shared_future<BuildResult>> depResults;
std::mutex depMutex;
return Build(cfg, depResults, depMutex);
}
}
// Only crafter-build running in its Flatpak packages a Flatpak: the program
// links that sandbox's glibc, the runtime's, so the app runs on it. A native
// crafter-build links against the host's glibc and libc++, which no runtime
// matches, so asking it for a Flatpak fails saying so, and Default builds
// the executable as linked, as it always has. A .flatpak-info without a
// runtime is staged, which is what a native process has, inside the Flatpak
// as well as out of it.
int main() {
const fs::path scratch = fs::temp_directory_path() / "crafter-build-flatpak-native";
std::error_code ec;
fs::remove_all(scratch, ec);
fs::create_directories(scratch);
const fs::path info = scratch / "flatpak-info";
std::ofstream(info) << "";
setenv("CRAFTER_BUILD_FLATPAK_INFO", info.string().c_str(), 1);
Check(GetToolchain().flatpakBranch.empty(), "without a runtime in the staged file there is none");
const fs::path fixture = fs::current_path() / "tests" / "FlatpakNative" / "fixture";
fs::remove_all(fixture / "bin", ec);
fs::remove_all(fixture / "build", ec);
Configuration app;
app.path = fixture;
app.name = "native-app";
app.outputName = "native";
app.target = HostTarget();
{
std::array<fs::path, 0> ifaces = {};
std::array<fs::path, 1> impls = { "main" };
app.GetInterfacesAndImplementations(ifaces, impls);
}
app.packaging = Packaging::Flatpak;
const BuildResult refused = BuildIt(app);
Check(refused.result.contains("only the Flatpak crafter-build packages a Flatpak") && refused.result.contains("native-app"), std::format("a native build refuses to package a Flatpak, saying why: {}", refused.result));
app.packaging = Packaging::Default;
const BuildResult built = BuildIt(app);
Check(built.result.empty(), std::format("Default builds: {}", built.result));
Check(ExpectedOutput(app) == app.BinDir() / "native" && fs::is_regular_file(ExpectedOutput(app)), "the executable is linked into the bin dir, as before");
Check(!fs::exists(app.BinDir() / "files"), "and it is not packaged");
const auto run = RunCommandWithTimeout(ShellQuote(ExpectedOutput(app).string()), std::chrono::seconds(30));
Check(run.exitCode == 0 && run.output.contains("native"), std::format("it runs: {}", run.output));
fs::remove_all(scratch, ec);
if (Failures > 0) {
std::println(std::cerr, "{} assertions failed", Failures);
return 1;
}
return 0;
}

View file

@ -0,0 +1,9 @@
// SPDX-License-Identifier: LGPL-3.0-only
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
import std;
int main() {
std::println("hello from a Flatpak");
return 0;
}

View file

@ -0,0 +1 @@
read beside the program

View file

@ -0,0 +1,181 @@
// SPDX-License-Identifier: LGPL-3.0-only
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
#include <stdlib.h>
import std;
import Crafter.Build;
namespace fs = std::filesystem;
using namespace Crafter;
namespace {
std::int32_t Failures = 0;
void Check(bool cond, std::string_view msg) {
if (!cond) {
std::println(std::cerr, "FAIL: {}", msg);
++Failures;
}
}
// The NEEDED entries of an ELF file, by the toolchain's llvm-readelf.
std::set<std::string> Needed(const fs::path& readelf, const fs::path& file) {
const auto r = RunCommandWithTimeout(std::format("{} --needed-libs {}", ShellQuote(readelf.string()), ShellQuote(file.string())), std::chrono::seconds(30));
std::set<std::string> names;
bool inList = false;
std::istringstream lines(r.output);
for (std::string line; std::getline(lines, line);) {
const std::size_t first = line.find_first_not_of(" \t");
const std::string t = first == std::string::npos ? std::string() : line.substr(first);
if (!inList) {
inList = t.starts_with("NeededLibraries [");
continue;
}
if (t == "]") break;
if (!t.empty()) names.insert(t);
}
return names;
}
// Whether the toolchain has its own copy of an LLVM runtime library.
bool ToolchainHas(const fs::path& clangxx, std::string_view name) {
const auto r = RunCommandWithTimeout(std::format("{} -print-file-name={}", ShellQuote(clangxx.string()), name), std::chrono::seconds(30));
std::string out = r.output;
while (!out.empty() && (out.back() == '\n' || out.back() == '\r')) out.pop_back();
const fs::path path = out;
std::error_code ec;
return r.exitCode == 0 && path.is_absolute() && fs::exists(path, ec);
}
std::map<fs::path, fs::file_time_type> Mtimes(const fs::path& root) {
std::map<fs::path, fs::file_time_type> times;
for (const fs::directory_entry& entry : fs::recursive_directory_iterator(root)) {
if (entry.is_regular_file()) times.emplace(entry.path(), entry.last_write_time());
}
return times;
}
}
// An executable packaged as a Flatpak comes out as the files/ of a Flatpak
// build directory, what becomes /app: the program and its files in
// files/bin, which ExpectedOutput and ProgramDir name, and in files/lib
// exactly the libraries of the toolchain the program needs, found there
// through its one run path, $ORIGIN/../lib. The Platform has no libc++, so
// an app without them would not start. The metadata and export/ are flatpak
// build-finish's to write, so the build writes neither. A second build
// changes nothing. The runtime is staged through CRAFTER_BUILD_FLATPAK_INFO,
// so the native loop packages too; inside the Flatpak the staged file wins
// over the sandbox's own.
int main() {
const fs::path scratch = fs::temp_directory_path() / "crafter-build-flatpak-output";
std::error_code ec;
fs::remove_all(scratch, ec);
fs::create_directories(scratch);
const fs::path info = scratch / "flatpak-info";
std::ofstream(info) << "[Application]\nname=net.catcrafts.CrafterBuild\nruntime=runtime/org.freedesktop.Sdk/x86_64/26.08\n";
// Before anything asks for the toolchain, which reads it once.
setenv("CRAFTER_BUILD_FLATPAK_INFO", info.string().c_str(), 1);
const Toolchain& tc = GetToolchain();
if (NormalizeTarget(tc.hostTriple) != "x86_64-linux-gnu") {
std::println(std::cerr, "SKIP: the staged runtime is x86_64 and the host is {}", tc.hostTriple);
return 77;
}
if (!tc.libcxxDir.empty()) {
std::println(std::cerr, "SKIP: CRAFTER_BUILD_LIBCXX_DIR is set, and a build against it is no Flatpak");
return 77;
}
Check(tc.flatpakArch == "x86_64" && tc.flatpakBranch == "26.08", std::format("the staged runtime is read: '{}' '{}'", tc.flatpakArch, tc.flatpakBranch));
const fs::path fixture = fs::current_path() / "tests" / "FlatpakOutput" / "fixture";
fs::remove_all(fixture / "bin", ec);
fs::remove_all(fixture / "build", ec);
Configuration app;
app.path = fixture;
app.name = "flatpak-hello";
app.outputName = "hello";
app.target = HostTarget();
app.packaging = Packaging::Flatpak;
app.files.push_back(fixture / "message.txt");
{
std::array<fs::path, 0> ifaces = {};
std::array<fs::path, 1> impls = { "main" };
app.GetInterfacesAndImplementations(ifaces, impls);
}
{
std::unordered_map<fs::path, std::shared_future<BuildResult>> depResults;
std::mutex depMutex;
const BuildResult r = Build(app, depResults, depMutex);
if (!r.result.empty()) {
std::println(std::cerr, "FAIL: build failed: {}", r.result);
return 1;
}
}
const fs::path root = app.BinDir();
const fs::path program = ExpectedOutput(app);
Check(app.ProgramDir() == root / "files" / "bin", std::format("ProgramDir is files/bin: {}", app.ProgramDir().string()));
Check(program == root / "files" / "bin" / "hello", std::format("ExpectedOutput is files/bin/hello: {}", program.string()));
Check(fs::is_regular_file(program), "the program is linked into files/bin");
Check(fs::is_regular_file(root / "files" / "bin" / "message.txt"), "cfg.files land beside the program");
Check(!fs::exists(root / "metadata") && !fs::exists(root / "export"), "no metadata or export/, which flatpak build-finish writes");
// files/lib holds what the toolchain links and the program needs, and
// nothing the runtime has.
const fs::path lib = root / "files" / "lib";
std::set<std::string> bundled;
for (const fs::directory_entry& entry : fs::directory_iterator(lib, ec)) bundled.insert(entry.path().filename().string());
std::set<std::string> needed = Needed(tc.llvmReadelf, program);
for (const std::string& name : bundled) needed.merge(Needed(tc.llvmReadelf, lib / name));
Check(bundled.contains("libc++.so.1"), "libc++.so.1 is bundled");
for (const std::string_view name : {"libc++.so.1", "libc++abi.so.1", "libunwind.so.1"}) {
if (needed.contains(std::string(name)) && ToolchainHas(tc.clangxx, name)) Check(bundled.contains(std::string(name)), std::format("{}, which the toolchain links, is bundled", name));
}
for (const std::string& name : bundled) Check(needed.contains(name), std::format("{} is bundled because something needs it", name));
for (const std::string_view name : {"libc.so.6", "libm.so.6", "libgcc_s.so.1", "ld-linux-x86-64.so.2"}) {
Check(!bundled.contains(std::string(name)), std::format("{}, the runtime's, is not bundled", name));
}
const auto dynamic = RunCommandWithTimeout(std::format("{} -d {}", ShellQuote(tc.llvmReadelf.string()), ShellQuote(program.string())), std::chrono::seconds(30));
Check(dynamic.output.contains("Library runpath: [$ORIGIN/../lib]"), std::format("the one run path is $ORIGIN/../lib:\n{}", dynamic.output));
// The loader takes libc++ from files/lib, not from wherever the
// toolchain keeps it.
if (std::system("command -v ldd > /dev/null 2>&1") == 0) {
// Without LD_LIBRARY_PATH, which flatpak-builder's build sandbox, where
// CI runs this suite, sets to /app/lib ahead of the program's run path:
// the check is what the installed app's loader does, and `flatpak run`
// sets none.
const auto ldd = RunCommandWithTimeout(std::format("env -u LD_LIBRARY_PATH ldd {}", ShellQuote(program.string())), std::chrono::seconds(30));
std::istringstream lines(ldd.output);
bool resolved = false;
for (std::string line; std::getline(lines, line);) {
const std::size_t arrow = line.find("libc++.so.1 => ");
if (arrow == std::string::npos) continue;
const std::string rest = line.substr(arrow + std::string_view("libc++.so.1 => ").size());
const fs::path path = rest.substr(0, rest.find(" ("));
resolved = fs::equivalent(path, lib / "libc++.so.1", ec);
}
Check(resolved, std::format("libc++.so.1 resolves to the bundled copy:\n{}", ldd.output));
}
const auto run = RunCommandWithTimeout(ShellQuote(program.string()), std::chrono::seconds(30));
Check(run.exitCode == 0 && run.output.contains("hello from a Flatpak"), std::format("the program runs (exit {}): {}", run.exitCode, run.output));
// A build with nothing to do writes nothing.
const std::map<fs::path, fs::file_time_type> before = Mtimes(root);
{
std::unordered_map<fs::path, std::shared_future<BuildResult>> depResults;
std::mutex depMutex;
const BuildResult r = Build(app, depResults, depMutex);
Check(r.result.empty(), std::format("the second build succeeds: {}", r.result));
}
Check(Mtimes(root) == before, "a second build leaves every file of the bin dir alone");
fs::remove_all(scratch, ec);
if (Failures > 0) {
std::println(std::cerr, "{} assertions failed", Failures);
return 1;
}
return 0;
}

View file

@ -0,0 +1,9 @@
// SPDX-License-Identifier: LGPL-3.0-only
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
export module Refused;
import std;
export std::int32_t Value() {
return 1;
}

View file

@ -0,0 +1,9 @@
// SPDX-License-Identifier: LGPL-3.0-only
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
import std;
int main() {
std::println("refused");
return 0;
}

View file

@ -0,0 +1,107 @@
// SPDX-License-Identifier: LGPL-3.0-only
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
#include <stdlib.h>
import std;
import Crafter.Build;
namespace fs = std::filesystem;
using namespace Crafter;
namespace {
std::int32_t Failures = 0;
void Check(bool cond, std::string_view msg) {
if (!cond) {
std::println(std::cerr, "FAIL: {}", msg);
++Failures;
}
}
BuildResult BuildIt(Configuration& cfg) {
std::unordered_map<fs::path, std::shared_future<BuildResult>> depResults;
std::mutex depMutex;
return Build(cfg, depResults, depMutex);
}
struct Refusal {
std::string_view what;
std::string target;
std::string sysroot;
std::string_view reason;
};
}
// An executable asking to be a Flatpak where it cannot be one is refused
// before anything is built, saying why: a Windows executable and a wasm
// build have outputs of their own, a build against a sysroot links that
// sysroot's libraries and not the runtime's, one for musl links a C library
// no runtime provides, and another architecture than the runtime's has no
// libc++ crafter-build could bundle. Each would otherwise be an app built
// against something other than what it runs with. With Default or None the
// same configurations keep the output they have, and a library asked to be
// a Flatpak is built as the library it is.
int main() {
const fs::path scratch = fs::temp_directory_path() / "crafter-build-flatpak-refusals";
std::error_code ec;
fs::remove_all(scratch, ec);
fs::create_directories(scratch);
const fs::path info = scratch / "flatpak-info";
std::ofstream(info) << "[Application]\nname=net.catcrafts.CrafterBuild\nruntime=runtime/org.freedesktop.Sdk/x86_64/26.08\n";
setenv("CRAFTER_BUILD_FLATPAK_INFO", info.string().c_str(), 1);
const fs::path fixture = fs::current_path() / "tests" / "FlatpakRefusals" / "fixture";
fs::remove_all(fixture / "bin", ec);
fs::remove_all(fixture / "build", ec);
const std::array<Refusal, 5> refusals = {{
{"a Windows executable", "x86_64-w64-mingw32", "", "a Windows executable is not packaged as a Flatpak"},
{"a wasm build", "wasm32-wasip1", "", "a wasm build is not packaged as a Flatpak"},
{"a build against a sysroot", HostTarget(), (scratch / "sysroot").string(), "links that sysroot's libraries"},
{"a musl build", "x86_64-alpine-linux-musl", "", "links musl"},
{"another architecture", "aarch64-linux-gnu", "", "the libc++ it would bundle, are x86_64"},
}};
for (const Refusal& refusal : refusals) {
Configuration app;
app.path = fixture;
app.name = "refused-app";
app.outputName = "refused";
app.target = refusal.target;
app.sysroot = refusal.sysroot;
app.packaging = Packaging::Flatpak;
std::array<fs::path, 0> ifaces = {};
std::array<fs::path, 1> impls = { "main" };
app.GetInterfacesAndImplementations(ifaces, impls);
const BuildResult r = BuildIt(app);
Check(r.result.contains(refusal.reason) && r.result.contains(app.name), std::format("{} is refused as a Flatpak, saying why and naming the configuration: {}", refusal.what, r.result));
Check(!fs::exists(app.BinDir()) && !fs::exists(app.BuildDir()), std::format("refusing {} leaves nothing behind", refusal.what));
for (const Packaging packaging : {Packaging::Default, Packaging::None}) {
app.packaging = packaging;
Check(app.ResolvedPackaging() == Packaging::None && app.ProgramDir() == app.BinDir(), std::format("{} keeps its own output with Default and None", refusal.what));
}
}
Configuration lib;
lib.path = fixture / "lib";
lib.name = "refused-lib";
lib.outputName = "refused";
lib.target = HostTarget();
lib.type = ConfigurationType::LibraryStatic;
lib.packaging = Packaging::Flatpak;
{
std::array<fs::path, 1> ifaces = { "Refused" };
std::array<fs::path, 0> impls = {};
lib.GetInterfacesAndImplementations(ifaces, impls);
}
Check(lib.ResolvedPackaging() == Packaging::None, "a library is never packaged");
const BuildResult built = BuildIt(lib);
Check(built.result.empty(), std::format("a library asked to be a Flatpak builds as a library: {}", built.result));
Check(fs::exists(ExpectedOutput(lib)) && !fs::exists(lib.BinDir() / "files"), "it is an archive, with no files/ beside it");
fs::remove_all(scratch, ec);
if (Failures > 0) {
std::println(std::cerr, "{} assertions failed", Failures);
return 1;
}
return 0;
}

View file

@ -0,0 +1,9 @@
// SPDX-License-Identifier: LGPL-3.0-only
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
export module Hello;
import std;
export std::string_view Greeting() {
return "hello from a test";
}

View file

@ -0,0 +1,10 @@
// SPDX-License-Identifier: LGPL-3.0-only
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
import std;
import Hello;
int main() {
std::println("{}", Greeting());
return 0;
}

View file

@ -0,0 +1,78 @@
// SPDX-License-Identifier: LGPL-3.0-only
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
import std;
import Crafter.Build;
namespace fs = std::filesystem;
using namespace Crafter;
namespace {
std::int32_t Failures = 0;
void Check(bool cond, std::string_view msg) {
if (!cond) {
std::println(std::cerr, "FAIL: {}", msg);
++Failures;
}
}
}
// A test is never packaged, whatever its Configuration asks for: the runner
// starts the binary itself. Saying so in AddTest alone would miss a test
// from AddMarchVariants, or one a project.cpp puts into cfg.tests itself:
// it would follow its own packaging, Default only while that means the
// executable as linked, and Packaging::Flatpak would be packaged, or, by a
// native crafter-build, refused. So RunTests runs every test as linked,
// and so does RunLint work out its compile command: the test's own module
// PCMs are where its VariantId puts them, and the Flatpak variant, which
// nothing builds, has none, so linting it with a rule that reads the AST
// used to fail the run for want of them, after any number of test runs.
int main() {
// AddTest resolves tests/<name>/main.cpp against the working directory,
// and the test's outputs land below it, in the fixture's own bin/ and
// build/.
fs::current_path(fs::current_path() / "tests" / "FlatpakTestsRaw" / "fixture");
std::error_code ec;
fs::remove_all("bin", ec);
fs::remove_all("build", ec);
Configuration project;
project.path = "./";
project.name = "flatpak-tests-raw";
project.outputName = "flatpak-tests-raw";
project.target = HostTarget();
{
std::array<fs::path, 1> ifaces = { "tests/hello/Hello" };
project.AddTest("hello", ifaces);
}
project.tests.back().config.packaging = Packaging::Flatpak;
RunTestsOptions opts;
opts.jobs = 1;
const TestSummary summary = RunTests(project, opts);
Check(summary.results.size() == 1, std::format("one test ran, got {}", summary.results.size()));
if (!summary.results.empty()) {
const TestResult& result = summary.results.front();
Check(result.outcome == TestOutcome::Pass, std::format("the test passes (exit {}): {}", result.exitCode, result.output));
Check(result.output.contains("hello from a test"), "the output is the program's own");
}
const Configuration& test = project.tests.back().config;
Check(test.ResolvedPackaging() == Packaging::None, "the test is built as linked");
Check(!fs::exists(test.BinDir() / "files") && fs::is_regular_file(test.BinDir() / "hello"), "its bin directory holds the program, and no Flatpak files/");
// As `crafter-build lint` loads the project afresh: the test asks for a
// Flatpak again, and main.cpp, which imports Hello, parses against the
// PCMs the test run built.
project.tests.back().config.packaging = Packaging::Flatpak;
std::size_t parsed = 0;
project.AddAstLintRule("parses", [&parsed](LintContext&) { ++parsed; });
const LintSummary lint = RunLint(project, RunLintOptions{});
Check(lint.errors == 0 && parsed == 2, std::format("lint parses the test's two files against those PCMs ({} errors, {} parsed)", lint.errors, parsed));
if (Failures > 0) {
std::println(std::cerr, "{} assertions failed", Failures);
return 1;
}
return 0;
}

View file

@ -0,0 +1,14 @@
// SPDX-License-Identifier: LGPL-3.0-only
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
import std;
// A function of libedit, called only on a path that never runs, so that the
// link records the library.
extern "C" void* history_init();
int main(int argc, char**) {
if (argc > 100) history_init();
std::println("linked against libedit");
return 0;
}

View file

@ -0,0 +1,125 @@
// SPDX-License-Identifier: LGPL-3.0-only
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
#include <stdlib.h>
import std;
import Crafter.Build;
namespace fs = std::filesystem;
using namespace Crafter;
namespace {
std::int32_t Failures = 0;
void Check(bool cond, std::string_view msg) {
if (!cond) {
std::println(std::cerr, "FAIL: {}", msg);
++Failures;
}
}
// The NEEDED entries of an ELF file, by the toolchain's llvm-readelf.
std::set<std::string> Needed(const fs::path& readelf, const fs::path& file) {
const auto r = RunCommandWithTimeout(std::format("{} --needed-libs {}", ShellQuote(readelf.string()), ShellQuote(file.string())), std::chrono::seconds(30));
std::set<std::string> names;
bool inList = false;
std::istringstream lines(r.output);
for (std::string line; std::getline(lines, line);) {
const std::size_t first = line.find_first_not_of(" \t");
const std::string t = first == std::string::npos ? std::string() : line.substr(first);
if (!inList) {
inList = t.starts_with("NeededLibraries [");
continue;
}
if (t == "]") break;
if (!t.empty()) names.insert(t);
}
return names;
}
}
// A program packaged as a Flatpak carries what its link takes from the
// toolchain's own lib dir, which the Flatpak link searches with -L. In
// crafter-build's Flatpak that is /app/lib, which holds libclang, libLLVM,
// liblldb and libedit beside the LLVM runtime libraries, none of them a
// runtime's. The writer used to look only in the directories of the shared
// libraries the program is built on and took any other name for the
// runtime's, so a program linked against one of those started under -r,
// where crafter-build's own /app/lib is on the loader's path, and failed
// once installed. The fixture links libedit. Skips where the toolchain is in
// /usr, whose lib dir is the system's, and where its lib dir has no libedit.
int main() {
const fs::path scratch = fs::temp_directory_path() / "crafter-build-flatpak-toolchain-library";
std::error_code ec;
fs::remove_all(scratch, ec);
fs::create_directories(scratch);
const fs::path info = scratch / "flatpak-info";
std::ofstream(info) << "[Application]\nname=net.catcrafts.CrafterBuild\nruntime=runtime/org.freedesktop.Sdk/x86_64/26.08\n";
setenv("CRAFTER_BUILD_FLATPAK_INFO", info.string().c_str(), 1);
const Toolchain& tc = GetToolchain();
if (NormalizeTarget(tc.hostTriple) != "x86_64-linux-gnu") {
std::println(std::cerr, "SKIP: the staged runtime is x86_64 and the host is {}", tc.hostTriple);
return 77;
}
if (!tc.libcxxDir.empty()) {
std::println(std::cerr, "SKIP: CRAFTER_BUILD_LIBCXX_DIR is set, and a build against it is no Flatpak");
return 77;
}
const fs::path toolchainLib = tc.LibcxxLibDir();
if (toolchainLib.empty()) {
std::println(std::cerr, "SKIP: the toolchain is in /usr, whose libraries are the system's");
return 77;
}
if (!fs::exists(toolchainLib / "libedit.so")) {
std::println(std::cerr, "SKIP: the toolchain's lib dir, {}, has no libedit.so", toolchainLib.string());
return 77;
}
const fs::path fixture = fs::current_path() / "tests" / "FlatpakToolchainLibrary" / "fixture";
fs::remove_all(fixture / "bin", ec);
fs::remove_all(fixture / "build", ec);
Configuration app;
app.path = fixture;
app.name = "toolchain-library-app";
app.outputName = "edit";
app.target = HostTarget();
app.packaging = Packaging::Flatpak;
app.flatpak.appId = "net.example.ToolchainLibrary";
app.linkFlags = { "-ledit" };
{
std::array<fs::path, 0> ifaces = {};
std::array<fs::path, 1> impls = { "main" };
app.GetInterfacesAndImplementations(ifaces, impls);
}
{
std::unordered_map<fs::path, std::shared_future<BuildResult>> depResults;
std::mutex depMutex;
if (const BuildResult r = Build(app, depResults, depMutex); !r.result.empty()) {
std::println(std::cerr, "FAIL: build failed: {}", r.result);
return 1;
}
}
const fs::path lib = app.BinDir() / "files" / "lib";
const std::set<std::string> needed = Needed(tc.llvmReadelf, ExpectedOutput(app));
const auto edit = std::ranges::find_if(needed, [](const std::string& name) { return name.starts_with("libedit.so"); });
Check(edit != needed.end(), std::format("the program needs libedit (NEEDED: {})", needed));
if (edit != needed.end()) {
Check(fs::exists(toolchainLib / *edit), std::format("{} is the toolchain's, in {}", *edit, toolchainLib.string()));
Check(fs::is_regular_file(lib / *edit), std::format("{} is carried in files/lib", *edit));
}
// Whatever the program and the libraries it carries need from the
// toolchain's lib dir is carried too.
std::set<std::string> all = needed;
for (const fs::directory_entry& entry : fs::directory_iterator(lib)) all.merge(Needed(tc.llvmReadelf, entry.path()));
for (const std::string& name : all) {
if (fs::exists(toolchainLib / name)) Check(fs::exists(lib / name), std::format("{}, from the toolchain's lib dir, is carried in files/lib", name));
}
fs::remove_all(scratch, ec);
if (Failures > 0) {
std::println(std::cerr, "{} assertions failed", Failures);
return 1;
}
return 0;
}

View file

@ -1,6 +1,7 @@
// SPDX-License-Identifier: LGPL-3.0-only
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
#include <stdlib.h>
import std;
import Crafter.Build;
namespace fs = std::filesystem;
@ -67,11 +68,20 @@ namespace {
// An executable built on a LibraryDynamic dependency starts: the loader
// finds lib<name>.so, which the executable's link took from the library's
// bin dir, through the run path the link records for that directory.
// Before, the link took the library and recorded nowhere to find it, so the
// program failed at start with "cannot open shared object file".
// bin dir. Linked as it is, the executable records that directory as a run
// path; packaged as a Flatpak, it carries the library in files/lib, where
// its run path looks. Before, the link took the library and recorded
// nowhere to find it, so the program failed at start with "cannot open
// shared object file", raw and packaged alike.
int main() {
const fs::path scratch = fs::temp_directory_path() / "crafter-build-shared-library-runs";
std::error_code ec;
fs::remove_all(scratch, ec);
fs::create_directories(scratch);
const fs::path info = scratch / "flatpak-info";
std::ofstream(info) << "[Application]\nname=net.catcrafts.CrafterBuild\nruntime=runtime/org.freedesktop.Sdk/x86_64/26.08\n";
setenv("CRAFTER_BUILD_FLATPAK_INFO", info.string().c_str(), 1);
const fs::path fixture = fs::current_path() / "tests" / "SharedLibraryRuns" / "fixture";
fs::remove_all(fixture / "bin", ec);
fs::remove_all(fixture / "build", ec);
@ -108,8 +118,24 @@ int main() {
const std::string comma = FromCommaDirectory(fixture);
Check(comma.empty(), std::format("built from a directory whose name holds a comma, it starts: {}", comma));
const auto raw = RunCommandWithTimeout(ShellQuote(ExpectedOutput(app).string()), std::chrono::seconds(30));
Check(raw.exitCode == 0 && raw.output.contains("hello from a shared library"), std::format("the program starts (exit {}): {}", raw.exitCode, raw.output));
Check(raw.exitCode == 0 && raw.output.contains("hello from a shared library"), std::format("linked as it is, it starts (exit {}): {}", raw.exitCode, raw.output));
if (NormalizeTarget(GetToolchain().hostTriple) == "x86_64-linux-gnu" && GetToolchain().libcxxDir.empty()) {
app.packaging = Packaging::Flatpak;
if (const std::string failed = BuildIt(app); !failed.empty()) {
std::println(std::cerr, "FAIL: the Flatpak build failed: {}", failed);
return 1;
}
Check(fs::is_regular_file(app.BinDir() / "files" / "lib" / "libgreet.so"), "the Flatpak carries the library in files/lib");
const auto packaged = RunCommandWithTimeout(ShellQuote(ExpectedOutput(app).string()), std::chrono::seconds(30));
Check(packaged.exitCode == 0 && packaged.output.contains("hello from a shared library"), std::format("packaged as a Flatpak, it starts (exit {}): {}", packaged.exitCode, packaged.output));
} else if (!GetToolchain().libcxxDir.empty()) {
std::println("the Flatpak half is left out: CRAFTER_BUILD_LIBCXX_DIR is set, and a build against it is no Flatpak");
} else {
std::println("the Flatpak half is left out: the staged runtime is x86_64 and the host is {}", GetToolchain().hostTriple);
}
fs::remove_all(scratch, ec);
if (Failures > 0) {
std::println(std::cerr, "{} assertions failed", Failures);
return 1;

View file

@ -69,6 +69,29 @@ int main() {
ApplyStandardArgs(cfg, raw);
Check(cfg.type == ConfigurationType::Executable, "--shared alone on Executable is a no-op");
}
{
// --packaging= is standard: it sets cfg.packaging and, its effect
// showing in VariantId already, stays out of projectArgs. Outside any
// project file, as here, it counts as the top-level project's.
Configuration flatpak;
std::array<std::string_view, 1> raw = { "--packaging=flatpak" };
ApplyStandardArgs(flatpak, raw);
Check(flatpak.packaging == Packaging::Flatpak, "--packaging=flatpak asks for a Flatpak");
Check(flatpak.projectArgs.empty(), "--packaging= is not a project arg");
Configuration none;
std::array<std::string_view, 1> rawNone = { "--packaging=none" };
ApplyStandardArgs(none, rawNone);
Check(none.packaging == Packaging::None, "--packaging=none asks for the executable as linked");
Configuration bad;
std::array<std::string_view, 1> rawBad = { "--packaging=snap" };
bool threw = false;
try {
ApplyStandardArgs(bad, rawBad);
} catch (const std::invalid_argument& e) {
threw = std::string_view(e.what()).contains("expected none or flatpak");
}
Check(threw, "an unknown --packaging= is an error naming the kinds");
}
// ArgQuery is returned over the same args span and exposes Has/Get.
{

View file

@ -215,6 +215,33 @@ int main() {
Check(!real.Key().starts_with("unknown-"), std::format("the real clang version parses (got '{}')", real.Key()));
}
{
// The runtime crafter-build runs on is the runtime= ref in
// /.flatpak-info's [Application] group: what a packaged program
// links against, and so the runtime it is packaged for.
ToolchainInputs in;
in.flatpakInfo = "[Application]\nname=net.catcrafts.CrafterBuild\nruntime=runtime/org.freedesktop.Sdk/x86_64/26.08\n\n[Instance]\nruntime=runtime/org.example.Other/aarch64/1\n";
const Toolchain tc = ResolveToolchain(in);
Check(tc.flatpakArch == "x86_64" && tc.flatpakBranch == "26.08", std::format("the runtime's arch and branch are read (got '{}' '{}')", tc.flatpakArch, tc.flatpakBranch));
Check(ResolveToolchain({}).flatpakBranch.empty(), "outside a Flatpak there is no runtime");
ToolchainInputs elsewhere;
elsewhere.flatpakInfo = "[Instance]\nruntime=runtime/org.freedesktop.Sdk/x86_64/26.08\n";
Check(ResolveToolchain(elsewhere).flatpakBranch.empty(), "a runtime= outside [Application] is not the runtime");
ToolchainInputs malformed;
malformed.flatpakInfo = "[Application]\nruntime=org.freedesktop.Sdk/26.08\n";
Check(ResolveToolchain(malformed).flatpakBranch.empty(), "a runtime= that is not a runtime ref is ignored");
// llvm-readelf, which reads what a packaged program needs, sits
// beside the compiler like llvm-ar; LibcxxSearchFlags is the link
// flags without the rpath a Flatpak does not use.
Check(ResolveToolchain({}).llvmReadelf == "llvm-readelf", "the PATH fallback names llvm-readelf bare");
ToolchainInputs prefixed;
prefixed.env.emplace("CRAFTER_BUILD_LLVM_DIR", full.string());
const Toolchain withPrefix = ResolveToolchain(prefixed);
Check(withPrefix.llvmReadelf == full / "bin" / "llvm-readelf", "llvm-readelf comes from the prefix");
Check(withPrefix.LibcxxSearchFlags() == std::format(" -L{}", (full / "lib").string()), std::format("the search flags are -L alone (got '{}')", withPrefix.LibcxxSearchFlags()));
}
fs::remove_all(scratch, ec);
return Failures == 0 ? 0 : 1;
}

View file

@ -46,6 +46,33 @@ int main() {
b.type = ConfigurationType::LibraryStatic;
Check(a.VariantId() != b.VariantId(), "type change perturbs VariantId");
}
{
// A Flatpak lays its bin dir out unlike the executable as linked, so
// the two get directories of their own. Only a Flatpak is keyed:
// Default and None, and a library whatever it asks for, keep the
// directory they had, and what the app is installed as changes
// files/share only, never what is compiled.
Configuration plain = MakeBase();
Configuration none = MakeBase();
none.packaging = Packaging::None;
Configuration flatpak = MakeBase();
flatpak.packaging = Packaging::Flatpak;
Configuration described = MakeBase();
described.packaging = Packaging::Flatpak;
described.flatpak.appId = "net.example.Described";
described.flatpak.desktopFile = "app.desktop";
described.flatpak.icons = {"icon.svg"};
Configuration library = MakeBase();
library.type = ConfigurationType::LibraryStatic;
Configuration flatpakLibrary = MakeBase();
flatpakLibrary.type = ConfigurationType::LibraryStatic;
flatpakLibrary.packaging = Packaging::Flatpak;
Check(plain.VariantId() == none.VariantId(), "Default and None share a directory");
Check(plain.VariantId() != flatpak.VariantId(), "a Flatpak gets a directory of its own");
Check(flatpak.VariantId() == described.VariantId(), "the app-id, desktop entry and icons do not move the directory");
Check(library.VariantId() == flatpakLibrary.VariantId(), "a library ignores packaging");
Check(flatpak.ProgramDir() == flatpak.BinDir() / "files" / "bin" && plain.ProgramDir() == plain.BinDir(), "a Flatpak's program lives in files/bin, everything else's in the bin dir");
}
{
// debug differs -> VariantId differs.
Configuration a = MakeBase();

View file

@ -45,6 +45,14 @@ int main() {
return 77; // skipped — environmental, not a code defect
}
// Assets go into files.json under the names Build() writes them as: a
// texture or mesh compressed (an upper-case extension too), a file of a
// directory entry under the directory's name, passed through as it is.
fs::create_directories(cfg.path / "maps" / "a");
std::ofstream(cfg.path / "maps" / "a" / "b.jpg") << "";
std::ofstream(cfg.path / "maps" / "mod.json") << "{}";
cfg.assets = { cfg.path / "tex.PNG", cfg.path / "mesh.obj", cfg.path / "maps" };
EnableWasiBrowserRuntime(cfg);
// Three files registered: runtime.js, generated index.html, files.json.
@ -86,6 +94,17 @@ int main() {
return 1;
}
{
std::ifstream fin(*manifest);
const std::string fjson{std::istreambuf_iterator<char>(fin), std::istreambuf_iterator<char>()};
for (const std::string_view name : {"\"tex.ctex\"", "\"mesh.cmesh\"", "\"maps/a/b.ctex\"", "\"maps/mod.json\""}) {
if (!fjson.contains(name)) {
std::println(std::cerr, "files.json lacks {}, the name the build writes the asset as: {}", name, fjson);
return 1;
}
}
}
// With no declared variants, variants.json is a single baseline entry
// pointing at outputName.wasm, with only the probes for what every wasm
// build needs, SIMD128 and exception handling, so that runtime.js can