Skip to content

Commit

Permalink
Merge branch 'cgo-build'
Browse files Browse the repository at this point in the history
  • Loading branch information
Nutomic committed Oct 17, 2017
2 parents 9840076 + 1660479 commit 536c826
Show file tree
Hide file tree
Showing 14 changed files with 67 additions and 277 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ gen/
src/main/jniLibs/
obj/
.gradle/
gobuild/

# Local configuration file (sdk path, etc)
local.properties
Expand Down
13 changes: 2 additions & 11 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
[submodule "ext/syncthing/src/github.com/syncthing/syncthing"]
path = ext/syncthing/src/github.com/syncthing/syncthing
[submodule "syncthing"]
path = go/src/github.com/syncthing/syncthing
url = https://github.com/syncthing/syncthing.git
ignore = dirty
[submodule "ext/golang/go"]
path = ext/golang/go
url = https://github.com/golang/go.git
ignore = dirty
[submodule "ext/golang/go1.4"]
path = ext/golang/go1.4
url = https://github.com/golang/go.git
ignore = dirty
13 changes: 11 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
sudo: required
language: android
jdk: oraclejdk8
dist: trusty

# Install Android SDK
android:
Expand All @@ -13,10 +14,18 @@ android:
- android-26
- extra-android-m2repository

# Install Android NDK (apparently there is no easier way to do this)
# https://github.com/travis-ci/travis-ci/issues/5395
before_script:
- curl -L https://dl.google.com/android/repository/android-ndk-r15c-linux-x86_64.zip -O
- unzip -q android-ndk-r15c-linux-x86_64.zip
- export ANDROID_NDK_HOME=`pwd`/android-ndk-r15c

# Install Golang
before_install:
- sudo add-apt-repository ppa:gophers/archive -y
- sudo apt-get update -qq
- sudo apt-get install golang -y
- sudo apt-get install golang-1.9-go -y

# Cache gradle dependencies
# https://docs.travis-ci.com/user/languages/android/#Caching
Expand All @@ -29,5 +38,5 @@ cache:
- $HOME/.gradle/wrapper/

script:
- ./gradlew clean lint
- ./gradlew lintVitalRelease
- ./gradlew buildNative assembleDebug
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Use `./gradlew assembleDebug` in the project directory to compile the APK.

To prepare a new release, execute `./prepare-release.bash`, and follow the instructions.

To check for updated gradle dependencies, run `gradle dependencyUpdates`. Additionally, the git submodule in `ext/syncthing/src/github.com/syncthing/syncthing` may need to be updated.
To check for updated gradle dependencies, run `gradle dependencyUpdates`. Additionally, the git submodule in `go/src/github.com/syncthing/syncthing/` may need to be updated.


### Building on Windows
Expand Down
4 changes: 1 addition & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,11 @@ android {

task buildNative(type: Exec) {
outputs.upToDateWhen { false }
executable = './make-all.bash'
executable = './make-syncthing.bash'
}

task cleanNative(type: Delete) {
delete 'src/main/jniLibs/'
delete 'ext/syncthing/bin/'
delete 'ext/syncthing/pkg/'
}

play {
Expand Down
1 change: 0 additions & 1 deletion ext/golang/go
Submodule go deleted from cd6b62
1 change: 0 additions & 1 deletion ext/golang/go1.4
Submodule go1.4 deleted from 50eb39
Submodule syncthing deleted from 5aade9
Submodule syncthing added at cdbb32
12 changes: 0 additions & 12 deletions make-all.bash

This file was deleted.

96 changes: 0 additions & 96 deletions make-go.bash

This file was deleted.

105 changes: 48 additions & 57 deletions make-syncthing.bash
Original file line number Diff line number Diff line change
Expand Up @@ -2,72 +2,63 @@

set -e

MYDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
JNIDIR="/src/main/jniLibs"
ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
TARGET_SDK=$(grep "targetSdkVersion" "${ROOT_DIR}/build.gradle" -m 1 | awk '{print $2}')
# Use seperate build dir so standalone ndk isn't deleted by `gradle clean`
BUILD_DIR="${ROOT_DIR}/gobuild"
export GOPATH="${ROOT_DIR}/go/"

case "$1" in
arm)
export CGO_ENABLED=0
export GOOS=linux
export GOARCH=arm
export GOARM=5
export TARGETDIR=$MYDIR$JNIDIR/armeabi
;;
arm64)
export CGO_ENABLED=0
export GOOS=linux
export GOARCH=arm64
unset GOARM
export TARGETDIR=$MYDIR$JNIDIR/arm64-v8a
;;
386)
export CGO_ENABLED=0
export GOOS=linux
export GOARCH=386
export GO386=387
export TARGETDIR=$MYDIR$JNIDIR/x86
;;
*)
echo "Invalid architecture"
exit 1
esac

unset GOPATH #Set by build.go
export GOROOT=${MYDIR}/ext/golang/dist/go-${GOOS}-${GOARCH}
export PATH=${GOROOT}/bin:${PATH}

case "$(uname)" in
*CYGWIN*)
export GOROOT=`cygpath -w $GOROOT`
;;
esac

pushd ext/syncthing/src/github.com/syncthing/syncthing

_GOOS=$GOOS
unset GOOS
_GOARCH=$GOARCH
unset GOARCH
cd "${ROOT_DIR}/go/src/github.com/syncthing/syncthing"

# Make sure all tags are available for git describe
# https://github.com/syncthing/syncthing-android/issues/872
git fetch --tags

go run build.go -goos=${_GOOS} -goarch=${_GOARCH} clean
go run build.go -goos=${_GOOS} -goarch=${_GOARCH} -no-upgrade build
for ANDROID_ARCH in arm x86 arm64; do
echo -e "Starting build for ${ANDROID_ARCH}\n"
case ${ANDROID_ARCH} in
arm)
GOARCH=arm
JNI_DIR="armeabi"
GCC="arm-linux-androideabi-gcc"
;;
arm64)
GOARCH=arm64
JNI_DIR="arm64-v8a"
GCC="aarch64-linux-android-gcc"
;;
x86)
GOARCH=386
JNI_DIR="x86"
GCC="i686-linux-android-gcc"
;;
*)
echo "Invalid architecture"
exit 1
esac

# Build standalone NDK toolchain if it doesn't exist.
# https://developer.android.com/ndk/guides/standalone_toolchain.html
STANDALONE_NDK_DIR="${BUILD_DIR}/standalone-ndk/android-${TARGET_SDK}-${GOARCH}"

export GOOS=$_GOOS
export GOARCH=$_GOARCH
if [ ! -d "$STANDALONE_NDK_DIR" ]; then
echo -e "Building standalone NDK\n"
${ANDROID_NDK_HOME}/build/tools/make-standalone-toolchain.sh \
--platform=android-${TARGET_SDK} --arch=${ANDROID_ARCH} \
--install-dir=${STANDALONE_NDK_DIR}
fi

mkdir -p ${TARGETDIR}
mv syncthing ${TARGETDIR}/libsyncthing.so
chmod 644 ${TARGETDIR}/libsyncthing.so
echo -e "Building Syncthing\n"
CGO_ENABLED=1 CC="${STANDALONE_NDK_DIR}/bin/${GCC}" \
go run build.go -goos android -goarch ${GOARCH} -pkgdir "${BUILD_DIR}/go-packages" -no-upgrade build

if [[ -e ./build.go ]]; then
git clean -f
fi
# Copy compiled binary to jniLibs folder
TARGET_DIR="$ROOT_DIR/src/main/jniLibs/$JNI_DIR"
mkdir -p ${TARGET_DIR}
mv syncthing ${TARGET_DIR}/libsyncthing.so

popd
echo -e "Finished build for ${ANDROID_ARCH}\n"

echo "Build Complete"
done

echo -e "All builds finished"
Loading

0 comments on commit 536c826

Please sign in to comment.