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 25, 2024
1 parent 3f0d0ec commit f1ce1c0
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 8 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 @@ -36,7 +36,7 @@ func handleDepsOnly(w worker) gwclient.BuildFunc {
return nil, nil, err
}

st, err := specToContainerLLB(w, spec, targetKey, rpmDir, files, sOpt, pg)
st, err := specToContainerLLB(w, spec, targetKey, rpmDir, files, sOpt, pg, dalec.WithPlatform(platform))
if err != nil {
return nil, nil, err
}
Expand Down
20 changes: 14 additions & 6 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,18 +64,26 @@ 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) {
base, err := w.Base(sOpt, opts...)
base = base.With(installBuildDeps(w, spec, targetKey, opts...))
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
native, err := w.Base(sOpt, opts...)
if err != nil {
return llb.Scratch(), err
}

br, err := rpm.SpecToBuildrootLLB(base, spec, sOpt, targetKey, opts...)
native = native.With(installBuildDeps(w, spec, targetKey, opts...))
br, err := rpm.SpecToBuildrootLLB(native, 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, err := w.Base(sOpt, opts...)
if err != nil {
return llb.Scratch(), err
}
base = base.With(installBuildDeps(w, spec, targetKey, opts...))
st := rpm.Build(br, base, specPath, opts...)

return frontend.MaybeSign(ctx, client, st, spec, targetKey, sOpt)
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 f1ce1c0

Please sign in to comment.