Skip to content

Commit

Permalink
Build supervisor with xgo
Browse files Browse the repository at this point in the history
  • Loading branch information
zolia committed Jun 1, 2020
1 parent 9116684 commit 81ab26e
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 4 deletions.
57 changes: 57 additions & 0 deletions bin/build_supervisor_xgo
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/bash

# Usage:
#> bin/build_supervisor_xgo <os>/<arch>..
#
# Cross compile (Unix):
#> bin/build_supervisor_xgo linux/amd64
#
# Cross compile (OSX + Windows):
#> bin/build_supervisor_xgo darwin/amd64 windows/amd64
#
# Check if program has dynamic libraries:
#> brew install readelf
#> readelf -d build/node/mysterium_node

set -e
source bin/helpers/functions.sh
source bin/helpers/output.sh

XGO_TARGETS=`IFS=','; echo "$*"`
if [ -z "$XGO_TARGETS" ]; then
print_error "Missing targets!"
exit 1
fi

DIR_BUILD="build/myst_supervisor"
mkdir -p ${DIR_BUILD}
DIR_TEMP=`mktemp -d ${DIR_BUILD}/${tempname}.XXXXXX`

IMAGE="mysteriumnetwork/xgo:1.13.8"
if [[ $XGO_TARGETS == windows* ]]
then
IMAGE="mysteriumnetwork/xgo:windows-0.0.1-go-1.13.6"
fi

docker run --rm \
-v "$PWD"/$DIR_TEMP:/build \
-v "$GOPATH"/xgo-cache:/deps-cache:ro \
-v "$PWD":/source \
-e OUT=myst_supervisor \
-e FLAG_V=false \
-e FLAG_X=false \
-e FLAG_RACE=false \
-e FLAG_LDFLAGS="-w -s $(get_linker_ldflags)" \
-e FLAG_BUILDMODE=default \
-e TARGETS="$XGO_TARGETS" \
"$IMAGE" ./cmd/supervisor

# Remove version from binary name:
# - myst_supervisor-darwin-10.6-amd64 -> myst_supervisor_darwin_amd64
# - myst_supervisor-linux-amd64 -> myst_supervisor_linux_amd64
for BINARY in `ls ${DIR_TEMP}`; do
BINARY_RENAMED=`echo ${BINARY} | sed -nE 's/myst_supervisor-([a-z]*)(-[0-9.]*)?-([0-z]*)(-[0-9]*)?/myst_supervisor_\1_\3/p'`
cp ${DIR_TEMP}/${BINARY} ${DIR_BUILD}/myst_supervisor
mv ${DIR_TEMP}/${BINARY} ${DIR_BUILD}/${BINARY_RENAMED}
done
rm -rf ${DIR_TEMP}
5 changes: 5 additions & 0 deletions bin/package_standalone
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ copy_config $OS $DIR_TEMP
if [ "$OS" == "windows" ]; then
cp -vp build/myst_supervisor/myst_supervisor.exe ${DIR_TEMP}/myst_supervisor.exe
else
echo "current dir: `pwd`"
echo "dir contents: `ls -la`"
echo "build dir contents: `ls -la build`"
echo "build myst dir contents: `ls -la build/myst_supervisor`"

cp -vp build/myst_supervisor/myst_supervisor ${DIR_TEMP}/myst_supervisor
fi

Expand Down
4 changes: 4 additions & 0 deletions ci/packages/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ func buildCrossBinary(os, arch string) error {
return sh.Run("bin/build_xgo", os+"/"+arch)
}

func buildSupervisorCrossBinary(os, arch string) error {
return sh.Run("bin/build_supervisor_xgo", os+"/"+arch)
}

func buildBinary(source, target string) error {
targetOS, ok := os.LookupEnv("GOOS")
if !ok {
Expand Down
7 changes: 3 additions & 4 deletions ci/packages/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"fmt"
"os"
"os/exec"
"path"
"path/filepath"
"text/template"

Expand All @@ -31,9 +30,10 @@ import (
"github.com/mysteriumnetwork/go-ci/job"
"github.com/mysteriumnetwork/go-ci/shell"
"github.com/mysteriumnetwork/go-ci/util"
"github.com/rs/zerolog/log"

"github.com/mysteriumnetwork/node/ci/storage"
"github.com/mysteriumnetwork/node/logconfig"
"github.com/rs/zerolog/log"
)

// PackageLinuxAmd64 builds and stores linux amd64 package
Expand Down Expand Up @@ -277,8 +277,7 @@ func packageStandalone(binaryPath, os, arch string) error {
if err := buildCrossBinary(os, arch); err != nil {
return err
}
err := buildBinaryFor(path.Join("cmd", "supervisor", "supervisor.go"), "myst_supervisor", os, arch)
if err != nil {
if err := buildSupervisorCrossBinary(os, arch); err != nil {
return err
}

Expand Down

0 comments on commit 81ab26e

Please sign in to comment.