From 9d62eef571ffd1fd2df8b97884d3689fced27fb1 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Tue, 7 Jan 2025 17:39:32 +0100 Subject: Implement architecture variants Architecture variants are children of an architecture that share the same ABI but are optimized for different ISA levels. They are available in Ubuntu 25.10 and newer, and not supported in Debian or other distributions. A deb built for a variant contains the Architecture-Variant field, and the Architecture field points to the baseline, for example: Architecture: amd64 Architecture-Variant: amd64v3 However, the apt-get indextargets command reports the variant in the Architecture: field, and most of the code in APT presents the variant as the architecture. There are two types of variants: 1. Standalone variants are recorded in the Architectures field of the Release file as if they were a real architecture: Architectures: amd64 amd64v3 Standalone architecture variants only fetch the standalone architecture variant's Packages file. To do this, this patch changes the code such that the variants indextargets "supplant" the base targets. This may have complicated outcomes on the apt-get indextargets command. 2. Other variants can only be identified by their files being recorded with hashes in the Release file. APT fetches both the base architecture's as well as the variant's Packages file. Variants are configured in the APT::Architecture-Variants list. Image builders may want to build specific variant images using APT::Architecture-Variants { "amd64v3"; } But this commit also implements an automatic discovery mechanism using the varianttable and /proc/cpuinfo. APT::Architecture-Variants "auto"; --- apt-pkg/pkgcachegen.cc | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'apt-pkg/pkgcachegen.cc') diff --git a/apt-pkg/pkgcachegen.cc b/apt-pkg/pkgcachegen.cc index 3358441ee..f3c3c10a0 100644 --- a/apt-pkg/pkgcachegen.cc +++ b/apt-pkg/pkgcachegen.cc @@ -104,12 +104,23 @@ bool pkgCacheGenerator::Start() map_stringitem_t idxArchitectures; std::vector archs = APT::Configuration::getArchitectures(); - if (archs.size() > 1) + auto const &variants = APT::Configuration::getArchitectureVariants(true); + if (archs.size() > 1 || not variants.empty()) { std::vector::const_iterator a = archs.begin(); std::string list = *a; for (++a; a != archs.end(); ++a) list.append(",").append(*a); + if (not variants.empty()) + { + list.append(";"); + for (auto const &variant : variants) + { + if (list.back() != ';') + list.append(","); + list.append(variant.name); + } + } idxArchitectures = WriteStringInMap(list); if (unlikely(idxArchitectures == 0)) return false; @@ -383,11 +394,20 @@ bool pkgCacheGenerator::MergeListVersion(ListParser &List, pkgCache::PkgIterator auto Hash = List.VersionHash(); std::string_view ListSHA256; + std::string_view ListArchVariant; bool const Debug = _config->FindB("Debug::pkgCacheGen", false); auto DebList = dynamic_cast(&List); if (DebList != nullptr) ListSHA256 = DebList->SHA256(); + if (DebList != nullptr) + ListArchVariant = DebList->ArchVariant(); + + auto variants = _config->FindVector("APT::Architecture-Variants"); + // Always add "no variant" at the back of the list. If it's already configured earlier, that wins + if (variants.empty() || variants.back() != "") + variants.push_back(""); + if (Ver.end() == false) { /* We know the list is sorted so we use that fact in the search. @@ -426,6 +446,13 @@ bool pkgCacheGenerator::MergeListVersion(ListParser &List, pkgCache::PkgIterator if (VF.end() == true) break; } + + // Variants are ordered by their index in the variant list. + if (std::find(variants.begin(), variants.end(), Ver.ArchVariant()) > std::find(variants.begin(), variants.end(), ListArchVariant)) + { + Res = 1; + break; + } } // proceed with the next till we have either the right // or we found another version (which will be lower) -- cgit v1.2.3-70-g09d2