libwg-go: use gopath

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Jason A. Donenfeld 2018-05-23 03:52:26 +02:00
parent a533be82e8
commit 62dbeca732
7 changed files with 46 additions and 33 deletions

View File

@ -1,7 +1,2 @@
go/ src/
*.go
libwg-go.h
jni.o
gopath/
goroot/
.gobuildversion .gobuildversion

View File

@ -11,7 +11,6 @@ NDK_GO_ARCH_MAP_arm64 := arm64
NDK_GO_ARCH_MAP_mips := mipsx NDK_GO_ARCH_MAP_mips := mipsx
NDK_GO_ARCH_MAP_mips64 := mips64x NDK_GO_ARCH_MAP_mips64 := mips64x
export GOPATH := $(CURDIR)/gopath
CLANG_FLAGS := --target=$(ANDROID_LLVM_TRIPLE) --gcc-toolchain=$(ANDROID_TOOLCHAIN_ROOT) --sysroot=$(ANDROID_SYSROOT) CLANG_FLAGS := --target=$(ANDROID_LLVM_TRIPLE) --gcc-toolchain=$(ANDROID_TOOLCHAIN_ROOT) --sysroot=$(ANDROID_SYSROOT)
export CGO_CFLAGS := $(CLANG_FLAGS) $(CFLAGS) export CGO_CFLAGS := $(CLANG_FLAGS) $(CFLAGS)
export CGO_LDFLAGS := $(CLANG_FLAGS) $(LDFLAGS) export CGO_LDFLAGS := $(CLANG_FLAGS) $(LDFLAGS)
@ -48,12 +47,12 @@ endif
$(shell test "$$(cat .gobuildversion 2>/dev/null)" = "$(GOBUILDVERSION_CURRENT)" || rm -f "$(DESTDIR)/libwg-go.so") $(shell test "$$(cat .gobuildversion 2>/dev/null)" = "$(GOBUILDVERSION_CURRENT)" || rm -f "$(DESTDIR)/libwg-go.so")
$(DESTDIR)/libwg-go.so: $(FILES) api-android.go jni.c $(DESTDIR)/libwg-go.so: $(FILES) src/git.zx2c4.com/wireguard-go/api-android.go src/git.zx2c4.com/wireguard-go/tun/api-android.go src/git.zx2c4.com/wireguard-go/jni.c
find . -name '*.go' -type l -delete find . -name '*.go' -type l -delete
find . -type d -empty -delete find . -type d -empty -delete
mkdir -p $(subst ../wireguard-go/,./,$(dir $(FILES))) mkdir -p $(subst ../wireguard-go/,./src/git.zx2c4.com/wireguard-go/,$(dir $(FILES)))
$(foreach FILE,$(FILES),ln -sfrt $(subst ../wireguard-go/,./,$(dir $(FILE))) $(FILE);) $(foreach FILE,$(FILES),ln -sfrt $(subst ../wireguard-go/,./src/git.zx2c4.com/wireguard-go/,$(dir $(FILE))) $(FILE);)
patch -p1 -f -R -s --dry-run -d"$$(go env GOROOT)" < goruntime-boottime-over-monotonic.diff patch -p1 -f -R -s --dry-run -d"$$(go env GOROOT)" < goruntime-boottime-over-monotonic.diff
go get -v -d GOPATH=$(PWD) go get -v -d git.zx2c4.com/wireguard-go
go build -v -o $(DESTDIR)/libwg-go.so -buildmode c-shared GOPATH=$(PWD) go build -v -o $(DESTDIR)/libwg-go.so -buildmode c-shared git.zx2c4.com/wireguard-go
go version > .gobuildversion go version > .gobuildversion

View File

@ -10,8 +10,8 @@ package main
import "C" import "C"
import ( import (
"./rwcancel"
"bufio" "bufio"
"git.zx2c4.com/wireguard-go/tun"
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
"io/ioutil" "io/ioutil"
"log" "log"
@ -64,28 +64,16 @@ func wgTurnOn(ifnameRef string, tun_fd int32, settings string) int32 {
logger.Debug.Println("Debug log enabled") logger.Debug.Println("Debug log enabled")
tun := &NativeTun{ tun, name, err := tun.CreateTUNFromFD(int(tun_fd))
fd: os.NewFile(uintptr(tun_fd), "/dev/tun"), if err != nil {
events: make(chan TUNEvent, 5), unix.Close(int(tun_fd))
errors: make(chan error, 5), logger.Error.Println(err)
nopi: true, return -1
} }
var err error
tun.fdCancel, err = rwcancel.NewRWCancel(int(tun_fd))
if err != nil {
unix.Close(int(tun_fd))
logger.Error.Println(err)
return -1
}
name, err := tun.Name()
if err != nil {
unix.Close(int(tun_fd))
logger.Error.Println(err)
return -1
}
logger.Info.Println("Attaching to interface", name) logger.Info.Println("Attaching to interface", name)
device := NewDevice(tun, logger) device := NewDevice(tun, logger)
logger.Debug.Println("Interface has MTU", device.tun.mtu) logger.Debug.Println("Interface has MTU", device.tun.mtu)
bufferedSettings := bufio.NewReadWriter(bufio.NewReader(strings.NewReader(settings)), bufio.NewWriter(ioutil.Discard)) bufferedSettings := bufio.NewReadWriter(bufio.NewReader(strings.NewReader(settings)), bufio.NewWriter(ioutil.Discard))

View File

@ -0,0 +1,31 @@
/* SPDX-License-Identifier: GPL-2.0-or-later
*
* Copyright (C) 2017-2018 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
*/
package tun
import (
"git.zx2c4.com/wireguard-go/rwcancel"
"os"
)
func CreateTUNFromFD(tun_fd int) (TUNDevice, string, error) {
tun := &nativeTun{
fd: os.NewFile(uintptr(tun_fd), "/dev/tun"),
events: make(chan TUNEvent, 5),
errors: make(chan error, 5),
nopi: true,
}
var err error
tun.fdCancel, err = rwcancel.NewRWCancel(tun_fd)
if err != nil {
return nil, "", err
}
name, err := tun.Name()
if err != nil {
tun.fdCancel.Cancel()
return nil, "", err
}
return tun, name, nil
}

@ -1 +1 @@
Subproject commit d67d89c7f9d83d22d750452236b0e16510ab1368 Subproject commit 6977826c2c9840f79dc2ac6b4206a5f393e9dfb4

@ -1 +1 @@
Subproject commit 65a74f3175855dc41b49332103ada6bb27733291 Subproject commit 0b647d1ca7e079f3bb2fe95c3ca7c05898315a6e