// SPDX-License-Identifier: LGPL-3.0-only // SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts® export module Crafter.Build:Interface; import std; import :Jobs; namespace fs = std::filesystem; namespace Crafter { export class Module; export class ModulePartition { public: // What this unit imports, as the Build() that made it read the // source: modules of its own configuration, partitions of its own // module, and modules of the configurations it is built on, each of // those with the BMI that configuration's build writes. An import of // anything else, `std` or a module from outside the build, has no // entry. std::vector moduleDependencies; std::vector partitionDependencies; std::vector> externalModuleDependencies; // The state of the Build() that made this unit: whether Check has // run, what it found, whether Schedule has added this unit's jobs, // and the one among them that writes its BMI, which is the job the // units importing it come after. bool needsRecompiling = false; bool checked = false; bool scheduled = false; std::optional precompileJob; std::string name; fs::path path; ModulePartition(std::string&& name, fs::path&& path); // Whether this unit's BMI has to be written again. The object made // from the BMI is not Check's to judge: see Schedule. bool Check(const fs::path& pcmDir, fs::file_time_type sourceFloor = fs::file_time_type::min()); // Adds the jobs this unit needs to `jobs`, once however often it is // called, and returns the one that writes its BMI, if there is one. // // A unit Check found stale gets two, one for each run of `clang`: the // BMI, after the BMIs of the stale units this one imports, which are // scheduled here as well, and then the object from that BMI, which // only the link waits for, so that the units importing this one start // when the first is done. // // A unit whose BMI is up to date gets the second job alone when its // object is missing or older than the BMI. A build that fails or is // interrupted between the two leaves a unit like that, and by its BMI // alone every build after it would call the unit built: the link then // took the object of the source before the edit, or found none. // // Every unit this one imports must have been checked: Build() checks // all of a configuration's interfaces before it schedules any. std::optional Schedule(JobGroup& jobs, std::string_view clang, const fs::path& pcmDir, const fs::path& buildDir); }; export class Module { public: // A primary module interface unit imports things too — `import Base;` // in `export module Widget;` is as much a layout dependency as the // same line in a partition. Recorded as a partition records the // modules it imports, with the same meanings, so Check() can see // through them and Schedule() can order itself behind a sibling // module in the same Configuration (issue #26). The partitions it // imports need no entry: it is checked and built after all of its // module's partitions. std::vector moduleDependencies; std::vector> externalModuleDependencies; // As in ModulePartition. bool needsRecompiling = false; bool checked = false; bool scheduled = false; std::optional precompileJob; std::vector> partitions; std::string name; fs::path path; Module(std::string&& name, fs::path&& path); bool Check(const fs::path& pcmDir, fs::file_time_type sourceFloor = fs::file_time_type::min()); // As ModulePartition::Schedule, for the primary interface, and // schedules every partition of the module with it. The primary // interface comes after every stale partition of the module, // whichever of them it imports, and after the stale sibling modules // it imports. std::optional Schedule(JobGroup& jobs, std::string_view clang, const fs::path& pcmDir, const fs::path& buildDir); }; }