From f57e9a9d21d991a8b5823ce73007e1bad7a55af4 Mon Sep 17 00:00:00 2001 From: NyaMisty Date: Sat, 22 Feb 2020 19:25:54 +0800 Subject: [PATCH] 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 --- appveyor.yml | 69 +++++++++++++++++++++++++++++++++++++--------------- build.py | 42 +++++++++++++++++++++++++++----- 2 files changed, 85 insertions(+), 26 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 46f7302..eac0236 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -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' \ No newline at end of file + - path: 'overture-*.zip' diff --git a/build.py b/build.py index 88faff3..6aca092 100755 --- a/build.py +++ b/build.py @@ -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 " @@ -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)