Skip to content

Commit

Permalink
Linux and win support added (I hope)
Browse files Browse the repository at this point in the history
  • Loading branch information
tadovas committed Aug 24, 2018
1 parent 001c3ff commit 98bebcc
Show file tree
Hide file tree
Showing 16 changed files with 165 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.ovpn
*.ovpn
build/
8 changes: 8 additions & 0 deletions build-all.sh
Original file line number Diff line number Diff line change
@@ -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
6 changes: 0 additions & 6 deletions openvpn3/bridge/copy.sh

This file was deleted.

Binary file removed openvpn3/bridge/libopenvpn3.a
Binary file not shown.
Binary file added openvpn3/bridge/libopenvpn3_darwin_amd64.a
Binary file not shown.
Binary file added openvpn3/bridge/libopenvpn3_linux_amd64.a
Binary file not shown.
Binary file added openvpn3/bridge/libopenvpn3_windows_amd64.a
Binary file not shown.
6 changes: 5 additions & 1 deletion openvpn3/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions scripts/Dockerfile-mingw-ubuntu
Original file line number Diff line number Diff line change
@@ -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"]
14 changes: 14 additions & 0 deletions scripts/build-on-mingw.sh
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions scripts/build-on-xgo.sh
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions scripts/concat-libs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash
set -e
#Usage ./concat-libs.sh outputlib.a <list of o files>
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
5 changes: 5 additions & 0 deletions scripts/helpers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

function fetch_openvpn3() {
git clone https://github.com/MysteriumNetwork/openvpn3.git core
}
26 changes: 26 additions & 0 deletions scripts/x-compile-linux.sh
Original file line number Diff line number Diff line change
@@ -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
26 changes: 26 additions & 0 deletions scripts/x-compile-mac.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash
set -e
#x-compile.sh <profile>
#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
27 changes: 27 additions & 0 deletions scripts/x-compile-windows.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash
set -e
#x-compile.sh <profile>
#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

0 comments on commit 98bebcc

Please sign in to comment.