// SPDX-License-Identifier: LGPL-3.0-only // SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts® #include 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 ifaces = {}; std::array impls = { "main" }; app.GetInterfacesAndImplementations(ifaces, impls); } std::unordered_map> 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; }