diff --git a/frontend/azlinux/handle_container.go b/frontend/azlinux/handle_container.go index 44c2da03e..1ec9b3b2f 100644 --- a/frontend/azlinux/handle_container.go +++ b/frontend/azlinux/handle_container.go @@ -25,7 +25,7 @@ func handleContainer(w worker) gwclient.BuildFunc { pg := dalec.ProgressGroup("Building " + targetKey + " container: " + spec.Name) - rpmDir, err := specToRpmLLB(ctx, w, client, spec, sOpt, targetKey, pg, dalec.WithPlatform(platform)) + rpmDir, err := specToRpmLLB(ctx, w, client, spec, sOpt, targetKey, platform, pg) if err != nil { return nil, nil, fmt.Errorf("error creating rpm: %w", err) } diff --git a/frontend/azlinux/handle_depsonly.go b/frontend/azlinux/handle_depsonly.go index 3de52c2cc..94ffbfea9 100644 --- a/frontend/azlinux/handle_depsonly.go +++ b/frontend/azlinux/handle_depsonly.go @@ -31,7 +31,7 @@ func handleDepsOnly(w worker) gwclient.BuildFunc { if err != nil { return nil, nil, err } - st, err := specToContainerLLB(w, client, spec, targetKey, rpmDir, files, sOpt, pg) + st, err := specToContainerLLB(w, client, spec, targetKey, rpmDir, files, sOpt, pg, dalec.WithPlatform(platform)) if err != nil { return nil, nil, err } diff --git a/frontend/azlinux/handle_rpm.go b/frontend/azlinux/handle_rpm.go index c4efbfb9e..89e1f8254 100644 --- a/frontend/azlinux/handle_rpm.go +++ b/frontend/azlinux/handle_rpm.go @@ -26,7 +26,7 @@ func handleRPM(w worker) gwclient.BuildFunc { return nil, nil, err } - st, err := specToRpmLLB(ctx, w, client, spec, sOpt, targetKey, pg, dalec.WithPlatform(platform)) + st, err := specToRpmLLB(ctx, w, client, spec, sOpt, targetKey, platform, pg) if err != nil { return nil, nil, err } @@ -64,13 +64,18 @@ func installBuildDeps(w worker, spec *dalec.Spec, targetKey string, opts ...llb. } } -func specToRpmLLB(ctx context.Context, w worker, client gwclient.Client, spec *dalec.Spec, sOpt dalec.SourceOpts, targetKey string, opts ...llb.ConstraintsOpt) (llb.State, error) { +func specToRpmLLB(ctx context.Context, w worker, client gwclient.Client, spec *dalec.Spec, sOpt dalec.SourceOpts, targetKey string, platform *ocispecs.Platform, opts ...llb.ConstraintsOpt) (llb.State, error) { + // Generate the buildroot with the native platform base := w.Base(client, opts...).With(installBuildDeps(w, spec, targetKey, opts...)) br, err := rpm.SpecToBuildrootLLB(base, spec, sOpt, targetKey, opts...) if err != nil { return llb.Scratch(), err } specPath := filepath.Join("SPECS", spec.Name, spec.Name+".spec") + + // Build the RPM with the target platform + opts = append(opts, dalec.WithPlatform(platform)) + base = w.Base(client, opts...).With(installBuildDeps(w, spec, targetKey, opts...)) st := rpm.Build(br, base, specPath, opts...) return frontend.MaybeSign(ctx, client, st, spec, targetKey) diff --git a/frontend/rpm/handle_buildroot.go b/frontend/rpm/handle_buildroot.go index 7438d8230..60722712f 100644 --- a/frontend/rpm/handle_buildroot.go +++ b/frontend/rpm/handle_buildroot.go @@ -21,6 +21,8 @@ func HandleBuildroot(wf WorkerFunc) gwclient.BuildFunc { return nil, nil, err } + // Note, we are not passing platform down here because everything should + // be able to work regardless of platform, so prefer the native platform. worker, err := wf(sOpt.Resolver, spec, targetKey) if err != nil { return nil, nil, err diff --git a/frontend/rpm/handle_sources.go b/frontend/rpm/handle_sources.go index 22b4fd64b..6449354a2 100644 --- a/frontend/rpm/handle_sources.go +++ b/frontend/rpm/handle_sources.go @@ -25,6 +25,8 @@ func HandleSources(wf WorkerFunc) gwclient.BuildFunc { return nil, nil, err } + // Note, we are not passing platform down here because everything should + // be able to work regardless of platform, so prefer the native platform. sources, err := Dalec2SourcesLLB(worker, spec, sOpt) if err != nil { return nil, nil, err