diff --git a/.gitignore b/.gitignore index 2e66e21..d10fb3a 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -*.ovpn \ No newline at end of file +*.ovpn +build/ \ No newline at end of file diff --git a/build-all.sh b/build-all.sh new file mode 100755 index 0000000..b2c135f --- /dev/null +++ b/build-all.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +set -e +rm -rf openvpn3/bridge/*.a openvpn3/bridge/*.h +docker run -it --rm -v `pwd`/build:/build -w /build -v `pwd`:/go-src-root --entrypoint /go-src-root/scripts/build-on-xgo.sh karalabe/xgo-base + +#We cross compile for windows on latest ubuntu because xgo-base has older ubuntu and older mingw with windows headers which are missing +docker build -t mingw-crosscompile -f scripts/Dockerfile-mingw-ubuntu . && \ +docker run -it --rm -v `pwd`/build:/build -w /build -v `pwd`:/go-src-root --entrypoint /go-src-root/scripts/build-on-mingw.sh mingw-crosscompile diff --git a/openvpn3/bridge/copy.sh b/openvpn3/bridge/copy.sh deleted file mode 100755 index 43869ed..0000000 --- a/openvpn3/bridge/copy.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash -#Copies header ant static library from given dir -#Usage: -# ./copy.sh -cp -f $1/adapter/library.h $2/. -cp -f $1/adapter/libopenvpn3.a $2/. \ No newline at end of file diff --git a/openvpn3/bridge/libopenvpn3.a b/openvpn3/bridge/libopenvpn3.a deleted file mode 100644 index f70f26f..0000000 Binary files a/openvpn3/bridge/libopenvpn3.a and /dev/null differ diff --git a/openvpn3/bridge/libopenvpn3_darwin_amd64.a b/openvpn3/bridge/libopenvpn3_darwin_amd64.a new file mode 100644 index 0000000..531f652 Binary files /dev/null and b/openvpn3/bridge/libopenvpn3_darwin_amd64.a differ diff --git a/openvpn3/bridge/libopenvpn3_linux_amd64.a b/openvpn3/bridge/libopenvpn3_linux_amd64.a new file mode 100644 index 0000000..6d88953 Binary files /dev/null and b/openvpn3/bridge/libopenvpn3_linux_amd64.a differ diff --git a/openvpn3/bridge/libopenvpn3_windows_amd64.a b/openvpn3/bridge/libopenvpn3_windows_amd64.a new file mode 100644 index 0000000..dd581b3 Binary files /dev/null and b/openvpn3/bridge/libopenvpn3_windows_amd64.a differ diff --git a/openvpn3/session.go b/openvpn3/session.go index 99d91be..6057407 100644 --- a/openvpn3/session.go +++ b/openvpn3/session.go @@ -6,7 +6,11 @@ package openvpn3 #cgo LDFLAGS: -lstdc++ #cgo LDFLAGS: -L${SRCDIR}/bridge -#cgo LDFLAGS: -lopenvpn3 +//main lib link +//TODO reuse GOOS somehow? +#cgo darwin LDFLAGS: -lopenvpn3_darwin_amd64 +#cgo linux LDFLAGS: -lopenvpn3_linux_amd64 +#cgo windows LDFLAGS: -lopenvpn3_windows_amd64 //TODO copied from openvpnv3 lib build tool - do we really need all of this? #cgo darwin LDFLAGS: -framework Security -framework CoreFoundation -framework SystemConfiguration -framework IOKit -framework ApplicationServices diff --git a/scripts/Dockerfile-mingw-ubuntu b/scripts/Dockerfile-mingw-ubuntu new file mode 100644 index 0000000..6cba75e --- /dev/null +++ b/scripts/Dockerfile-mingw-ubuntu @@ -0,0 +1,13 @@ +FROM ubuntu:18.04 + +# Make sure apt-get is up to date and dependent packages are installed +RUN \ + apt-get update && \ + apt-get install -y automake autogen build-essential ca-certificates \ + gcc-mingw-w64 g++-mingw-w64 \ + make xz-utils cpio wget zip unzip git texinfo help2man \ + --no-install-recommends + +# Fix any stock package issues +RUN ln -s /usr/include/asm-generic /usr/include/asm +ENTRYPOINT ["/bin/bash"] diff --git a/scripts/build-on-mingw.sh b/scripts/build-on-mingw.sh new file mode 100755 index 0000000..76231a0 --- /dev/null +++ b/scripts/build-on-mingw.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +set -e + +export O3=`pwd` +export DEP_DIR=`pwd`/dep_dir +mkdir -p $DEP_DIR +export DL=/build/dls +mkdir -p $DL + +echo "Deps are in: $DEP_DIR" +echo "DLs go to: $DL" +echo "O3 is: $O3" + +/go-src-root/scripts/x-compile-windows.sh \ No newline at end of file diff --git a/scripts/build-on-xgo.sh b/scripts/build-on-xgo.sh new file mode 100755 index 0000000..169a36a --- /dev/null +++ b/scripts/build-on-xgo.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash +set -e + +. /go-src-root/scripts/helpers.sh +rm -rf core +fetch_openvpn3 + +cp -f core/adapter/library.h /go-src-root/openvpn3/bridge/. + +export O3=`pwd` +export DEP_DIR=`pwd`/dep_dir +mkdir -p $DEP_DIR +export DL=/build/dls +mkdir -p $DL + +echo "Deps are in: $DEP_DIR" +echo "DLs go to: $DL" +echo "O3 is: $O3" + +/go-src-root/scripts/x-compile-linux.sh +/go-src-root/scripts/x-compile-mac.sh \ No newline at end of file diff --git a/scripts/concat-libs.sh b/scripts/concat-libs.sh new file mode 100755 index 0000000..a023978 --- /dev/null +++ b/scripts/concat-libs.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash +set -e +#Usage ./concat-libs.sh outputlib.a +outputLib=$1 +shift + +mkdir -p objs +pushd objs + for lib in ${MORE_LIBS[@]}; do + echo "Extracting $lib" + $AR_CMD x $lib + done +popd + +$AR_CMD rc $outputLib \ + objs/*.o \ + ${@} +rm -rf objs diff --git a/scripts/helpers.sh b/scripts/helpers.sh new file mode 100755 index 0000000..c4d961c --- /dev/null +++ b/scripts/helpers.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +function fetch_openvpn3() { + git clone https://github.com/MysteriumNetwork/openvpn3.git core +} \ No newline at end of file diff --git a/scripts/x-compile-linux.sh b/scripts/x-compile-linux.sh new file mode 100755 index 0000000..c8ab27b --- /dev/null +++ b/scripts/x-compile-linux.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +set -e + +PLATFORM=linux +SCRIPTS=linux +LIBSUFFIX=linux_amd64 + +echo "Building for: $PLATFORM" + +core/scripts/$SCRIPTS/build-all + +. core/vars/setpath +. core/vars/vars-linux + +cd core/adapter +PROF=$PLATFORM MTLS=1 NOSSL=1 LZ4=1 ASIO=1 ECHO=1 CO=1 build library + +LIB_OUT="/go-src-root/openvpn3/bridge/libopenvpn3_${LIBSUFFIX}.a" +rm -rf $LIB_OUT + +libs=("$DEP_DIR/mbedtls/mbedtls-$PLATFORM/library/libmbedtls.a" \ +"$DEP_DIR/lz4/lz4-$PLATFORM/lib/liblz4.a" ) + +MORE_LIBS=${libs[@]} /go-src-root/scripts/concat-libs.sh $LIB_OUT library.o + +$RANLIB_CMD $LIB_OUT | grep -v "has no symbols" || true diff --git a/scripts/x-compile-mac.sh b/scripts/x-compile-mac.sh new file mode 100755 index 0000000..6cb3f7c --- /dev/null +++ b/scripts/x-compile-mac.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +set -e +#x-compile.sh +#where profile can be linux | osx | mingw (windows) + +PLATFORM=osx +SCRIPTS=mac +LIBSUFFIX=darwin_amd64 + +echo "Building for: $PLATFORM" + +OSX_ONLY=1 "core/scripts/$SCRIPTS/build-all" + +. core/vars/setpath + + +cd core/adapter +PROF=$PLATFORM MTLS=1 NOSSL=1 LZ4=1 ASIO=1 ECHO=1 CO=1 build library + +LIB_OUT="/go-src-root/openvpn3/bridge/libopenvpn3_${LIBSUFFIX}.a" +rm -rf $LIB_OUT + +x86_64-apple-darwin15-libtool -static -o $LIB_OUT \ + $DEP_DIR/mbedtls/mbedtls-$PLATFORM/library/libmbedtls.a \ + $DEP_DIR/lz4/lz4-$PLATFORM/lib/liblz4.a \ + library.o diff --git a/scripts/x-compile-windows.sh b/scripts/x-compile-windows.sh new file mode 100755 index 0000000..9bbd232 --- /dev/null +++ b/scripts/x-compile-windows.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash +set -e +#x-compile.sh +#where profile can be linux | osx | mingw (windows) + +PLATFORM=mingw +SCRIPTS=win +LIBSUFFIX=windows_amd64 + +echo "Building for: $PLATFORM" + +"core/scripts/$SCRIPTS/build-all" + +. core/vars/setpath +. core/vars/vars-$PLATFORM +cd core/adapter +PROF=$PLATFORM MTLS=1 NOSSL=1 LZ4=1 ASIO=1 ECHO=1 CO=1 build library + +LIB_OUT="/go-src-root/openvpn3/bridge/libopenvpn3_${LIBSUFFIX}.a" +rm -rf $LIB_OUT + +libs=("$DEP_DIR/mbedtls/mbedtls-$PLATFORM/library/libmbedtls.a" \ +"$DEP_DIR/lz4/lz4-$PLATFORM/lib/liblz4.a" ) + +MORE_LIBS=${libs[@]} /go-src-root/scripts/concat-libs.sh $LIB_OUT library.o + +$RANLIB_CMD $LIB_OUT | grep -v "has no symbols" || true