@@ -31,10 +31,10 @@ const (
31
31
var (
32
32
// Platforms are the supported platforms this build process supports.
33
33
Platforms = [... ]Platform {
34
- {"darwin" , "amd64" },
35
- {"linux" , "amd64" },
36
- {"linux" , "arm64" },
37
- {"windows" , "amd64" },
34
+ {"darwin" , "amd64" , "" },
35
+ {"linux" , "amd64" , "" },
36
+ {"linux" , "arm64" , "noasm" },
37
+ {"windows" , "amd64" , "" },
38
38
}
39
39
// Date is the date.
40
40
Date = time .Now ().Format ("2006-01-02T15:04:05-0700" )
56
56
57
57
// Platform represents a golang OS and ARCH build target.
58
58
type Platform struct {
59
- os , arch string
59
+ os , arch , tags string
60
60
}
61
61
62
62
func init () {
@@ -90,6 +90,24 @@ func init() {
90
90
}
91
91
}
92
92
93
+ func GetCurrentPlatform () (Platform , error ) {
94
+ os := TargetOS
95
+ arch := TargetArch
96
+ if os == "" {
97
+ os = runtime .GOOS
98
+ }
99
+ if arch == "" {
100
+ arch = runtime .GOARCH
101
+ }
102
+ for _ , platform := range Platforms {
103
+ if platform .os == os && platform .arch == arch {
104
+ return platform , nil
105
+ }
106
+ }
107
+
108
+ return Platform {}, errors .New ("platform not found" )
109
+ }
110
+
93
111
// Step is a function that represents a step in the build process.
94
112
type Step func () error
95
113
@@ -264,9 +282,13 @@ func build() error {
264
282
func buildgateway () error {
265
283
Print ("building gateway executable..." )
266
284
267
- err := Exec (Go , "install" , "-ldflags" ,
268
- Ldflags (),
269
- fmt .Sprintf ("%s/cmd/mashling-gateway" , ImportPath ))
285
+ arg := []string {"install" }
286
+ platform , err := GetCurrentPlatform ()
287
+ if err == nil && platform .tags != "" {
288
+ arg = append (arg , "-tags" , platform .tags )
289
+ }
290
+ arg = append (arg , "-ldflags" , Ldflags (), fmt .Sprintf ("%s/cmd/mashling-gateway" , ImportPath ))
291
+ err = Exec (Go , arg ... )
270
292
if err != nil {
271
293
return err
272
294
}
@@ -277,9 +299,13 @@ func buildgateway() error {
277
299
func buildcli () error {
278
300
Print ("building CLI executable..." )
279
301
280
- err := Exec (Go , "install" , "-ldflags" ,
281
- Ldflags (),
282
- fmt .Sprintf ("%s/cmd/mashling-cli" , ImportPath ))
302
+ arg := []string {"install" }
303
+ platform , err := GetCurrentPlatform ()
304
+ if err == nil && platform .tags != "" {
305
+ arg = append (arg , "-tags" , platform .tags )
306
+ }
307
+ arg = append (arg , "-ldflags" , Ldflags (), fmt .Sprintf ("%s/cmd/mashling-cli" , ImportPath ))
308
+ err = Exec (Go , arg ... )
283
309
if err != nil {
284
310
return err
285
311
}
@@ -331,11 +357,11 @@ func releaseall() error {
331
357
Print ("building release executables" )
332
358
333
359
for _ , platform := range Platforms {
334
- gateway , err := releaseGatewayWithTarget (platform .os , platform .arch )
360
+ gateway , err := releaseGatewayWithTarget (platform .os , platform .arch , platform . tags )
335
361
if err != nil {
336
362
return err
337
363
}
338
- cli , cErr := releaseCLIWithTarget (platform .os , platform .arch )
364
+ cli , cErr := releaseCLIWithTarget (platform .os , platform .arch , platform . tags )
339
365
if cErr != nil {
340
366
return cErr
341
367
}
@@ -356,15 +382,11 @@ func releasegateway() error {
356
382
Resolve (upx )
357
383
358
384
Print ("building gateway release executable" )
359
- os := TargetOS
360
- arch := TargetArch
361
- if os == "" {
362
- os = runtime .GOOS
363
- }
364
- if arch == "" {
365
- arch = runtime .GOARCH
385
+ platform , err := GetCurrentPlatform ()
386
+ if err != nil {
387
+ return err
366
388
}
367
- gateway , err := releaseGatewayWithTarget (os , arch )
389
+ gateway , err := releaseGatewayWithTarget (platform . os , platform . arch , platform . tags )
368
390
if err != nil {
369
391
return err
370
392
}
@@ -383,15 +405,11 @@ func releasecli() error {
383
405
Resolve (upx )
384
406
385
407
Print ("building CLI release executable" )
386
- os := TargetOS
387
- arch := TargetArch
388
- if os == "" {
389
- os = runtime .GOOS
390
- }
391
- if arch == "" {
392
- arch = runtime .GOARCH
408
+ platform , err := GetCurrentPlatform ()
409
+ if err != nil {
410
+ return err
393
411
}
394
- cli , err := releaseCLIWithTarget (os , arch )
412
+ cli , err := releaseCLIWithTarget (platform . os , platform . arch , platform . tags )
395
413
if err != nil {
396
414
return err
397
415
}
@@ -405,13 +423,13 @@ func releasecli() error {
405
423
return nil
406
424
}
407
425
408
- func releaseGatewayWithTarget (os string , arch string ) (string , error ) {
426
+ func releaseGatewayWithTarget (os string , arch string , tags string ) (string , error ) {
409
427
var extension string
410
428
if os == "windows" {
411
429
extension = ".exe"
412
430
}
413
431
gateway := fmt .Sprintf ("release/mashling-gateway-%s-%s%s" , os , arch , extension )
414
- cmd := exec .Command (Go , "build" , "-tags" , "release noasm" ,
432
+ cmd := exec .Command (Go , "build" , "-tags" , "release " + tags ,
415
433
"-ldflags" , ReleaseLdflags (),
416
434
"-o" , gateway ,
417
435
fmt .Sprintf ("%s/cmd/mashling-gateway" , ImportPath ))
@@ -425,13 +443,13 @@ func releaseGatewayWithTarget(os string, arch string) (string, error) {
425
443
return gateway , nil
426
444
}
427
445
428
- func releaseCLIWithTarget (os string , arch string ) (string , error ) {
446
+ func releaseCLIWithTarget (os string , arch string , tags string ) (string , error ) {
429
447
var extension string
430
448
if os == "windows" {
431
449
extension = ".exe"
432
450
}
433
451
cli := fmt .Sprintf ("release/mashling-cli-%s-%s%s" , os , arch , extension )
434
- cmd := exec .Command (Go , "build" , "-tags" , "release noasm" ,
452
+ cmd := exec .Command (Go , "build" , "-tags" , "release " + tags ,
435
453
"-ldflags" , ReleaseLdflags (),
436
454
"-o" , cli ,
437
455
fmt .Sprintf ("%s/cmd/mashling-cli" , ImportPath ))
0 commit comments