From f7bf0b8e7412ecb8d56749cff584adc90ab5ae21 Mon Sep 17 00:00:00 2001 From: Mygod Date: Fri, 18 Jan 2019 09:45:25 +0800 Subject: [PATCH] Migrate to go mod --- .circleci/config.yml | 6 ++++ .gitmodules | 6 ++-- app/.gitignore | 4 --- app/build.gradle | 6 ++-- app/go-build.bash | 30 +++++++++++++++++ app/src/clean.bash | 8 ----- app/src/main/go/v2ray-plugin | 1 + app/src/make.bash | 62 ------------------------------------ app/src/v2ray-plugin | 1 - 9 files changed, 43 insertions(+), 81 deletions(-) create mode 100644 app/go-build.bash delete mode 100755 app/src/clean.bash create mode 160000 app/src/main/go/v2ray-plugin delete mode 100755 app/src/make.bash delete mode 160000 app/src/v2ray-plugin diff --git a/.circleci/config.yml b/.circleci/config.yml index abdf814..9ea583b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -12,9 +12,15 @@ jobs: - run: git submodule update --init --recursive - restore_cache: key: jars-{{ checksum "build.gradle" }} + - restore_cache: + key: go - run: name: Run Build and Tests command: ./gradlew assembleDebug check + - save_cache: + paths: + - ~/go + key: go - save_cache: paths: - ~/.gradle diff --git a/.gitmodules b/.gitmodules index eaa4661..6af06a0 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ -[submodule "app/src/v2ray-plugin"] - path = app/src/v2ray-plugin - url = https://github.com/madeye/v2ray-plugin +[submodule "app/src/main/go/v2ray-plugin"] + path = app/src/main/go/v2ray-plugin + url = https://github.com/shadowsocks/v2ray-plugin.git diff --git a/app/.gitignore b/app/.gitignore index 6f472d0..9750b94 100644 --- a/app/.gitignore +++ b/app/.gitignore @@ -3,7 +3,3 @@ # no tests written yet /src/androidTest /src/test -/src/bin -/src/pkg -/src/src -/.deps diff --git a/app/build.gradle b/app/build.gradle index c70fd01..3a4b904 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -41,15 +41,15 @@ android { universalApk true } } - sourceSets.main.jniLibs.srcDirs += new File(projectDir, "src/bin") + sourceSets.main.jniLibs.srcDirs += new File(projectDir, "build/go") } task goBuild(type: Exec) { if (Os.isFamily(Os.FAMILY_WINDOWS)) { println "Warning: Building on Windows is not supported" } else { - executable "sh" - args "-c", "src/make.bash " + minSdkVersion + executable "/bin/bash" + args "go-build.bash", minSdkVersion environment "ANDROID_HOME", android.sdkDirectory environment "ANDROID_NDK_HOME", android.ndkDirectory } diff --git a/app/go-build.bash b/app/go-build.bash new file mode 100644 index 0000000..38ccdc2 --- /dev/null +++ b/app/go-build.bash @@ -0,0 +1,30 @@ +#!/bin/bash + +[[ -z "${ANDROID_NDK_HOME}" ]] && ANDROID_NDK_HOME="${ANDROID_HOME}/ndk-bundle" +TOOLCHAIN="$(find ${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/* -maxdepth 1 -type d -print -quit)/bin" +ABIS=(armeabi-v7a arm64-v8a x86 x86_64) +GO_ARCHS=('arm GOARM=7' arm64 386 amd64) +CLANG_ARCHS=(armv7a-linux-androideabi aarch64-linux-android i686-linux-android x86_64-linux-android) +STRIP_ARCHS=(arm-linux-androideabi aarch64-linux-android i686-linux-android x86_64-linux-android) + +MIN_API="$1" +ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +OUT_DIR="$ROOT/build/go" + +cd "$ROOT/src/main/go/v2ray-plugin" +BIN="libv2ray.so" +for i in "${!ABIS[@]}"; do + ABI="${ABIS[$i]}" + [[ -f "${OUT_DIR}/${ABI}/${BIN}" ]] && continue + echo "Build ${BIN} ${ABI}" + mkdir -p ${OUT_DIR}/${ABI} \ + && env \ + CGO_ENABLED=1 CC="${TOOLCHAIN}/${CLANG_ARCHS[$i]}${MIN_API}-clang" \ + GOOS=android GOARCH=${GO_ARCHS[$i]} \ + go build -v -ldflags='-s -w' -o "${OUT_DIR}/unstripped" \ + && "${TOOLCHAIN}/${STRIP_ARCHS[$i]}-strip" "${OUT_DIR}/unstripped" -o "${OUT_DIR}/${ABI}/${BIN}" \ + || exit -1 + rm "${OUT_DIR}/unstripped" +done + +cd "$ROOT" diff --git a/app/src/clean.bash b/app/src/clean.bash deleted file mode 100755 index 0afe174..0000000 --- a/app/src/clean.bash +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash - -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" - -rm -rf $DIR/.deps -rm -rf $DIR/bin - -echo "Successfully clean v2ray" diff --git a/app/src/main/go/v2ray-plugin b/app/src/main/go/v2ray-plugin new file mode 160000 index 0000000..d3c1201 --- /dev/null +++ b/app/src/main/go/v2ray-plugin @@ -0,0 +1 @@ +Subproject commit d3c12013b948ed7177cb1cde41e23d50256e3ae4 diff --git a/app/src/make.bash b/app/src/make.bash deleted file mode 100755 index f654a68..0000000 --- a/app/src/make.bash +++ /dev/null @@ -1,62 +0,0 @@ -#!/bin/bash - -function try () { -"$@" || exit -1 -} - -[ -z "$ANDROID_NDK_HOME" ] && ANDROID_NDK_HOME=$ANDROID_HOME/ndk-bundle -TOOLCHAIN=$(find $ANDROID_NDK_HOME/toolchains/llvm/prebuilt/* -maxdepth 1 -type d -print -quit)/bin - -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -MIN_API=$1 -TARGET=$DIR/bin - -try mkdir -p $TARGET/armeabi-v7a $TARGET/x86 $TARGET/arm64-v8a $TARGET/x86_64 - -export GOPATH=$DIR - -pushd $DIR/v2ray-plugin - -if [ ! -f "$TARGET/armeabi-v7a/libv2ray.so" ] || [ ! -f "$TARGET/arm64-v8a/libv2ray.so" ] || - [ ! -f "$TARGET/x86/libv2ray.so" ] || [ ! -f "$TARGET/x86_64/libv2ray.so" ]; then - - echo "Get dependences for v2ray" - go get -v - - echo "Cross compile v2ray for arm" - if [ ! -f "$TARGET/armeabi-v7a/libv2ray.so" ]; then - try env CGO_ENABLED=1 CC=$TOOLCHAIN/armv7a-linux-androideabi${MIN_API}-clang GOOS=android GOARCH=arm GOARM=7 \ - go build -ldflags="-s -w" -o client - try $TOOLCHAIN/arm-linux-androideabi-strip client - try mv client $TARGET/armeabi-v7a/libv2ray.so - fi - - echo "Cross compile v2ray for arm64" - if [ ! -f "$TARGET/arm64-v8a/libv2ray.so" ]; then - try env CGO_ENABLED=1 CC=$TOOLCHAIN/aarch64-linux-android${MIN_API}-clang GOOS=android GOARCH=arm64 \ - go build -ldflags="-s -w" -o client - try $TOOLCHAIN/aarch64-linux-android-strip client - try mv client $TARGET/arm64-v8a/libv2ray.so - fi - - echo "Cross compile v2ray for 386" - if [ ! -f "$TARGET/x86/libv2ray.so" ]; then - try env CGO_ENABLED=1 CC=$TOOLCHAIN/i686-linux-android${MIN_API}-clang GOOS=android GOARCH=386 \ - go build -ldflags="-s -w" -o client - try $TOOLCHAIN/i686-linux-android-strip client - try mv client $TARGET/x86/libv2ray.so - fi - - echo "Cross compile v2ray for amd64" - if [ ! -f "$TARGET/x86_64/libv2ray.so" ]; then - try env CGO_ENABLED=1 CC=$TOOLCHAIN/x86_64-linux-android${MIN_API}-clang GOOS=android GOARCH=amd64 \ - go build -ldflags="-s -w" -o client - try $TOOLCHAIN/x86_64-linux-android-strip client - try mv client $TARGET/x86_64/libv2ray.so - fi - - popd - -fi - -echo "Successfully build v2ray" diff --git a/app/src/v2ray-plugin b/app/src/v2ray-plugin deleted file mode 160000 index 1be661d..0000000 --- a/app/src/v2ray-plugin +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 1be661dbac71272443c0c69e0828b15f36152691