module; #include module cargoxx.codegen; import std; import cargoxx.util; namespace cargoxx::codegen { auto parse_vendor_toml(std::string_view body) -> util::Result { toml::table root; try { root = toml::parse(body); } catch (const toml::parse_error& e) { return std::unexpected(util::Error{ util::ErrorCode::ManifestParseError, std::format("vendor.toml is not valid TOML: {}", e.description()), "", std::nullopt, std::nullopt, }); } auto missing = [](std::string msg) { return util::Error{ util::ErrorCode::ManifestInvalidField, std::move(msg), "", std::nullopt, std::nullopt, }; }; VendorIndex out; if (const auto* tbl = root["nixpkgs"].as_table()) { if (auto v = (*tbl)["store_path"].value()) { out.nixpkgs_store_path = *v; } else { return std::unexpected(missing("vendor.toml: [nixpkgs].store_path is required")); } } else { return std::unexpected(missing("vendor.toml: [nixpkgs] table is required")); } if (const auto* tbl = root["flake_utils"].as_table()) { if (auto v = (*tbl)["store_path"].value()) { out.flake_utils_store_path = *v; } else { return std::unexpected(missing("vendor.toml: [flake_utils].store_path is required")); } } else { return std::unexpected(missing("vendor.toml: [flake_utils] table is required")); } if (const auto* arr = root["dep"].as_array()) { for (const auto& el : *arr) { const auto* tbl = el.as_table(); if (!tbl) { return std::unexpected(missing("vendor.toml: [[dep]] entries must be tables")); } auto attr = (*tbl)["nixpkgs_attr"].value(); auto path = (*tbl)["store_path"].value(); if (!attr || !path) { return std::unexpected(missing( "vendor.toml: each [[dep]] needs nixpkgs_attr and store_path")); } out.dep_store_paths.emplace(*attr, *path); } } return out; } } // namespace cargoxx::codegen