mirror of
https://github.com/syncthing/syncthing-android.git
synced 2024-11-22 04:11:14 +00:00
Use CGO to build Syncthing with support for DNS (fixes #57)
This commit is contained in:
parent
093afbcb13
commit
a05fa80470
15 changed files with 9883 additions and 100 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -38,6 +38,9 @@ proguard/
|
|||
gradle/wrapper/gradle/
|
||||
gradle/wrapper/gradlew*
|
||||
|
||||
# Go native dependencies
|
||||
ext/golang/dist
|
||||
|
||||
# Syncthing native dependencies
|
||||
ext/syncthing/pkg/
|
||||
ext/syncthing/src/code.google.com/
|
||||
|
|
6
.gitmodules
vendored
6
.gitmodules
vendored
|
@ -1,3 +1,9 @@
|
|||
[submodule "ext/syncthing/src/github.com/syncthing/syncthing"]
|
||||
path = ext/syncthing/src/github.com/syncthing/syncthing
|
||||
url = https://github.com/syncthing/syncthing.git
|
||||
[submodule "ext/golang/go"]
|
||||
path = ext/golang/go
|
||||
url = https://github.com/golang/go.git
|
||||
[submodule "ext/golang/go1.4"]
|
||||
path = ext/golang/go1.4
|
||||
url = https://github.com/golang/go.git
|
||||
|
|
|
@ -1,78 +0,0 @@
|
|||
#!/bin/bash -e
|
||||
|
||||
# Build the syncthing library
|
||||
ORIG=$(pwd)
|
||||
mkdir -p bin
|
||||
|
||||
# Load submodules
|
||||
if [ ! -e "ext/syncthing/src/github.com/syncthing/syncthing/.git" ]; then
|
||||
git submodule update --init --recursive
|
||||
fi
|
||||
|
||||
# Check for GOLANG installation
|
||||
if [ -z $GOROOT ] || [[ $(go version) != go\ version\ go1.4* ]] ; then
|
||||
mkdir -p "build"
|
||||
tmpgo='build/go'
|
||||
if [ ! -f "$tmpgo/bin/go" ]; then
|
||||
# Download GOLANG v1.4.2
|
||||
wget -O go.src.tar.gz http://golang.org/dl/go1.4.2.src.tar.gz
|
||||
sha1=$(sha1sum go.src.tar.gz)
|
||||
if [ "$sha1" != "460caac03379f746c473814a65223397e9c9a2f6 go.src.tar.gz" ]; then
|
||||
echo "go.src.tar.gz SHA1 checksum does not match!"
|
||||
exit 1
|
||||
fi
|
||||
mkdir -p $tmpgo
|
||||
tar -xzf go.src.tar.gz --strip=1 -C $tmpgo
|
||||
rm go.src.tar.gz
|
||||
# Build GO for host
|
||||
pushd $tmpgo/src
|
||||
GO386=387 GOARM=5 ./make.bash --no-clean
|
||||
popd
|
||||
fi
|
||||
# Add GO to the environment
|
||||
export GOROOT="$(pwd)/$tmpgo"
|
||||
fi
|
||||
|
||||
# Add GO compiler to PATH
|
||||
export PATH=$GOROOT/bin:$PATH
|
||||
# Disable CGO (no dynamic linking)
|
||||
export CGO_ENABLED=0
|
||||
|
||||
# Check whether GOLANG is compiled with cross-compilation for 386
|
||||
if [ ! -f $GOROOT/bin/linux_386/go ]; then
|
||||
pushd $GOROOT/src
|
||||
# Build GO for cross-compilation
|
||||
GOOS=linux GOARCH=386 GO386=387 ./make.bash --no-clean
|
||||
popd
|
||||
fi
|
||||
|
||||
# Check whether GOLANG is compiled with cross-compilation for arm
|
||||
if [ ! -f $GOROOT/bin/linux_arm/go ]; then
|
||||
pushd $GOROOT/src
|
||||
# Build GO for cross-compilation
|
||||
GOOS=linux GOARCH=arm GOARM=5 ./make.bash --no-clean
|
||||
popd
|
||||
fi
|
||||
|
||||
# Setup GOPATH
|
||||
cd "ext/syncthing/"
|
||||
export GOPATH="$(pwd)"
|
||||
|
||||
# Install godep
|
||||
$GOROOT/bin/go get github.com/tools/godep
|
||||
export PATH="$(pwd)/bin":$PATH
|
||||
|
||||
# Setup syncthing and clean
|
||||
export ENVIRONMENT=android
|
||||
cd src/github.com/syncthing/syncthing
|
||||
$GOROOT/bin/go run build.go clean
|
||||
|
||||
# X86
|
||||
GO386=387 $GOROOT/bin/go run build.go -goos linux -goarch 386 -no-upgrade build
|
||||
mv syncthing $ORIG/bin/syncthing-x86
|
||||
$GOROOT/bin/go run build.go clean
|
||||
|
||||
# ARM
|
||||
GOARM=5 $GOROOT/bin/go run build.go -goos linux -goarch arm -no-upgrade build
|
||||
mv syncthing $ORIG/bin/syncthing-armeabi
|
||||
$GOROOT/bin/go run build.go clean
|
22
build.gradle
22
build.gradle
|
@ -27,10 +27,6 @@ dependencies {
|
|||
androidTestCompile 'com.squareup.okhttp:mockwebserver:2.4.0'
|
||||
}
|
||||
|
||||
preBuild {
|
||||
dependsOn 'buildNative'
|
||||
}
|
||||
|
||||
project.archivesBaseName = 'syncthing'
|
||||
|
||||
android {
|
||||
|
@ -104,25 +100,9 @@ android {
|
|||
|
||||
task buildNative(type: Exec) {
|
||||
outputs.upToDateWhen { false }
|
||||
executable = './build-syncthing.sh'
|
||||
executable = './make-all.bash'
|
||||
}
|
||||
|
||||
task copyNative(type: Copy) {
|
||||
def lib_dir = "libs/"
|
||||
new File(lib_dir).mkdirs()
|
||||
def st_dir = "bin/";
|
||||
from st_dir + 'syncthing-x86', st_dir + 'syncthing-armeabi';
|
||||
into lib_dir
|
||||
rename('syncthing-x86', 'x86/libsyncthing.so')
|
||||
rename('syncthing-armeabi', 'armeabi/libsyncthing.so')
|
||||
}
|
||||
buildNative.finalizedBy copyNative
|
||||
|
||||
task cleanBin(type: Delete) {
|
||||
delete 'bin/'
|
||||
}
|
||||
copyNative.finalizedBy cleanBin
|
||||
|
||||
task cleanNative(type: Delete) {
|
||||
delete 'bin/'
|
||||
delete 'build/'
|
||||
|
|
1
ext/golang/go
Submodule
1
ext/golang/go
Submodule
|
@ -0,0 +1 @@
|
|||
Subproject commit 525d4bd5203ce0bc6d36add058041dcdfb979161
|
1
ext/golang/go1.4
Submodule
1
ext/golang/go1.4
Submodule
|
@ -0,0 +1 @@
|
|||
Subproject commit 50eb39bb23e8b03e823c38e844f0410d0b5325d2
|
|
@ -0,0 +1,267 @@
|
|||
From df553e646c597ab7fb26e3ffa2b730c04ab069f8 Mon Sep 17 00:00:00 2001
|
||||
From: Hyang-Ah Hana Kim <hyangah@gmail.com>
|
||||
Date: Thu, 5 Nov 2015 16:32:27 -0500
|
||||
Subject: [PATCH 1/4] cmd,runtime: TLS setup for android/386
|
||||
|
||||
Same ugly hack as https://go-review.googlesource.com/15991.
|
||||
|
||||
Update golang/go#9327.
|
||||
|
||||
Change-Id: I58284e83268a15de95eabc833c3e01bf1e3faa2e
|
||||
---
|
||||
src/cmd/internal/obj/x86/asm6.go | 3 ++
|
||||
src/cmd/link/internal/ld/sym.go | 15 +++++--
|
||||
src/runtime/cgo/gcc_android_386.c | 87 +++++++++++++++++++++++++++++++++++++++
|
||||
src/runtime/cgo/gcc_linux_386.c | 12 ++++++
|
||||
src/runtime/rt0_android_386.s | 39 ++++++++++++++++++
|
||||
src/runtime/sys_linux_386.s | 10 +++++
|
||||
6 files changed, 162 insertions(+), 4 deletions(-)
|
||||
create mode 100644 src/runtime/cgo/gcc_android_386.c
|
||||
create mode 100644 src/runtime/rt0_android_386.s
|
||||
|
||||
diff --git a/src/cmd/internal/obj/x86/asm6.go b/src/cmd/internal/obj/x86/asm6.go
|
||||
index 919e00b..13ab240 100644
|
||||
--- a/src/cmd/internal/obj/x86/asm6.go
|
||||
+++ b/src/cmd/internal/obj/x86/asm6.go
|
||||
@@ -1975,6 +1975,9 @@ func prefixof(ctxt *obj.Link, p *obj.Prog, a *obj.Addr) int {
|
||||
if p.Mode == 32 {
|
||||
switch ctxt.Headtype {
|
||||
default:
|
||||
+ if isAndroid {
|
||||
+ return 0x65 // GS
|
||||
+ }
|
||||
log.Fatalf("unknown TLS base register for %s", obj.Headstr(ctxt.Headtype))
|
||||
|
||||
case obj.Hdarwin,
|
||||
diff --git a/src/cmd/link/internal/ld/sym.go b/src/cmd/link/internal/ld/sym.go
|
||||
index da5776d..d91f138 100644
|
||||
--- a/src/cmd/link/internal/ld/sym.go
|
||||
+++ b/src/cmd/link/internal/ld/sym.go
|
||||
@@ -102,10 +102,17 @@ func linknew(arch *LinkArch) *Link {
|
||||
obj.Hopenbsd,
|
||||
obj.Hdragonfly,
|
||||
obj.Hsolaris:
|
||||
- if obj.Getgoos() == "android" && ctxt.Arch.Thechar == '6' {
|
||||
- // Android/x86 constant - offset from 0(FS) to our
|
||||
- // TLS slot. Explained in src/runtime/cgo/gcc_android_*.c
|
||||
- ctxt.Tlsoffset = 0x1d0
|
||||
+ if obj.Getgoos() == "android" {
|
||||
+ switch ctxt.Arch.Thechar {
|
||||
+ case '6':
|
||||
+ // Android/x86 constant - offset from 0(FS) to our
|
||||
+ // TLS slot. Explained in src/runtime/cgo/gcc_android_*.c
|
||||
+ ctxt.Tlsoffset = 0x1d0
|
||||
+ case '8':
|
||||
+ ctxt.Tlsoffset = 0xf8
|
||||
+ default:
|
||||
+ ctxt.Tlsoffset = -1 * ctxt.Arch.Ptrsize
|
||||
+ }
|
||||
} else {
|
||||
ctxt.Tlsoffset = -1 * ctxt.Arch.Ptrsize
|
||||
}
|
||||
diff --git a/src/runtime/cgo/gcc_android_386.c b/src/runtime/cgo/gcc_android_386.c
|
||||
new file mode 100644
|
||||
index 0000000..a82d7d0
|
||||
--- /dev/null
|
||||
+++ b/src/runtime/cgo/gcc_android_386.c
|
||||
@@ -0,0 +1,87 @@
|
||||
+// Copyright 2015 The Go Authors. All rights reserved.
|
||||
+// Use of this source code is governed by a BSD-style
|
||||
+// license that can be found in the LICENSE file.
|
||||
+
|
||||
+#include <string.h> /* for strerror */
|
||||
+#include <pthread.h>
|
||||
+#include <signal.h>
|
||||
+#include "libcgo.h"
|
||||
+
|
||||
+static void* threadentry(void*);
|
||||
+static pthread_key_t k1;
|
||||
+
|
||||
+#define magic1 (0x23581321U)
|
||||
+
|
||||
+static void
|
||||
+inittls(void)
|
||||
+{
|
||||
+ uint32 x;
|
||||
+ pthread_key_t tofree[128], k;
|
||||
+ int i, ntofree;
|
||||
+
|
||||
+ /*
|
||||
+ * Same logic, code as gcc_android_amd64.c:/inittls.
|
||||
+ * Note that this is a temporary hack that should be fixed soon.
|
||||
+ *
|
||||
+ * TODO: fix this.
|
||||
+ *
|
||||
+ * The linker and runtime hard-code this constant offset
|
||||
+ * from %gs where we expect to find g. Disgusting.
|
||||
+ *
|
||||
+ * Known to src/cmd/link/internal/ld/sym.go:/0xf8
|
||||
+ * and to src/runtime/sys_linux_386.s:/0xf8 or /GOOS_android.
|
||||
+ * TODO(hyangah): check 0xb0 works with API23+
|
||||
+ *
|
||||
+ * As disgusting as on the darwin/386, darwin/amd64.
|
||||
+ */
|
||||
+ ntofree = 0;
|
||||
+ for(;;) {
|
||||
+ if(pthread_key_create(&k, nil) < 0) {
|
||||
+ fprintf(stderr, "runtime/cgo: pthread_key_create failed\n");
|
||||
+ abort();
|
||||
+ }
|
||||
+ pthread_setspecific(k, (void*)magic1);
|
||||
+ asm volatile("movl %%gs:0xf8, %0" : "=r"(x));
|
||||
+ pthread_setspecific(k, 0);
|
||||
+ if (x == magic1) {
|
||||
+ k1 = k;
|
||||
+ break;
|
||||
+ }
|
||||
+ if(ntofree >= nelem(tofree)) {
|
||||
+ fprintf(stderr, "runtime/cgo: could not obtain pthread_keys\n");
|
||||
+ fprintf(stderr, "\ttried");
|
||||
+ for(i=0; i<ntofree; i++)
|
||||
+ fprintf(stderr, " %#x", (unsigned)tofree[i]);
|
||||
+ fprintf(stderr, "\n");
|
||||
+ abort();
|
||||
+ }
|
||||
+ tofree[ntofree++] = k;
|
||||
+ }
|
||||
+ // TODO: output to stderr is not useful for apps.
|
||||
+ // Can we fall back to Android's log library?
|
||||
+
|
||||
+ /*
|
||||
+ * We got the key we wanted. Free the others.
|
||||
+ */
|
||||
+ for(i=0; i<ntofree; i++) {
|
||||
+ pthread_key_delete(tofree[i]);
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+
|
||||
+static void*
|
||||
+threadentry(void *v)
|
||||
+{
|
||||
+ ThreadStart ts;
|
||||
+
|
||||
+ ts = *(ThreadStart*)v;
|
||||
+ free(v);
|
||||
+
|
||||
+ pthread_setspecific(k1, (void*)ts.g);
|
||||
+
|
||||
+ crosscall_386(ts.fn);
|
||||
+ return nil;
|
||||
+}
|
||||
+
|
||||
+void (*x_cgo_inittls)(void) = inittls;
|
||||
+void* (*x_cgo_threadentry)(void*) = threadentry;
|
||||
diff --git a/src/runtime/cgo/gcc_linux_386.c b/src/runtime/cgo/gcc_linux_386.c
|
||||
index 9801c87..8fb7130 100644
|
||||
--- a/src/runtime/cgo/gcc_linux_386.c
|
||||
+++ b/src/runtime/cgo/gcc_linux_386.c
|
||||
@@ -10,6 +10,10 @@
|
||||
static void *threadentry(void*);
|
||||
static void (*setg_gcc)(void*);
|
||||
|
||||
+// These will be set in gcc_android_386.c for android-specific customization.
|
||||
+void (*x_cgo_inittls)(void);
|
||||
+void* (*x_cgo_threadentry)(void*);
|
||||
+
|
||||
void
|
||||
x_cgo_init(G *g, void (*setg)(void*))
|
||||
{
|
||||
@@ -21,6 +25,10 @@ x_cgo_init(G *g, void (*setg)(void*))
|
||||
pthread_attr_getstacksize(&attr, &size);
|
||||
g->stacklo = (uintptr)&attr - size + 4096;
|
||||
pthread_attr_destroy(&attr);
|
||||
+
|
||||
+ if (x_cgo_inittls) {
|
||||
+ x_cgo_inittls();
|
||||
+ }
|
||||
}
|
||||
|
||||
|
||||
@@ -57,6 +65,10 @@ _cgo_sys_thread_start(ThreadStart *ts)
|
||||
static void*
|
||||
threadentry(void *v)
|
||||
{
|
||||
+ if (x_cgo_threadentry) {
|
||||
+ return x_cgo_threadentry(v);
|
||||
+ }
|
||||
+
|
||||
ThreadStart ts;
|
||||
|
||||
ts = *(ThreadStart*)v;
|
||||
diff --git a/src/runtime/rt0_android_386.s b/src/runtime/rt0_android_386.s
|
||||
new file mode 100644
|
||||
index 0000000..bf44af3
|
||||
--- /dev/null
|
||||
+++ b/src/runtime/rt0_android_386.s
|
||||
@@ -0,0 +1,39 @@
|
||||
+// Copyright 2015 The Go Authors. All rights reserved.
|
||||
+// Use of this source code is governed by a BSD-style
|
||||
+// license that can be found in the LICENSE file.
|
||||
+
|
||||
+#include "textflag.h"
|
||||
+
|
||||
+TEXT _rt0_386_android(SB),NOSPLIT,$8
|
||||
+ MOVL 8(SP), AX // argc
|
||||
+ LEAL 12(SP), BX // argv
|
||||
+ MOVL AX, 0(SP)
|
||||
+ MOVL BX, 4(SP)
|
||||
+ CALL main(SB)
|
||||
+ INT $3
|
||||
+
|
||||
+TEXT _rt0_386_android_lib(SB),NOSPLIT,$0
|
||||
+ PUSHL $_rt0_386_android_argv(SB) // argv
|
||||
+ PUSHL $1 // argc
|
||||
+ CALL _rt0_386_linux_lib(SB)
|
||||
+ POPL AX
|
||||
+ POPL AX
|
||||
+ RET
|
||||
+
|
||||
+DATA _rt0_386_android_argv+0x00(SB)/4,$_rt0_386_android_argv0(SB)
|
||||
+DATA _rt0_386_android_argv+0x04(SB)/4,$0
|
||||
+DATA _rt0_386_android_argv+0x08(SB)/4,$0
|
||||
+DATA _rt0_386_android_argv+0x0c(SB)/4,$15 // AT_PLATFORM (auxvec.h)
|
||||
+DATA _rt0_386_android_argv+0x10(SB)/4,$_rt0_386_android_auxv0(SB)
|
||||
+DATA _rt0_386_android_argv+0x14(SB)/4,$0
|
||||
+DATA _rt0_386_android_argv+0x18(SB)/4,$0
|
||||
+DATA _rt0_386_android_argv+0x1c(SB)/4,$0
|
||||
+GLOBL _rt0_386_android_argv(SB),NOPTR,$0x20
|
||||
+
|
||||
+// TODO: AT_HWCAP necessary? If so, what value?
|
||||
+
|
||||
+DATA _rt0_386_android_argv0(SB)/8, $"gojni"
|
||||
+GLOBL _rt0_386_android_argv0(SB),RODATA,$8
|
||||
+
|
||||
+DATA _rt0_386_android_auxv0(SB)/8, $"i386"
|
||||
+GLOBL _rt0_386_android_auxv0(SB),RODATA,$8
|
||||
diff --git a/src/runtime/sys_linux_386.s b/src/runtime/sys_linux_386.s
|
||||
index 9e0e87c..a52c4b2 100644
|
||||
--- a/src/runtime/sys_linux_386.s
|
||||
+++ b/src/runtime/sys_linux_386.s
|
||||
@@ -405,6 +405,15 @@ TEXT runtime·setldt(SB),NOSPLIT,$32
|
||||
MOVL entry+0(FP), BX // entry
|
||||
MOVL address+4(FP), CX // base address
|
||||
|
||||
+#ifdef GOOS_android
|
||||
+ /*
|
||||
+ * Same as in sys_darwin_386.s:/ugliness, different constant.
|
||||
+ * address currently holds m->tls, which must be %gs:0xf8.
|
||||
+ * See cgo/gcc_android_386.c for the derivation of the constant.
|
||||
+ */
|
||||
+ SUBL $0xf8, CX
|
||||
+ MOVL CX, 0(CX)
|
||||
+#else
|
||||
/*
|
||||
* When linking against the system libraries,
|
||||
* we use its pthread_create and let it set up %gs
|
||||
@@ -420,6 +429,7 @@ TEXT runtime·setldt(SB),NOSPLIT,$32
|
||||
*/
|
||||
ADDL $0x4, CX // address
|
||||
MOVL CX, 0(CX)
|
||||
+#endif
|
||||
|
||||
// set up user_desc
|
||||
LEAL 16(SP), AX // struct user_desc
|
||||
--
|
||||
2.5.2
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
From 4d38efc71f1a8733377cb0d0b06eeaee11ddb15c Mon Sep 17 00:00:00 2001
|
||||
From: Hyang-Ah Hana Kim <hyangah@gmail.com>
|
||||
Date: Thu, 5 Nov 2015 16:35:24 -0500
|
||||
Subject: [PATCH 2/4] runtime: add syscalls needed for android/386 logging
|
||||
|
||||
Update golang/go#9327.
|
||||
|
||||
Change-Id: I27ef973190d9ae652411caf3739414b5d46ca7d2
|
||||
---
|
||||
src/runtime/sys_linux_386.s | 31 +++++++++++++++++++++++++++++++
|
||||
1 file changed, 31 insertions(+)
|
||||
|
||||
diff --git a/src/runtime/sys_linux_386.s b/src/runtime/sys_linux_386.s
|
||||
index a52c4b2..eaf1d1e 100644
|
||||
--- a/src/runtime/sys_linux_386.s
|
||||
+++ b/src/runtime/sys_linux_386.s
|
||||
@@ -518,3 +518,34 @@ TEXT runtime·closeonexec(SB),NOSPLIT,$0
|
||||
MOVL $1, DX // FD_CLOEXEC
|
||||
INVOKE_SYSINFO
|
||||
RET
|
||||
+
|
||||
+// int access(const char *name, int mode)
|
||||
+TEXT runtime·access(SB),NOSPLIT,$0
|
||||
+ MOVL $33, AX // syscall - access
|
||||
+ MOVL name+0(FP), BX
|
||||
+ MOVL mode+4(FP), CX
|
||||
+ INVOKE_SYSINFO
|
||||
+ MOVL AX, ret+8(FP)
|
||||
+ RET
|
||||
+
|
||||
+// int connect(int fd, const struct sockaddr *addr, socklen_t addrlen)
|
||||
+TEXT runtime·connect(SB),NOSPLIT,$0
|
||||
+ // connect is implemented as socketcall(NR_socket, 3, *(rest of args))
|
||||
+ // stack already should have fd, addr, addrlen.
|
||||
+ MOVL $102, AX // syscall - socketcall
|
||||
+ MOVL $3, BX // connect
|
||||
+ LEAL fd+0(FP), CX
|
||||
+ INVOKE_SYSINFO
|
||||
+ MOVL AX, ret+12(FP)
|
||||
+ RET
|
||||
+
|
||||
+// int socket(int domain, int type, int protocol)
|
||||
+TEXT runtime·socket(SB),NOSPLIT,$0
|
||||
+ // socket is implemented as socketcall(NR_socket, 1, *(rest of args))
|
||||
+ // stack already should have domain, type, protocol.
|
||||
+ MOVL $102, AX // syscall - socketcall
|
||||
+ MOVL $1, BX // socket
|
||||
+ LEAL domain+0(FP), CX
|
||||
+ INVOKE_SYSINFO
|
||||
+ MOVL AX, ret+12(FP)
|
||||
+ RET
|
||||
--
|
||||
2.5.2
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
From 467be3ff84bd18698b2c7dce8695a210c19b705a Mon Sep 17 00:00:00 2001
|
||||
From: Hyang-Ah Hana Kim <hyangah@gmail.com>
|
||||
Date: Thu, 5 Nov 2015 16:37:07 -0500
|
||||
Subject: [PATCH 3/4] cmd: enable android/386 build (buildmode=pie by default)
|
||||
|
||||
no buildmode=c-shared yet.
|
||||
|
||||
Update golang/go#9327.
|
||||
|
||||
Change-Id: I9989d954d574807bac105da401c3463607fe8a99
|
||||
---
|
||||
src/cmd/compile/internal/gc/lex.go | 2 +-
|
||||
src/cmd/go/build.go | 4 ++--
|
||||
2 files changed, 3 insertions(+), 3 deletions(-)
|
||||
|
||||
diff --git a/src/cmd/compile/internal/gc/lex.go b/src/cmd/compile/internal/gc/lex.go
|
||||
index 9fe0f6c..31d41b4 100644
|
||||
--- a/src/cmd/compile/internal/gc/lex.go
|
||||
+++ b/src/cmd/compile/internal/gc/lex.go
|
||||
@@ -221,7 +221,7 @@ func Main() {
|
||||
var flag_shared int
|
||||
var flag_dynlink bool
|
||||
switch Thearch.Thechar {
|
||||
- case '5', '6', '7', '9':
|
||||
+ case '5', '6', '7', '8', '9':
|
||||
obj.Flagcount("shared", "generate code that can be linked into a shared library", &flag_shared)
|
||||
}
|
||||
if Thearch.Thechar == '6' {
|
||||
diff --git a/src/cmd/go/build.go b/src/cmd/go/build.go
|
||||
index e869b27..50d7a6d 100644
|
||||
--- a/src/cmd/go/build.go
|
||||
+++ b/src/cmd/go/build.go
|
||||
@@ -361,7 +361,7 @@ func buildModeInit() {
|
||||
ldBuildmode = "c-shared"
|
||||
case "default":
|
||||
switch platform {
|
||||
- case "android/arm", "android/amd64":
|
||||
+ case "android/arm", "android/amd64", "android/386":
|
||||
codegenArg = "-shared"
|
||||
ldBuildmode = "pie"
|
||||
default:
|
||||
@@ -375,7 +375,7 @@ func buildModeInit() {
|
||||
fatalf("-buildmode=pie not supported by gccgo")
|
||||
} else {
|
||||
switch platform {
|
||||
- case "android/arm", "linux/amd64", "android/amd64":
|
||||
+ case "android/arm", "linux/amd64", "android/amd64", "android/386":
|
||||
codegenArg = "-shared"
|
||||
default:
|
||||
fatalf("-buildmode=pie not supported on %s\n", platform)
|
||||
--
|
||||
2.5.2
|
||||
|
|
@ -0,0 +1,99 @@
|
|||
From de38cf7c1a1e59009e917c3619ca1c6d1372b72c Mon Sep 17 00:00:00 2001
|
||||
From: Hyang-Ah Hana Kim <hyangah@gmail.com>
|
||||
Date: Fri, 6 Nov 2015 17:28:58 -0500
|
||||
Subject: [PATCH 4/4] cmd: allow buildmode=c-shared for android/386
|
||||
|
||||
Update golang/go#9327.
|
||||
|
||||
Change-Id: Iab7dad31cf6b9f9347c3f34faebb67ecb38b17fc
|
||||
---
|
||||
misc/cgo/testcshared/test.bash | 4 +++-
|
||||
src/cmd/dist/test.go | 4 +++-
|
||||
src/cmd/go/build.go | 2 +-
|
||||
src/cmd/link/internal/ld/lib.go | 24 +++++++++++++++++++++---
|
||||
4 files changed, 28 insertions(+), 6 deletions(-)
|
||||
|
||||
diff --git a/misc/cgo/testcshared/test.bash b/misc/cgo/testcshared/test.bash
|
||||
index a641162..8963e4b 100755
|
||||
--- a/misc/cgo/testcshared/test.bash
|
||||
+++ b/misc/cgo/testcshared/test.bash
|
||||
@@ -81,7 +81,9 @@ GOPATH=$(pwd) go install -buildmode=c-shared $suffix libgo
|
||||
GOPATH=$(pwd) go build -buildmode=c-shared $suffix -o libgo.$libext src/libgo/libgo.go
|
||||
binpush libgo.$libext
|
||||
|
||||
-if [ "$goos" == "linux" ] || [ "$goos" == "android" ] ; then
|
||||
+# TODO: fix text relocation bug in android/386.
|
||||
+
|
||||
+if [ "$goos" == "linux" ] || [ "$goos" == "android" ] && [ "$goarch" != "386" ] ; then
|
||||
if readelf -d libgo.$libext | grep TEXTREL >/dev/null; then
|
||||
echo "libgo.$libext has TEXTREL set"
|
||||
exit 1
|
||||
diff --git a/src/cmd/dist/test.go b/src/cmd/dist/test.go
|
||||
index 6b0056a..8a7638c 100644
|
||||
--- a/src/cmd/dist/test.go
|
||||
+++ b/src/cmd/dist/test.go
|
||||
@@ -581,7 +581,9 @@ func (t *tester) supportedBuildmode(mode string) bool {
|
||||
case "c-shared":
|
||||
// TODO(hyangah): add linux-386.
|
||||
switch pair {
|
||||
- case "linux-amd64", "darwin-amd64", "android-arm", "linux-arm", "linux-arm64":
|
||||
+ case "linux-amd64", "linux-arm", "linux-arm64",
|
||||
+ "darwin-amd64",
|
||||
+ "android-amd64", "android-386", "android-arm":
|
||||
return true
|
||||
}
|
||||
return false
|
||||
diff --git a/src/cmd/go/build.go b/src/cmd/go/build.go
|
||||
index 50d7a6d..e7a9f13 100644
|
||||
--- a/src/cmd/go/build.go
|
||||
+++ b/src/cmd/go/build.go
|
||||
@@ -351,7 +351,7 @@ func buildModeInit() {
|
||||
} else {
|
||||
switch platform {
|
||||
case "linux/amd64", "linux/arm", "linux/arm64",
|
||||
- "android/amd64", "android/arm":
|
||||
+ "android/amd64", "android/arm", "android/386":
|
||||
codegenArg = "-shared"
|
||||
case "darwin/amd64":
|
||||
default:
|
||||
diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go
|
||||
index f0e0511..d17825f 100644
|
||||
--- a/src/cmd/link/internal/ld/lib.go
|
||||
+++ b/src/cmd/link/internal/ld/lib.go
|
||||
@@ -317,12 +317,30 @@ func (mode *BuildMode) Set(s string) error {
|
||||
}
|
||||
*mode = BuildmodeCArchive
|
||||
case "c-shared":
|
||||
- if goarch != "amd64" && goarch != "arm" && goarch != "arm64" {
|
||||
- return badmode()
|
||||
+ switch goos {
|
||||
+ case "android":
|
||||
+ switch goarch {
|
||||
+ case "386", "amd64", "arm", "arm64":
|
||||
+ default:
|
||||
+ return badmode()
|
||||
+ }
|
||||
+ default:
|
||||
+ switch goarch {
|
||||
+ case "amd64", "arm", "arm64":
|
||||
+ default:
|
||||
+ return badmode()
|
||||
+ }
|
||||
}
|
||||
*mode = BuildmodeCShared
|
||||
case "shared":
|
||||
- if goos != "linux" || (goarch != "386" && goarch != "amd64" && goarch != "arm" && goarch != "arm64") {
|
||||
+ switch goos {
|
||||
+ case "linux":
|
||||
+ switch goarch {
|
||||
+ case "386", "amd64", "arm", "arm64":
|
||||
+ default:
|
||||
+ return badmode()
|
||||
+ }
|
||||
+ default:
|
||||
return badmode()
|
||||
}
|
||||
*mode = BuildmodeShared
|
||||
--
|
||||
2.5.2
|
||||
|
9173
ext/patches/syncthing-inotify/godeps/0001-add-godeps.patch
Normal file
9173
ext/patches/syncthing-inotify/godeps/0001-add-godeps.patch
Normal file
File diff suppressed because it is too large
Load diff
|
@ -1 +1 @@
|
|||
Subproject commit 3e25b579bc4843b6cde69e867e8b6e5e6ea304c1
|
||||
Subproject commit 56f1c295b609e402c994e93fb963636d89247ca2
|
13
make-all.bash
Executable file
13
make-all.bash
Executable file
|
@ -0,0 +1,13 @@
|
|||
#!/bin/bash -e
|
||||
|
||||
# Build the syncthing library
|
||||
|
||||
./make-go.bash arm
|
||||
./make-syncthing.bash arm
|
||||
|
||||
./make-go.bash 386
|
||||
./make-syncthing.bash 386
|
||||
|
||||
./make-go.bash amd64
|
||||
./make-syncthing.bash amd64
|
||||
|
115
make-go.bash
Executable file
115
make-go.bash
Executable file
|
@ -0,0 +1,115 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
|
||||
RESET=1
|
||||
|
||||
MYDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
if [ -z "$ANDROID_NDK" ]; then
|
||||
echo "Error: unspecified ANDROID_NDK"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "$GOROOT_BOOTSTRAP" ]; then
|
||||
# We need Go 1.4 to bootstrap Go 1.5
|
||||
if [ -z $GOROOT ] || [[ $(go version) != go\ version\ go1.4* ]] ; then
|
||||
git submodule update --init ext/golang/go1.4
|
||||
# Build Go 1.4 for host
|
||||
pushd ext/golang/go1.4/src
|
||||
./make.bash --no-clean
|
||||
popd
|
||||
# Add Go 1.4 to the environment
|
||||
export GOROOT="$(pwd)/ext/golang/go1.4"
|
||||
fi
|
||||
# Add Go 1.4 compiler to PATH
|
||||
export GOROOT_BOOTSTRAP=$GOROOT
|
||||
fi
|
||||
|
||||
case "$1" in
|
||||
arm)
|
||||
if [ ! -d "${MYDIR}/build/ndk-$1" ]; then
|
||||
sh ${ANDROID_NDK}/build/tools/make-standalone-toolchain.sh --platform=android-9 --toolchain=arm-linux-androideabi-4.9 --install-dir=${MYDIR}/build/ndk-$1
|
||||
fi
|
||||
export CC_FOR_TARGET=${MYDIR}/build/ndk-arm/bin/arm-linux-androideabi-gcc
|
||||
export CXX_FOR_TARGET=${MYDIR}/build/ndk-arm/bin/arm-linux-androideabi-g++
|
||||
export CGO_ENABLED=1
|
||||
export GOOS=android
|
||||
export GOARCH=arm
|
||||
export GOARM=5
|
||||
;;
|
||||
386)
|
||||
if [ ! -d "${MYDIR}/build/ndk-$1" ]; then
|
||||
sh ${ANDROID_NDK}/build/tools/make-standalone-toolchain.sh --platform=android-9 --toolchain=x86-4.9 --install-dir=${MYDIR}/build/ndk-$1
|
||||
fi
|
||||
export CC_FOR_TARGET=${MYDIR}/build/ndk-386/bin/i686-linux-android-gcc
|
||||
export CXX_FOR_TARGET=${MYDIR}/build/ndk-386/bin/i686-linux-android-g++
|
||||
export CGO_ENABLED=1
|
||||
export GOOS=android
|
||||
export GOARCH=386
|
||||
export GO386=387
|
||||
;;
|
||||
amd64)
|
||||
if [ ! -d "${MYDIR}/build/ndk-$1" ]; then
|
||||
sh ${ANDROID_NDK}/build/tools/make-standalone-toolchain.sh --platform=android-21 --toolchain=x86_64-4.9 --install-dir=${MYDIR}/build/ndk-$1
|
||||
fi
|
||||
export CC_FOR_TARGET=${MYDIR}/build/ndk-amd64/bin/x86_64-linux-android-gcc
|
||||
export CXX_FOR_TARGET=${MYDIR}/build/ndk-amd64/bin/x86_64-linux-android-g++
|
||||
export CGO_ENABLED=1
|
||||
export GOOS=android
|
||||
export GOARCH=amd64
|
||||
;;
|
||||
*)
|
||||
echo "Must specify either arm or 386 or amd64"
|
||||
exit 1
|
||||
esac
|
||||
|
||||
#TODO figure out why --depth 1 never works right
|
||||
if [ $RESET -eq 1 ]; then
|
||||
git submodule update --init ext/golang/go
|
||||
fi
|
||||
|
||||
unset GOPATH
|
||||
|
||||
export GOROOT_FINAL=${MYDIR}/ext/golang/dist/go-${GOOS}-${GOARCH}
|
||||
|
||||
if [ -d "$GOROOT_FINAL" ]; then
|
||||
rm -r "$GOROOT_FINAL"
|
||||
fi
|
||||
mkdir -p "$GOROOT_FINAL"
|
||||
|
||||
pushd ext/golang/go/src
|
||||
|
||||
if [ "$GOARCH" = "386" ]; then
|
||||
git am -3 ../../../patches/golang/386/*
|
||||
fi
|
||||
|
||||
set +e
|
||||
./clean.bash
|
||||
rm -r ../bin
|
||||
rm -r ../pkg
|
||||
set -e
|
||||
|
||||
if [ ! -e ../VERSION ]; then
|
||||
echo "$(git describe --tags)" > ../VERSION
|
||||
fi
|
||||
|
||||
./make.bash --no-banner
|
||||
cp -a ../bin "${GOROOT_FINAL}"/
|
||||
cp -a ../pkg "${GOROOT_FINAL}"/
|
||||
cp -a ../src "${GOROOT_FINAL}"/
|
||||
|
||||
if [[ $RESET -eq 1 && -e ./make.bash ]]; then
|
||||
pushd ../
|
||||
git clean -f
|
||||
popd
|
||||
fi
|
||||
|
||||
popd
|
||||
|
||||
if [ $RESET -eq 1 ]; then
|
||||
git submodule update --init ext/golang/go
|
||||
fi
|
||||
|
||||
echo "Complete"
|
||||
|
96
make-syncthing.bash
Executable file
96
make-syncthing.bash
Executable file
|
@ -0,0 +1,96 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
|
||||
RESET=1
|
||||
|
||||
MYDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
if [ -z "$ANDROID_NDK" ]; then
|
||||
echo "Error: unspecified ANDROID_NDK"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
case "$1" in
|
||||
arm)
|
||||
if [ ! -d "${MYDIR}/build/ndk-$1" ]; then
|
||||
sh ${ANDROID_NDK}/build/tools/make-standalone-toolchain.sh --platform=android-9 --toolchain=arm-linux-androideabi-4.9 --install-dir=${MYDIR}/build/ndk-$1
|
||||
fi
|
||||
export CC=${MYDIR}/build/ndk-$1/bin/arm-linux-androideabi-gcc
|
||||
export CXX=${MYDIR}/build/ndk-$1/bin/arm-linux-androideabi-g++
|
||||
export CGO_ENABLED=1
|
||||
export GOOS=android
|
||||
export GOARCH=arm
|
||||
export GOARM=5
|
||||
export TARGETDIR=${MYDIR}/libs/armeabi
|
||||
;;
|
||||
386)
|
||||
if [ ! -d "${MYDIR}/build/ndk-$1" ]; then
|
||||
sh ${ANDROID_NDK}/build/tools/make-standalone-toolchain.sh --platform=android-9 --toolchain=x86-4.9 --install-dir=${MYDIR}/build/ndk-$1
|
||||
fi
|
||||
export CC_FOR_TARGET=${MYDIR}/build/ndk-$1/bin/i686-linux-android-gcc
|
||||
export CXX_FOR_TARGET=${MYDIR}/build/ndk-$1/bin/i686-linux-android-g++
|
||||
export CGO_ENABLED=1
|
||||
export GOOS=android
|
||||
export GOARCH=386
|
||||
export GO386=387
|
||||
export TARGETDIR=${MYDIR}/libs/x86
|
||||
;;
|
||||
amd64)
|
||||
if [ ! -d "${MYDIR}/build/ndk-$1" ]; then
|
||||
sh ${ANDROID_NDK}/build/tools/make-standalone-toolchain.sh --platform=android-9 --toolchain=x86_64-4.9 --install-dir=${MYDIR}/build/ndk-$1
|
||||
fi
|
||||
export CC_FOR_TARGET=${MYDIR}/build/ndk-$1/bin/x86_64-linux-android-gcc
|
||||
export CXX_FOR_TARGET=${MYDIR}/build/ndk-$1/bin/x86_64-linux-android-g++
|
||||
export CGO_ENABLED=1
|
||||
export GOOS=android
|
||||
export GOARCH=amd64
|
||||
export TARGETDIR=${MYDIR}/libs/x86_64
|
||||
;;
|
||||
*)
|
||||
echo "Must specify either arm or 386 or amd64"
|
||||
exit 1
|
||||
esac
|
||||
|
||||
unset GOPATH #Set by build.go
|
||||
export GOROOT=${MYDIR}/ext/golang/dist/go-${GOOS}-${GOARCH}
|
||||
export PATH=${GOROOT}/bin:${PATH}
|
||||
|
||||
if [ ! -x ${GOROOT}/bin/${GOOS}_${GOARCH}/go ]; then
|
||||
echo Need to build go for ${GOOS}-${GOARCH}
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ $RESET -eq 1 ]; then
|
||||
git submodule update --init ext/syncthing/src/github.com/syncthing/syncthing
|
||||
fi
|
||||
|
||||
pushd ext/syncthing/src/github.com/syncthing/syncthing
|
||||
|
||||
_GOOS=$GOOS
|
||||
unset GOOS
|
||||
_GOARCH=$GOARCH
|
||||
unset GOARCH
|
||||
|
||||
go run build.go -goos=${_GOOS} -goarch=${_GOARCH} clean
|
||||
go run build.go -goos=${_GOOS} -goarch=${_GOARCH} -no-upgrade build
|
||||
|
||||
export GOOS=$_GOOS
|
||||
export GOARCH=$_GOARCH
|
||||
|
||||
mkdir -p ${TARGETDIR}
|
||||
mv syncthing ${TARGETDIR}/libsyncthing.so
|
||||
chmod 644 ${TARGETDIR}/libsyncthing.so
|
||||
|
||||
if [[ RESET -eq 1 && -e ./build.go ]]; then
|
||||
git clean -f
|
||||
fi
|
||||
|
||||
popd
|
||||
|
||||
if [ $RESET -eq 1 ]; then
|
||||
git submodule update --init ext/syncthing/src/github.com/syncthing/syncthing
|
||||
fi
|
||||
|
||||
echo "Build Complete"
|
||||
|
Loading…
Reference in a new issue