Skip to content

Commit

Permalink
Support build android and ios executables (#212)
Browse files Browse the repository at this point in the history
Mobile build with test

Change to ubuntu + mac

Fix build.py

Fix android build

Cleanup the appveyor.yml
  • Loading branch information
NyaMisty authored Feb 22, 2020
1 parent adccb00 commit f57e9a9
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 26 deletions.
69 changes: 49 additions & 20 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,59 @@
# appveyor.yml
image: Ubuntu
image:
- Ubuntu
- macOS

clone_folder: /usr/go/src/github.com/shawn1m/overture
stack: go 1.13

for:
-
matrix:
only:
- image: macOS

environment:
GOPATH: /tmp/
clone_folder: /tmp/go/src/github.com/shawn1m/overture
before_build:
- "echo Building from macOS"
- "go env"
- "ls -al"
- "python3 ./build.py -create-sample"
- "python3 ./build.py -build-ios"

-
matrix:
only:
- image: Ubuntu

init:
#- sh: curl -sflL 'https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-ssh.sh' | bash -e -
environment:
APPVEYOR_SSH_KEY: ""
GOPATH: /usr/go/
ANDROID_NDK_ROOT: /tmp/android-ndk-r16b
clone_folder: /usr/go/src/github.com/shawn1m/overture
before_build:
- "wget https://dl.google.com/android/repository/android-ndk-r16b-linux-x86_64.zip -O /tmp/android-ndk.zip"
- "unzip -q /tmp/android-ndk.zip -d /tmp"
- "python $ANDROID_NDK_ROOT/build/tools/make_standalone_toolchain.py --api=16 --install-dir=$ANDROID_NDK_ROOT/bin/arm-linux-androideabi/ --arch=arm"
- "python $ANDROID_NDK_ROOT/build/tools/make_standalone_toolchain.py --api=21 --install-dir=$ANDROID_NDK_ROOT/bin/aarch64-linux-android/ --arch=arm64"
- "python $ANDROID_NDK_ROOT/build/tools/make_standalone_toolchain.py --api=16 --install-dir=$ANDROID_NDK_ROOT/bin/i686-linux-android/ --arch=x86"
- "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"
- "python3 ./build.py -create-sample"
- "python3 ./build.py -build-android"
- "python3 ./build.py -build"
on_finish:
#- sh: export APPVEYOR_SSH_BLOCK=true
#- sh: curl -sflL 'https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-ssh.sh' | bash -e -

branches:
only:
- master

skip_tags: true

skip_branch_with_pr: true

environment:
GOPATH: /usr/go/

stack: go 1.13

before_build:
- "python3 ./build.py -create-sample"
- "python3 ./build.py -build"

before_test:
- go vet ./...
#skip_tags: true

test_script:
- go test ./...
#skip_branch_with_pr: true

artifacts:
- path: 'overture-*.zip'
- path: 'overture-*.zip'
42 changes: 36 additions & 6 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,41 @@
["windows", "amd64"]
]

GO_IOS_ARCH_LIST = [
["darwin", "arm64"],
["darwin", "arm"]
]

def go_build_zip():
GO_ANDROID_ARCH_LIST = [
["android", "arm", "arm-linux-androideabi"],
["android", "arm64", "aarch64-linux-android"],
["android", "386", "i686-linux-android"],
["android", "amd64", "x86_64-linux-android"],
]


def go_build_desktop(binary_name, version, o, a, p):
mipsflag = (" GOMIPS=" + (p[0] if p else "") if p else "")
subprocess.check_call("GOOS=" + o + " GOARCH=" + a + mipsflag + " CGO_ENABLED=0" + " go build -ldflags \"-s -w " +
"-X main.version=" + version + "\" -o " + binary_name + " main/main.go", shell=True)

def go_build_ios(binary_name, version, o, a, p):
subprocess.check_call("CC=$(go env GOROOT)/misc/ios/clangwrap.sh GOOS=" + o + " GOARCH=" + a + " CGO_ENABLED=1" + " go build -ldflags \"-s -w " +
"-X main.version=" + version + "\" -o " + binary_name + " main/main.go", shell=True)

def go_build_android(binary_name, version, o, a, p):
triple = p[0]
subprocess.check_call("CC=$ANDROID_NDK_ROOT/bin/" + triple + "/bin/clang GOOS=" + o + " GOARCH=" + a + " CGO_ENABLED=1" + " go build -ldflags \"-s -w " +
"-X main.version=" + version + "\" -o " + binary_name + " main/main.go", shell=True)

def go_build_zip(arches, builder):
subprocess.check_call("GOOS=windows go get -v github.com/shawn1m/overture/main", shell=True)
for o, a, *p in GO_OS_ARCH_LIST:
for o, a, *p in arches:
zip_name = "overture-" + o + "-" + a + ("-" + (p[0] if p else "") if p else "")
binary_name = zip_name + (".exe" if o == "windows" else "")
version = subprocess.check_output("git describe --tags", shell=True).decode()
mipsflag = (" GOMIPS=" + (p[0] if p else "") if p else "")
try:
subprocess.check_call("GOOS=" + o + " GOARCH=" + a + mipsflag + " CGO_ENABLED=0" + " go build -ldflags \"-s -w " +
"-X main.version=" + version + "\" -o " + binary_name + " main/main.go", shell=True)
builder(binary_name, version, o, a, p)
subprocess.check_call("zip " + zip_name + ".zip " + binary_name + " " + "hosts_sample "
"ip_network_primary_sample "
"ip_network_alternative_sample "
Expand Down Expand Up @@ -66,4 +90,10 @@ def create_sample_file():
create_sample_file()

if "-build" in sys.argv:
go_build_zip()
go_build_zip(GO_OS_ARCH_LIST, go_build_desktop)

if "-build-ios" in sys.argv:
go_build_zip(GO_IOS_ARCH_LIST, go_build_ios)

if "-build-android" in sys.argv:
go_build_zip(GO_ANDROID_ARCH_LIST, go_build_android)

0 comments on commit f57e9a9

Please sign in to comment.