From 0fa3fe3d435e694c7818ddaca8f755a47d9745cd Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Sun, 29 Mar 2020 02:28:41 -0600 Subject: tunnel: libwg-go: stick go tarball in gradle cache This way we don't have to build over and over. Signed-off-by: Jason A. Donenfeld --- tunnel/build.gradle | 4 ++-- tunnel/tools/CMakeLists.txt | 1 + tunnel/tools/libwg-go/Makefile | 20 +++++++++++++++----- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/tunnel/build.gradle b/tunnel/build.gradle index 2f5835c1..a2cc73e0 100644 --- a/tunnel/build.gradle +++ b/tunnel/build.gradle @@ -30,14 +30,14 @@ android { release { externalNativeBuild { cmake { - arguments "-DANDROID_PACKAGE_NAME=${groupName}" + arguments "-DANDROID_PACKAGE_NAME=${groupName}", "-DGRADLE_USER_HOME=${project.gradle.gradleUserHomeDir}" } } } debug { externalNativeBuild { cmake { - arguments "-DANDROID_PACKAGE_NAME=${groupName}.debug" + arguments "-DANDROID_PACKAGE_NAME=${groupName}.debug", "-DGRADLE_USER_HOME=${project.gradle.gradleUserHomeDir}" } } } diff --git a/tunnel/tools/CMakeLists.txt b/tunnel/tools/CMakeLists.txt index 90e61a06..91b28534 100644 --- a/tunnel/tools/CMakeLists.txt +++ b/tunnel/tools/CMakeLists.txt @@ -24,6 +24,7 @@ add_custom_target(libwg-go.so WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/lib ANDROID_LLVM_TRIPLE=${ANDROID_LLVM_TRIPLE} ANDROID_SYSROOT=${ANDROID_SYSROOT} ANDROID_PACKAGE_NAME=${ANDROID_PACKAGE_NAME} + GRADLE_USER_HOME=${GRADLE_USER_HOME} CFLAGS=${CMAKE_C_FLAGS}\ -Wno-unused-command-line-argument LDFLAGS=${CMAKE_SHARED_LINKER_FLAGS}\ -fuse-ld=gold DESTDIR=${CMAKE_LIBRARY_OUTPUT_DIRECTORY} diff --git a/tunnel/tools/libwg-go/Makefile b/tunnel/tools/libwg-go/Makefile index 6c2d25b5..f4abca5f 100644 --- a/tunnel/tools/libwg-go/Makefile +++ b/tunnel/tools/libwg-go/Makefile @@ -20,18 +20,28 @@ export GOARCH := $(NDK_GO_ARCH_MAP_$(ANDROID_ARCH_NAME)) export GOOS := android export CGO_ENABLED := 1 -DESIRED_GO_VERSION := 1.14.1 +GO_VERSION := 1.14.1 +GO_TARBALL := go$(GO_VERSION).$(shell uname -s | tr '[:upper:]' '[:lower:]')-$(NDK_GO_ARCH_MAP_$(shell uname -m)).tar.gz default: $(DESTDIR)/libwg-go.so -$(BUILDDIR)/go-$(DESIRED_GO_VERSION)/.prepared: +$(GRADLE_USER_HOME)/caches/golang/$(GO_TARBALL): mkdir -p "$(dir $@)" flock -x "$@.lock" -c ' \ [ -f "$@" ] && exit 0; \ - curl "https://dl.google.com/go/go$(DESIRED_GO_VERSION).$(shell uname -s | tr '[:upper:]' '[:lower:]')-$(NDK_GO_ARCH_MAP_$(shell uname -m)).tar.gz" | tar -C "$(dir $@)" --strip-components=1 -xzf - && \ + curl -o "$@.tmp" "https://dl.google.com/go/$(GO_TARBALL)" && \ + mv "$@.tmp" "$@"' + +$(BUILDDIR)/go-$(GO_VERSION)/.prepared: $(GRADLE_USER_HOME)/caches/golang/$(GO_TARBALL) + mkdir -p "$(dir $@)" + flock -x "$@.lock" -c ' \ + [ -f "$@" ] && exit 0; \ + tar -C "$(dir $@)" --strip-components=1 -xzf "$^" && \ patch -p1 -f -N -r- -d "$(dir $@)" < goruntime-boottime-over-monotonic.diff && \ touch "$@"' -$(DESTDIR)/libwg-go.so: export PATH := $(BUILDDIR)/go-$(DESIRED_GO_VERSION)/bin/:$(PATH) -$(DESTDIR)/libwg-go.so: $(BUILDDIR)/go-$(DESIRED_GO_VERSION)/.prepared go.mod +$(DESTDIR)/libwg-go.so: export PATH := $(BUILDDIR)/go-$(GO_VERSION)/bin/:$(PATH) +$(DESTDIR)/libwg-go.so: $(BUILDDIR)/go-$(GO_VERSION)/.prepared go.mod go build -tags linux -ldflags="-X golang.zx2c4.com/wireguard/ipc.socketDirectory=/data/data/$(ANDROID_PACKAGE_NAME)/cache/wireguard" -v -trimpath -o "$@" -buildmode c-shared + +.DELETE_ON_ERROR: -- cgit v1.2.3