Skip to content

Commit

Permalink
bib: use target architecture for buildroot as well
Browse files Browse the repository at this point in the history
The existing code is trying to fetch two containers when doing
a cross-arch image. The buildroot is run in the native architecture
and only the target tree is run non-native. However it turns out
this is not neccessary as even doing the buildroot in non-native
is fast enough (given that it's mostly I/O and all I/O is run
naively via syscall translation).

So this commit removes the fetching of the native arch container
for the buildroot. Note that in practise this was already the
case when passing --target-arch to any container that had native
build available. Here due to a bug/misfeature in the resolver library
used it already resolved (incorrectly) to the target architecture and
nobody noticed because it was good enough (after [0] got fixed).

[0] https://lists.nongnu.org/archive/html/qemu-devel/2024-02/msg03971.html
  • Loading branch information
mvo5 committed Apr 10, 2024
1 parent 8e0597c commit 2950534
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions bib/cmd/bootc-image-builder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,28 +170,22 @@ func makeManifest(c *ManifestConfig, cacheRoot string) (manifest.OSBuildManifest

// Resolve container - the normal case is that host and target
// architecture are the same. However it is possible to build
// cross-arch images. When this is done the "build" pipeline
// will run with the "native" architecture of the target
// container and the other pipelines (usually just "image"
// will use the target architecture).
// cross-arch images by using qemu-user. Just run everything
// (including the build-root) with the target arch then, it
// is fast enough (given that it's mostly I/O and all I/O is
// run naively via syscall translation)
hostArch := arch.Current().String()
targetArch := c.Architecture.String()

resolverNative := container.NewResolver(hostArch)
resolverTarget := resolverNative
if hostArch != targetArch {
resolverTarget = container.NewResolver(targetArch)
var resolver *container.Resolver
if targetArch != "" {
resolver = container.NewResolver(targetArch)
} else {
resolver = container.NewResolver(hostArch)
}

containerSpecs := make(map[string][]container.Spec)
for plName, sourceSpecs := range manifest.GetContainerSourceSpecs() {
var resolver *container.Resolver
if plName == "build" {
resolver = resolverNative
} else {
resolver = resolverTarget
}

for _, c := range sourceSpecs {
resolver.Add(c)
}
Expand Down

0 comments on commit 2950534

Please sign in to comment.