Skip to content

Commit 8c23f20

Browse files
committed
Makefile, build: move cross compilation into ci.go
1 parent 4f65227 commit 8c23f20

File tree

3 files changed

+57
-50
lines changed

3 files changed

+57
-50
lines changed

Makefile

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# with Go source code. If you know what GOPATH is then you probably
33
# don't need to bother with make.
44

5-
.PHONY: geth geth-cross evm all test xgo clean
5+
.PHONY: geth geth-cross evm all test clean
66
.PHONY: geth-linux geth-linux-386 geth-linux-amd64
77
.PHONY: geth-linux-arm geth-linux-arm-5 geth-linux-arm-6 geth-linux-arm-7 geth-linux-arm64
88
.PHONY: geth-darwin geth-darwin-386 geth-darwin-amd64
@@ -33,9 +33,6 @@ clean:
3333

3434
# Cross Compilation Targets (xgo)
3535

36-
xgo:
37-
build/env.sh go get github.com/karalabe/xgo
38-
3936
geth-cross: geth-linux geth-darwin geth-windows geth-android geth-ios
4037
@echo "Full cross compilation done:"
4138
@ls -ld $(GOBIN)/geth-*
@@ -44,74 +41,74 @@ geth-linux: geth-linux-386 geth-linux-amd64 geth-linux-arm
4441
@echo "Linux cross compilation done:"
4542
@ls -ld $(GOBIN)/geth-linux-*
4643

47-
geth-linux-386: xgo
48-
build/env.sh $(GOBIN)/xgo --go=$(GO) --dest=$(GOBIN) --targets=linux/386 -v $(shell build/flags.sh) ./cmd/geth
44+
geth-linux-386:
45+
build/env.sh go run build/ci.go xgo --go=$(GO) --dest=$(GOBIN) --targets=linux/386 -v ./cmd/geth
4946
@echo "Linux 386 cross compilation done:"
5047
@ls -ld $(GOBIN)/geth-linux-* | grep 386
5148

52-
geth-linux-amd64: xgo
53-
build/env.sh $(GOBIN)/xgo --go=$(GO) --dest=$(GOBIN) --targets=linux/amd64 -v $(shell build/flags.sh) ./cmd/geth
49+
geth-linux-amd64:
50+
build/env.sh go run build/ci.go xgo --go=$(GO) --dest=$(GOBIN) --targets=linux/amd64 -v ./cmd/geth
5451
@echo "Linux amd64 cross compilation done:"
5552
@ls -ld $(GOBIN)/geth-linux-* | grep amd64
5653

5754
geth-linux-arm: geth-linux-arm-5 geth-linux-arm-6 geth-linux-arm-7 geth-linux-arm64
5855
@echo "Linux ARM cross compilation done:"
5956
@ls -ld $(GOBIN)/geth-linux-* | grep arm
6057

61-
geth-linux-arm-5: xgo
62-
build/env.sh $(GOBIN)/xgo --go=$(GO) --dest=$(GOBIN) --targets=linux/arm-5 -v $(shell build/flags.sh) ./cmd/geth
58+
geth-linux-arm-5:
59+
build/env.sh go run build/ci.go xgo --go=$(GO) --dest=$(GOBIN) --targets=linux/arm-5 -v ./cmd/geth
6360
@echo "Linux ARMv5 cross compilation done:"
6461
@ls -ld $(GOBIN)/geth-linux-* | grep arm-5
6562

66-
geth-linux-arm-6: xgo
67-
build/env.sh $(GOBIN)/xgo --go=$(GO) --dest=$(GOBIN) --targets=linux/arm-6 -v $(shell build/flags.sh) ./cmd/geth
63+
geth-linux-arm-6:
64+
build/env.sh go run build/ci.go xgo --go=$(GO) --dest=$(GOBIN) --targets=linux/arm-6 -v ./cmd/geth
6865
@echo "Linux ARMv6 cross compilation done:"
6966
@ls -ld $(GOBIN)/geth-linux-* | grep arm-6
7067

71-
geth-linux-arm-7: xgo
72-
build/env.sh $(GOBIN)/xgo --go=$(GO) --dest=$(GOBIN) --targets=linux/arm-7 -v $(shell build/flags.sh) ./cmd/geth
68+
geth-linux-arm-7:
69+
build/env.sh go run build/ci.go xgo --go=$(GO) --dest=$(GOBIN) --targets=linux/arm-7 -v ./cmd/geth
7370
@echo "Linux ARMv7 cross compilation done:"
7471
@ls -ld $(GOBIN)/geth-linux-* | grep arm-7
7572

76-
geth-linux-arm64: xgo
77-
build/env.sh $(GOBIN)/xgo --go=$(GO) --dest=$(GOBIN) --targets=linux/arm64 -v $(shell build/flags.sh) ./cmd/geth
73+
geth-linux-arm64:
74+
build/env.sh go run build/ci.go xgo --go=$(GO) --dest=$(GOBIN) --targets=linux/arm64 -v ./cmd/geth
7875
@echo "Linux ARM64 cross compilation done:"
7976
@ls -ld $(GOBIN)/geth-linux-* | grep arm64
8077

8178
geth-darwin: geth-darwin-386 geth-darwin-amd64
8279
@echo "Darwin cross compilation done:"
8380
@ls -ld $(GOBIN)/geth-darwin-*
8481

85-
geth-darwin-386: xgo
86-
build/env.sh $(GOBIN)/xgo --go=$(GO) --dest=$(GOBIN) --targets=darwin/386 -v $(shell build/flags.sh) ./cmd/geth
82+
geth-darwin-386:
83+
build/env.sh go run build/ci.go xgo --go=$(GO) --dest=$(GOBIN) --targets=darwin/386 -v ./cmd/geth
8784
@echo "Darwin 386 cross compilation done:"
8885
@ls -ld $(GOBIN)/geth-darwin-* | grep 386
8986

90-
geth-darwin-amd64: xgo
91-
build/env.sh $(GOBIN)/xgo --go=$(GO) --dest=$(GOBIN) --targets=darwin/amd64 -v $(shell build/flags.sh) ./cmd/geth
87+
geth-darwin-amd64:
88+
build/env.sh go run build/ci.go xgo --go=$(GO) --dest=$(GOBIN) --targets=darwin/amd64 -v ./cmd/geth
9289
@echo "Darwin amd64 cross compilation done:"
9390
@ls -ld $(GOBIN)/geth-darwin-* | grep amd64
9491

9592
geth-windows: geth-windows-386 geth-windows-amd64
9693
@echo "Windows cross compilation done:"
9794
@ls -ld $(GOBIN)/geth-windows-*
9895

99-
geth-windows-386: xgo
100-
build/env.sh $(GOBIN)/xgo --go=$(GO) --dest=$(GOBIN) --targets=windows/386 -v $(shell build/flags.sh) ./cmd/geth
96+
geth-windows-386:
97+
build/env.sh go run build/ci.go xgo --go=$(GO) --dest=$(GOBIN) --targets=windows/386 -v ./cmd/geth
10198
@echo "Windows 386 cross compilation done:"
10299
@ls -ld $(GOBIN)/geth-windows-* | grep 386
103100

104-
geth-windows-amd64: xgo
105-
build/env.sh $(GOBIN)/xgo --go=$(GO) --dest=$(GOBIN) --targets=windows/amd64 -v $(shell build/flags.sh) ./cmd/geth
101+
geth-windows-amd64:
102+
build/env.sh go run build/ci.go xgo --go=$(GO) --dest=$(GOBIN) --targets=windows/amd64 -v ./cmd/geth
106103
@echo "Windows amd64 cross compilation done:"
107104
@ls -ld $(GOBIN)/geth-windows-* | grep amd64
108105

109-
geth-android: xgo
110-
build/env.sh $(GOBIN)/xgo --go=$(GO) --dest=$(GOBIN) --targets=android-21/aar -v $(shell build/flags.sh) ./cmd/geth
106+
geth-android:
107+
build/env.sh go run build/ci.go xgo --go=$(GO) --dest=$(GOBIN) --targets=android-21/aar -v ./cmd/geth
111108
@echo "Android cross compilation done:"
112109
@ls -ld $(GOBIN)/geth-android-*
113110

114-
geth-ios: xgo
115-
build/env.sh $(GOBIN)/xgo --go=$(GO) --dest=$(GOBIN) --targets=ios-7.0/framework -v $(shell build/flags.sh) ./cmd/geth
111+
geth-ios:
112+
build/env.sh go run build/ci.go xgo --go=$(GO) --dest=$(GOBIN) --targets=ios-7.0/framework -v ./cmd/geth
116113
@echo "iOS framework cross compilation done:"
117114
@ls -ld $(GOBIN)/geth-ios-*

build/ci.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Available commands are:
2828
archive [ -type zip|tar ] -- archives build artefacts
2929
importkeys -- imports signing keys from env
3030
debsrc [ -sign key-id ] [ -upload dest ] -- creates a debian source package
31+
xgo [ options ] -- cross builds according to options
3132
3233
For all commands, -n prevents execution of external programs (dry run mode).
3334
@@ -121,6 +122,8 @@ func main() {
121122
doDebianSource(os.Args[2:])
122123
case "travis-debsrc":
123124
doTravisDebianSource(os.Args[2:])
125+
case "xgo":
126+
doXgo(os.Args[2:])
124127
default:
125128
log.Fatal("unknown command ", os.Args[1])
126129
}
@@ -463,3 +466,32 @@ func stageDebianSource(tmpdir string, meta debMetadata) (pkgdir string) {
463466

464467
return pkgdir
465468
}
469+
470+
// Cross compilation
471+
472+
func doXgo(cmdline []string) {
473+
// Make sure xgo is available for cross compilation
474+
gogetxgo := goTool("get", "github.com/karalabe/xgo")
475+
build.MustRun(gogetxgo)
476+
477+
// Execute the actual cross compilation
478+
pkg := cmdline[len(cmdline)-1]
479+
args := append(cmdline[:len(cmdline)-1], makeBuildFlags("")...)
480+
481+
build.MustRun(xgoTool(append(args, pkg)...))
482+
}
483+
484+
func xgoTool(args ...string) *exec.Cmd {
485+
cmd := exec.Command(filepath.Join(GOBIN, "xgo"), args...)
486+
cmd.Env = []string{
487+
"GOPATH=" + build.GOPATH(),
488+
"GOBIN=" + GOBIN,
489+
}
490+
for _, e := range os.Environ() {
491+
if strings.HasPrefix(e, "GOPATH=") || strings.HasPrefix(e, "GOBIN=") {
492+
continue
493+
}
494+
cmd.Env = append(cmd.Env, e)
495+
}
496+
return cmd
497+
}

build/flags.sh

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)