Skip to content

Commit

Permalink
enable cross build
Browse files Browse the repository at this point in the history
  • Loading branch information
Daishan Peng authored and Denise committed Nov 14, 2017
1 parent 679fe51 commit 1fd6129
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions Dockerfile.dapper
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ ENV DAPPER_SOURCE /go/src/github.com/rancher/rke/
ENV DAPPER_RUN_ARGS --privileged -v /var/lib/docker
ENV DAPPER_OUTPUT ./bin ./dist
ENV DAPPER_DOCKER_SOCKET true
ENV DAPPER_ENV TAG REPO GOOS CROSS
ENV TRASH_CACHE ${DAPPER_SOURCE}/.trash-cache
ENV HOME ${DAPPER_SOURCE}
WORKDIR ${DAPPER_SOURCE}
Expand Down
22 changes: 22 additions & 0 deletions scripts/build
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,28 @@ source $(dirname $0)/version

cd $(dirname $0)/..

OS_PLATFORM_ARG=(linux darwin)
OS_ARCH_ARG[linux]="amd64 arm"
OS_ARCH_ARG[windows]="386 amd64"
OS_ARCH_ARG[darwin]="amd64"

mkdir -p bin
[ "$(uname)" != "Darwin" ] && LINKFLAGS="-linkmode external -extldflags -static -s"
CGO_ENABLED=0 go build -ldflags "-X main.VERSION=$VERSION $LINKFLAGS" -o bin/rke

if [ -n "$CROSS" ]; then
rm -rf build/bin
mkdir -p build/bin
for OS in ${OS_PLATFORM_ARG[@]}; do
for ARCH in ${OS_ARCH_ARG[${OS}]}; do
OUTPUT_BIN="build/bin/rke_$OS-$ARCH"
if test "$OS" = "windows"; then
OUTPUT_BIN="${OUTPUT_BIN}.exe"
fi
echo "Building binary for $OS/$ARCH..."
GOARCH=$ARCH GOOS=$OS CGO_ENABLED=0 go build \
-ldflags="-w -X main.VERSION=$VERSION" \
-o ${OUTPUT_BIN} ./
done
done
fi

0 comments on commit 1fd6129

Please sign in to comment.