@@ -56,13 +56,31 @@ func handleRPM(w worker) gwclient.BuildFunc {
56
56
}
57
57
}
58
58
59
- type installFunc func (dalec.SourceOpts ) (llb.RunOption , error )
59
+ func platformFuzzyMatches (p * ocispecs.Platform ) bool {
60
+ if p == nil {
61
+ return true
62
+ }
63
+
64
+ // Note, this is intentionally not doing a strict match here
65
+ // (e.g. [platforms.OnlyStrict])
66
+ // This is used to see if we can get some optimizations when building for a
67
+ // non-native platformm and in most cases the [platforms.Only] vector handles
68
+ // things like building armv7 on an arm64 machine, which should be able to run
69
+ // natively.
70
+ return platforms .Only (platforms .DefaultSpec ()).Match (* p )
71
+ }
72
+
73
+ func installBuildDeps (w worker , sOpt dalec.SourceOpts , spec * dalec.Spec , targetKey string , platform * ocispecs.Platform , opts ... llb.ConstraintsOpt ) (llb.StateOption , error ) {
74
+ deps := spec .GetBuildDeps (targetKey )
75
+ if len (deps ) == 0 {
76
+ return func (in llb.State ) llb.State { return in }, nil
77
+ }
78
+
79
+ opts = append (opts , dalec .ProgressGroup ("Install build deps" ))
60
80
61
- // Creates and installs an rpm meta-package that requires the passed in deps as runtime-dependencies
62
- func installBuildDepsPackage (target string , packageName string , w worker , sOpt dalec.SourceOpts , deps map [string ]dalec.PackageConstraints , platform * ocispecs.Platform , installOpts ... installOpt ) installFunc {
63
81
// depsOnly is a simple dalec spec that only includes build dependencies and their constraints
64
82
depsOnly := dalec.Spec {
65
- Name : fmt . Sprintf ( "%s -build-dependencies", packageName ) ,
83
+ Name : spec . Name + " -build-dependencies" ,
66
84
Description : "Provides build dependencies for mariner2 and azlinux3" ,
67
85
Version : "1.0" ,
68
86
License : "Apache 2.0" ,
@@ -72,46 +90,42 @@ func installBuildDepsPackage(target string, packageName string, w worker, sOpt d
72
90
},
73
91
}
74
92
75
- return func (Opt dalec.SourceOpts ) (llb.RunOption , error ) {
76
- pg := dalec .ProgressGroup ("Building container for build dependencies" )
93
+ // create an RPM with just the build dependencies, using our same base worker
94
+ rpmDir , err := createRPM (w , sOpt , & depsOnly , targetKey , platform , opts ... )
95
+ if err != nil {
96
+ return nil , err
97
+ }
98
+
99
+ rpmMountDir := "/tmp/rpms"
100
+ pkg := []string {"/tmp/rpms/*/*.rpm" }
77
101
78
- // create an RPM with just the build dependencies, using our same base worker
79
- rpmDir , err := createRPM ( w , sOpt , & depsOnly , target , platform , pg )
102
+ if ! platformFuzzyMatches ( platform ) {
103
+ base , err := w . Base ( sOpt , opts ... )
80
104
if err != nil {
81
105
return nil , err
82
106
}
83
107
84
- var opts []llb.ConstraintsOpt
85
- opts = append (opts , dalec .ProgressGroup ("Install build deps" ))
86
-
87
- rpmMountDir := "/tmp/rpms"
88
-
89
- installOpts = append ([]installOpt {
90
- noGPGCheck ,
91
- withMounts (llb .AddMount (rpmMountDir , rpmDir , llb .SourcePath ("/RPMS" ))),
92
- installWithConstraints (opts ),
93
- }, installOpts ... )
94
-
95
- // install the built RPMs into the worker itself
96
- return w .Install ([]string {"/tmp/rpms/*/*.rpm" }, installOpts ... ), nil
97
- }
98
- }
99
-
100
- func installBuildDeps (w worker , sOpt dalec.SourceOpts , spec * dalec.Spec , targetKey string , platform * ocispecs.Platform , opts ... llb.ConstraintsOpt ) (llb.StateOption , error ) {
101
- deps := spec .GetBuildDeps (targetKey )
102
- if len (deps ) == 0 {
103
- return func (in llb.State ) llb.State { return in }, nil
104
- }
105
-
106
- opts = append (opts , dalec .ProgressGroup ("Install build deps" ))
107
-
108
- installOpt , err := installBuildDepsPackage (targetKey , spec .Name , w , sOpt , deps , platform , installWithConstraints (opts ))(sOpt )
109
- if err != nil {
110
- return nil , err
108
+ return func (in llb.State ) llb.State {
109
+ return base .Run (
110
+ w .Install (
111
+ pkg ,
112
+ withMounts (llb .AddMount (rpmMountDir , rpmDir , llb .SourcePath ("/RPMS" ))),
113
+ atRoot ("/tmp/rootfs" ),
114
+ withPlatform (platform ),
115
+ ),
116
+ ).AddMount ("/tmp/rootfs" , in )
117
+ }, nil
111
118
}
112
119
113
120
return func (in llb.State ) llb.State {
114
- return in .Run (installOpt , dalec .WithConstraints (opts ... )).Root ()
121
+ return in .Run (
122
+ w .Install (
123
+ []string {"/tmp/rpms/*/*.rpm" },
124
+ withMounts (llb .AddMount (rpmMountDir , rpmDir , llb .SourcePath ("/RPMS" ))),
125
+ installWithConstraints (opts ),
126
+ ),
127
+ dalec .WithConstraints (opts ... ),
128
+ ).Root ()
115
129
}, nil
116
130
}
117
131
@@ -233,15 +247,13 @@ func createRPM(w worker, sOpt dalec.SourceOpts, spec *dalec.Spec, targetKey stri
233
247
}
234
248
235
249
var runOpts []llb.RunOption
236
- if platform != nil {
237
- if platforms .Only (platforms .DefaultSpec ()).Match (* platform ) && hasGolangBuildDep (spec , targetKey ) {
238
- native , err := rpmWorker (w , sOpt , spec , targetKey , nil , opts ... )
239
- if err != nil {
240
- return llb .Scratch (), err
241
- }
242
-
243
- runOpts = append (runOpts , nativeGoMount (native , platform ))
250
+ if ! platformFuzzyMatches (platform ) && hasGolangBuildDep (spec , targetKey ) {
251
+ native , err := rpmWorker (w , sOpt , spec , targetKey , nil , opts ... )
252
+ if err != nil {
253
+ return llb .Scratch (), err
244
254
}
255
+
256
+ runOpts = append (runOpts , nativeGoMount (native , platform ))
245
257
}
246
258
247
259
specPath := filepath .Join ("SPECS" , spec .Name , spec .Name + ".spec" )
0 commit comments