Skip to content

Commit d974233

Browse files
authored
Merge pull request #228 from TIBCOSoftware/chore-arm-noasm
Only use noasm with arm
2 parents c53f768 + 70079e5 commit d974233

File tree

1 file changed

+51
-33
lines changed

1 file changed

+51
-33
lines changed

build.go

+51-33
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ const (
3131
var (
3232
// Platforms are the supported platforms this build process supports.
3333
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", ""},
3838
}
3939
// Date is the date.
4040
Date = time.Now().Format("2006-01-02T15:04:05-0700")
@@ -56,7 +56,7 @@ var (
5656

5757
// Platform represents a golang OS and ARCH build target.
5858
type Platform struct {
59-
os, arch string
59+
os, arch, tags string
6060
}
6161

6262
func init() {
@@ -90,6 +90,24 @@ func init() {
9090
}
9191
}
9292

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+
93111
// Step is a function that represents a step in the build process.
94112
type Step func() error
95113

@@ -264,9 +282,13 @@ func build() error {
264282
func buildgateway() error {
265283
Print("building gateway executable...")
266284

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...)
270292
if err != nil {
271293
return err
272294
}
@@ -277,9 +299,13 @@ func buildgateway() error {
277299
func buildcli() error {
278300
Print("building CLI executable...")
279301

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...)
283309
if err != nil {
284310
return err
285311
}
@@ -331,11 +357,11 @@ func releaseall() error {
331357
Print("building release executables")
332358

333359
for _, platform := range Platforms {
334-
gateway, err := releaseGatewayWithTarget(platform.os, platform.arch)
360+
gateway, err := releaseGatewayWithTarget(platform.os, platform.arch, platform.tags)
335361
if err != nil {
336362
return err
337363
}
338-
cli, cErr := releaseCLIWithTarget(platform.os, platform.arch)
364+
cli, cErr := releaseCLIWithTarget(platform.os, platform.arch, platform.tags)
339365
if cErr != nil {
340366
return cErr
341367
}
@@ -356,15 +382,11 @@ func releasegateway() error {
356382
Resolve(upx)
357383

358384
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
366388
}
367-
gateway, err := releaseGatewayWithTarget(os, arch)
389+
gateway, err := releaseGatewayWithTarget(platform.os, platform.arch, platform.tags)
368390
if err != nil {
369391
return err
370392
}
@@ -383,15 +405,11 @@ func releasecli() error {
383405
Resolve(upx)
384406

385407
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
393411
}
394-
cli, err := releaseCLIWithTarget(os, arch)
412+
cli, err := releaseCLIWithTarget(platform.os, platform.arch, platform.tags)
395413
if err != nil {
396414
return err
397415
}
@@ -405,13 +423,13 @@ func releasecli() error {
405423
return nil
406424
}
407425

408-
func releaseGatewayWithTarget(os string, arch string) (string, error) {
426+
func releaseGatewayWithTarget(os string, arch string, tags string) (string, error) {
409427
var extension string
410428
if os == "windows" {
411429
extension = ".exe"
412430
}
413431
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,
415433
"-ldflags", ReleaseLdflags(),
416434
"-o", gateway,
417435
fmt.Sprintf("%s/cmd/mashling-gateway", ImportPath))
@@ -425,13 +443,13 @@ func releaseGatewayWithTarget(os string, arch string) (string, error) {
425443
return gateway, nil
426444
}
427445

428-
func releaseCLIWithTarget(os string, arch string) (string, error) {
446+
func releaseCLIWithTarget(os string, arch string, tags string) (string, error) {
429447
var extension string
430448
if os == "windows" {
431449
extension = ".exe"
432450
}
433451
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,
435453
"-ldflags", ReleaseLdflags(),
436454
"-o", cli,
437455
fmt.Sprintf("%s/cmd/mashling-cli", ImportPath))

0 commit comments

Comments
 (0)