Skip to content

Commit 1dcd0fd

Browse files
committed
Use native platform to fetch sources, generate buildroot, etc
When building for a non-native platform (typically under qemu), use the native platform for most operations that do not need platform specific things, such as applying patches, tarring up sources, and fetching go module deps. Signed-off-by: Brian Goff <[email protected]>
1 parent c217cf1 commit 1dcd0fd

File tree

5 files changed

+13
-4
lines changed

5 files changed

+13
-4
lines changed

frontend/azlinux/handle_container.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func handleContainer(w worker) gwclient.BuildFunc {
2525

2626
pg := dalec.ProgressGroup("Building " + targetKey + " container: " + spec.Name)
2727

28-
rpmDir, err := specToRpmLLB(ctx, w, client, spec, sOpt, targetKey, pg, dalec.WithPlatform(platform))
28+
rpmDir, err := specToRpmLLB(ctx, w, client, spec, sOpt, targetKey, platform, pg)
2929
if err != nil {
3030
return nil, nil, fmt.Errorf("error creating rpm: %w", err)
3131
}

frontend/azlinux/handle_depsonly.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func handleDepsOnly(w worker) gwclient.BuildFunc {
3131
if err != nil {
3232
return nil, nil, err
3333
}
34-
st, err := specToContainerLLB(w, client, spec, targetKey, rpmDir, files, sOpt, pg)
34+
st, err := specToContainerLLB(w, client, spec, targetKey, rpmDir, files, sOpt, pg, dalec.WithPlatform(platform))
3535
if err != nil {
3636
return nil, nil, err
3737
}

frontend/azlinux/handle_rpm.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func handleRPM(w worker) gwclient.BuildFunc {
2626
return nil, nil, err
2727
}
2828

29-
st, err := specToRpmLLB(ctx, w, client, spec, sOpt, targetKey, pg, dalec.WithPlatform(platform))
29+
st, err := specToRpmLLB(ctx, w, client, spec, sOpt, targetKey, platform, pg)
3030
if err != nil {
3131
return nil, nil, err
3232
}
@@ -64,13 +64,18 @@ func installBuildDeps(w worker, spec *dalec.Spec, targetKey string, opts ...llb.
6464
}
6565
}
6666

67-
func specToRpmLLB(ctx context.Context, w worker, client gwclient.Client, spec *dalec.Spec, sOpt dalec.SourceOpts, targetKey string, opts ...llb.ConstraintsOpt) (llb.State, error) {
67+
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) {
68+
// Generate the buildroot with the native platform
6869
base := w.Base(client, opts...).With(installBuildDeps(w, spec, targetKey, opts...))
6970
br, err := rpm.SpecToBuildrootLLB(base, spec, sOpt, targetKey, opts...)
7071
if err != nil {
7172
return llb.Scratch(), err
7273
}
7374
specPath := filepath.Join("SPECS", spec.Name, spec.Name+".spec")
75+
76+
// Build the RPM with the target platform
77+
opts = append(opts, dalec.WithPlatform(platform))
78+
base = w.Base(client, opts...).With(installBuildDeps(w, spec, targetKey, opts...))
7479
st := rpm.Build(br, base, specPath, opts...)
7580

7681
return frontend.MaybeSign(ctx, client, st, spec, targetKey)

frontend/rpm/handle_buildroot.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ func HandleBuildroot(wf WorkerFunc) gwclient.BuildFunc {
2121
return nil, nil, err
2222
}
2323

24+
// Note, we are not passing platform down here because everything should
25+
// be able to work regardless of platform, so prefer the native platform.
2426
worker, err := wf(sOpt.Resolver, spec, targetKey)
2527
if err != nil {
2628
return nil, nil, err

frontend/rpm/handle_sources.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ func HandleSources(wf WorkerFunc) gwclient.BuildFunc {
2525
return nil, nil, err
2626
}
2727

28+
// Note, we are not passing platform down here because everything should
29+
// be able to work regardless of platform, so prefer the native platform.
2830
sources, err := Dalec2SourcesLLB(worker, spec, sOpt)
2931
if err != nil {
3032
return nil, nil, err

0 commit comments

Comments
 (0)