Skip to content

Commit

Permalink
Use native platform to fetch sources, generate buildroot, etc
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
cpuguy83 committed Jul 18, 2024
1 parent c217cf1 commit 1dcd0fd
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion frontend/azlinux/handle_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/azlinux/handle_depsonly.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
9 changes: 7 additions & 2 deletions frontend/azlinux/handle_rpm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions frontend/rpm/handle_buildroot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions frontend/rpm/handle_sources.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1dcd0fd

Please sign in to comment.