98 lines
2.7 KiB
C++
98 lines
2.7 KiB
C++
#pragma once
|
|
|
|
#include <Void/Functional/Error.hpp>
|
|
#include <Void/Functional/Result.hpp>
|
|
#include <Void/Text/Semver.hpp>
|
|
|
|
#include <compare>
|
|
#include <map>
|
|
#include <optional>
|
|
#include <set>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace Void::Build::Package {
|
|
|
|
// Registry authority is an explicit part of package identity to prevent cross-registry
|
|
// substitution.
|
|
struct PackageId {
|
|
std::string registry_authority;
|
|
std::string name;
|
|
|
|
auto operator<=>(const PackageId &) const = default;
|
|
[[nodiscard]] std::string format() const;
|
|
};
|
|
|
|
struct DependencyConstraint {
|
|
PackageId target;
|
|
std::string range_expr;
|
|
std::vector<std::string> required_features;
|
|
std::string origin_label;
|
|
};
|
|
|
|
struct BinaryVariantMeta {
|
|
std::string variant_id;
|
|
std::string os;
|
|
std::string architecture;
|
|
std::string compiler_family;
|
|
std::string compiler_abi;
|
|
std::string stdlib_abi;
|
|
std::string linkage;
|
|
std::string cpu_features;
|
|
std::string sanitizers_key;
|
|
std::string lto_mode;
|
|
std::string dependency_closure_hash;
|
|
std::string sha256;
|
|
std::string download_url;
|
|
};
|
|
|
|
struct ReleaseRecord {
|
|
PackageId id;
|
|
Void::Semver::Version version;
|
|
bool yanked{false};
|
|
std::string source_sha256;
|
|
std::string source_url;
|
|
std::vector<DependencyConstraint> dependencies;
|
|
std::vector<BinaryVariantMeta> binaries;
|
|
};
|
|
|
|
class PackageIndex {
|
|
public:
|
|
void add_release(ReleaseRecord release);
|
|
[[nodiscard]] std::vector<ReleaseRecord> releases_for(const PackageId &id) const;
|
|
|
|
private:
|
|
std::map<PackageId, std::vector<ReleaseRecord>> releases_;
|
|
};
|
|
|
|
struct SolvedPackage {
|
|
PackageId id;
|
|
Void::Semver::Version version;
|
|
std::string source_sha256;
|
|
std::string source_url;
|
|
std::set<std::string> enabled_features;
|
|
std::vector<PackageId> dependencies;
|
|
std::vector<BinaryVariantMeta> binaries;
|
|
};
|
|
|
|
struct SolveResult {
|
|
std::map<PackageId, SolvedPackage> packages; // Deterministically ordered.
|
|
};
|
|
|
|
struct SolveOptions {
|
|
// Already-pinned compatible versions from an existing lockfile (never silently upgraded!).
|
|
std::map<PackageId, Void::Semver::Version> pinned_versions;
|
|
bool allow_yanked_if_pinned{true};
|
|
std::size_t max_steps{50000};
|
|
};
|
|
|
|
// Deterministic PubGrub-style SemVer dependency solver (Plan 11):
|
|
// - One version per PackageId per resolution context
|
|
// - Prefers compatible pinned versions; otherwise picks highest non-yanked matching version
|
|
// - Produces human-readable incompatibility chains on unsatisfiable graphs.
|
|
[[nodiscard]] Void::Result::Result<SolveResult, Void::Result::Error>
|
|
solve_dependencies(const std::vector<DependencyConstraint> &root_constraints,
|
|
const PackageIndex &index, const SolveOptions &options = {});
|
|
|
|
} // namespace Void::Build::Package
|