Skip to content

Commit f57e9a9

Browse files
authored
Support build android and ios executables (#212)
Mobile build with test Change to ubuntu + mac Fix build.py Fix android build Cleanup the appveyor.yml
1 parent adccb00 commit f57e9a9

File tree

2 files changed

+85
-26
lines changed

2 files changed

+85
-26
lines changed

appveyor.yml

+49-20
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,59 @@
11
# appveyor.yml
2-
image: Ubuntu
2+
image:
3+
- Ubuntu
4+
- macOS
35

4-
clone_folder: /usr/go/src/github.com/shawn1m/overture
6+
stack: go 1.13
7+
8+
for:
9+
-
10+
matrix:
11+
only:
12+
- image: macOS
13+
14+
environment:
15+
GOPATH: /tmp/
16+
clone_folder: /tmp/go/src/github.com/shawn1m/overture
17+
before_build:
18+
- "echo Building from macOS"
19+
- "go env"
20+
- "ls -al"
21+
- "python3 ./build.py -create-sample"
22+
- "python3 ./build.py -build-ios"
23+
24+
-
25+
matrix:
26+
only:
27+
- image: Ubuntu
28+
29+
init:
30+
#- sh: curl -sflL 'https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-ssh.sh' | bash -e -
31+
environment:
32+
APPVEYOR_SSH_KEY: ""
33+
GOPATH: /usr/go/
34+
ANDROID_NDK_ROOT: /tmp/android-ndk-r16b
35+
clone_folder: /usr/go/src/github.com/shawn1m/overture
36+
before_build:
37+
- "wget https://dl.google.com/android/repository/android-ndk-r16b-linux-x86_64.zip -O /tmp/android-ndk.zip"
38+
- "unzip -q /tmp/android-ndk.zip -d /tmp"
39+
- "python $ANDROID_NDK_ROOT/build/tools/make_standalone_toolchain.py --api=16 --install-dir=$ANDROID_NDK_ROOT/bin/arm-linux-androideabi/ --arch=arm"
40+
- "python $ANDROID_NDK_ROOT/build/tools/make_standalone_toolchain.py --api=21 --install-dir=$ANDROID_NDK_ROOT/bin/aarch64-linux-android/ --arch=arm64"
41+
- "python $ANDROID_NDK_ROOT/build/tools/make_standalone_toolchain.py --api=16 --install-dir=$ANDROID_NDK_ROOT/bin/i686-linux-android/ --arch=x86"
42+
- "python $ANDROID_NDK_ROOT/build/tools/make_standalone_toolchain.py --api=21 --install-dir=$ANDROID_NDK_ROOT/bin/x86_64-linux-android/ --arch=x86_64"
43+
- "python3 ./build.py -create-sample"
44+
- "python3 ./build.py -build-android"
45+
- "python3 ./build.py -build"
46+
on_finish:
47+
#- sh: export APPVEYOR_SSH_BLOCK=true
48+
#- sh: curl -sflL 'https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-ssh.sh' | bash -e -
549

650
branches:
751
only:
852
- master
953

10-
skip_tags: true
11-
12-
skip_branch_with_pr: true
13-
14-
environment:
15-
GOPATH: /usr/go/
16-
17-
stack: go 1.13
18-
19-
before_build:
20-
- "python3 ./build.py -create-sample"
21-
- "python3 ./build.py -build"
22-
23-
before_test:
24-
- go vet ./...
54+
#skip_tags: true
2555

26-
test_script:
27-
- go test ./...
56+
#skip_branch_with_pr: true
2857

2958
artifacts:
30-
- path: 'overture-*.zip'
59+
- path: 'overture-*.zip'

build.py

+36-6
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,41 @@
2121
["windows", "amd64"]
2222
]
2323

24+
GO_IOS_ARCH_LIST = [
25+
["darwin", "arm64"],
26+
["darwin", "arm"]
27+
]
2428

25-
def go_build_zip():
29+
GO_ANDROID_ARCH_LIST = [
30+
["android", "arm", "arm-linux-androideabi"],
31+
["android", "arm64", "aarch64-linux-android"],
32+
["android", "386", "i686-linux-android"],
33+
["android", "amd64", "x86_64-linux-android"],
34+
]
35+
36+
37+
def go_build_desktop(binary_name, version, o, a, p):
38+
mipsflag = (" GOMIPS=" + (p[0] if p else "") if p else "")
39+
subprocess.check_call("GOOS=" + o + " GOARCH=" + a + mipsflag + " CGO_ENABLED=0" + " go build -ldflags \"-s -w " +
40+
"-X main.version=" + version + "\" -o " + binary_name + " main/main.go", shell=True)
41+
42+
def go_build_ios(binary_name, version, o, a, p):
43+
subprocess.check_call("CC=$(go env GOROOT)/misc/ios/clangwrap.sh GOOS=" + o + " GOARCH=" + a + " CGO_ENABLED=1" + " go build -ldflags \"-s -w " +
44+
"-X main.version=" + version + "\" -o " + binary_name + " main/main.go", shell=True)
45+
46+
def go_build_android(binary_name, version, o, a, p):
47+
triple = p[0]
48+
subprocess.check_call("CC=$ANDROID_NDK_ROOT/bin/" + triple + "/bin/clang GOOS=" + o + " GOARCH=" + a + " CGO_ENABLED=1" + " go build -ldflags \"-s -w " +
49+
"-X main.version=" + version + "\" -o " + binary_name + " main/main.go", shell=True)
50+
51+
def go_build_zip(arches, builder):
2652
subprocess.check_call("GOOS=windows go get -v github.com/shawn1m/overture/main", shell=True)
27-
for o, a, *p in GO_OS_ARCH_LIST:
53+
for o, a, *p in arches:
2854
zip_name = "overture-" + o + "-" + a + ("-" + (p[0] if p else "") if p else "")
2955
binary_name = zip_name + (".exe" if o == "windows" else "")
3056
version = subprocess.check_output("git describe --tags", shell=True).decode()
31-
mipsflag = (" GOMIPS=" + (p[0] if p else "") if p else "")
3257
try:
33-
subprocess.check_call("GOOS=" + o + " GOARCH=" + a + mipsflag + " CGO_ENABLED=0" + " go build -ldflags \"-s -w " +
34-
"-X main.version=" + version + "\" -o " + binary_name + " main/main.go", shell=True)
58+
builder(binary_name, version, o, a, p)
3559
subprocess.check_call("zip " + zip_name + ".zip " + binary_name + " " + "hosts_sample "
3660
"ip_network_primary_sample "
3761
"ip_network_alternative_sample "
@@ -66,4 +90,10 @@ def create_sample_file():
6690
create_sample_file()
6791

6892
if "-build" in sys.argv:
69-
go_build_zip()
93+
go_build_zip(GO_OS_ARCH_LIST, go_build_desktop)
94+
95+
if "-build-ios" in sys.argv:
96+
go_build_zip(GO_IOS_ARCH_LIST, go_build_ios)
97+
98+
if "-build-android" in sys.argv:
99+
go_build_zip(GO_ANDROID_ARCH_LIST, go_build_android)

0 commit comments

Comments
 (0)