Skip to content

Commit

Permalink
Fix #47: Build from source
Browse files Browse the repository at this point in the history
  • Loading branch information
x0b committed Mar 19, 2020
1 parent cf9d8a0 commit fb4f9f1
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 1 deletion.
1 change: 1 addition & 0 deletions rclone/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/gopath
101 changes: 101 additions & 0 deletions rclone/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
def repository = 'github.com/rclone/rclone'
def buildTag = 'v1.51.0'

import java.nio.file.Paths
def osName = System.properties['os.name'].toLowerCase()
def osArch = System.properties['os.arch']
def String os
if (osName.contains('windows')) {
if(osArch.equals('amd64')) {
os = "windows-x86_64"
} else if (osArch.equals('x86')) {
os = "windows"
}
} else if (osName.contains("linux")) {
os = "linux-x86_64"
} else if (osName.contains('mac')) {
os = "darwin-x86_64"
}

task fetchRclone(type: Exec) {
mkdir "gopath"
environment 'GOPATH', Paths.get(projectDir.absolutePath, 'gopath')
commandLine 'go', 'get', '-d', repository
}

task checkoutRclone(type: Exec) {
dependsOn fetchRclone
workingDir Paths.get(System.getenv('GOPATH'), "src/${repository}".split('/'))
commandLine 'git', 'checkout', buildTag
}

task cleanNative {
enabled = false
doLast {
delete '../app/lib/armeabi-v7a/librclone.so'
delete '../app/lib/arm64-v8a/librclone.so'
delete '../app/lib/x86/librclone.so'
delete '../app/lib/x86_64/librclone.so'
}
}

task buildArm(type: Exec) {
dependsOn checkoutRclone
environment 'GOPATH', Paths.get(projectDir.absolutePath, 'gopath')
def String crossCompiler = Paths.get(System.getenv('ANDROID_HOME'), 'ndk-bundle', 'toolchains', 'llvm', 'prebuilt', os, 'bin', 'armv7a-linux-androideabi21-clang')
environment 'CC', crossCompiler
environment 'CC_FOR_TARGET', crossCompiler
environment 'GOOS', 'android'
environment 'GOARCH', 'arm'
environment 'GOARM', '7'
environment 'CGO_ENABLED', '1'
commandLine 'go', 'build', '-v', '-tags', 'linux', '-o', '../app/lib/armeabi-v7a/librclone.so', repository
}

task buildArm64(type: Exec) {
dependsOn checkoutRclone
environment 'GOPATH', Paths.get(projectDir.absolutePath, 'gopath')
def String crossCompiler = Paths.get(System.getenv('ANDROID_HOME'), 'ndk-bundle', 'toolchains', 'llvm', 'prebuilt', os, 'bin', 'aarch64-linux-android21-clang')
environment 'CC', crossCompiler
environment 'CC_FOR_TARGET', crossCompiler
environment 'GOOS', 'android'
environment 'GOARCH', 'arm64'
environment 'CGO_ENABLED', '1'
commandLine 'go', 'build', '-v', '-tags', 'linux', '-o', '../app/lib/arm64-v8a/librclone.so', repository
}

task buildx86(type: Exec) {
dependsOn checkoutRclone
environment 'GOPATH', Paths.get(projectDir.absolutePath, 'gopath')
def String crossCompiler = Paths.get(System.getenv('ANDROID_HOME'), 'ndk-bundle', 'toolchains', 'llvm', 'prebuilt', os, 'bin', 'i686-linux-android21-clang')
environment 'CC', crossCompiler
environment 'CC_FOR_TARGET', crossCompiler
environment 'GOOS', 'android'
environment 'GOARCH', '386'
environment 'CGO_ENABLED', '1'
commandLine 'go', 'build', '-v', '-tags', 'linux', '-o', '../app/lib/x86/librclone.so', repository
}

task buildx64(type: Exec) {
dependsOn checkoutRclone
environment 'GOPATH', Paths.get(projectDir.absolutePath, 'gopath')
def String crossCompiler = Paths.get(System.getenv('ANDROID_HOME'), 'ndk-bundle', 'toolchains', 'llvm', 'prebuilt', os, 'bin', 'x86_64-linux-android21-clang')
environment 'CC', crossCompiler
environment 'CC_FOR_TARGET', crossCompiler
environment 'GOOS', 'android'
environment 'GOARCH', 'amd64'
environment 'CGO_ENABLED', '1'
commandLine 'go', 'build', '-v', '-tags', 'linux', '-o', '../app/lib/x86_64/librclone.so', repository
}

task buildNative {
dependsOn fetchRclone
dependsOn checkoutRclone
dependsOn buildArm
dependsOn buildArm64
dependsOn buildx86
dependsOn buildx64
}

buildNative.mustRunAfter(buildArm, buildArm64, buildx86, buildx64)
defaultTasks 'buildNative'
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include ':app', ':safdav'
include ':app', ':safdav', ':rclone'

0 comments on commit fb4f9f1

Please sign in to comment.