Support build targets, handle Go version limitations

This commit is contained in:
Péter Szilágyi 2015-09-14 18:02:27 +03:00
parent 921735e9a6
commit 049bbe5e88
11 changed files with 219 additions and 48 deletions

View File

@ -46,16 +46,30 @@ ENV PATH /osxcross/target/bin:$PATH
# Configure the container for Android cross compilation
ENV ANDROID_NDK_PATH http://dl.google.com/android/ndk/android-ndk-r10e-linux-x86_64.bin
ENV ANDROID_NDK android-ndk-r10e
ENV ANDROID_PLATROOT /usr/local/$ANDROID_NDK/platforms/
ENV ANDROID_PLATFORM android-21
ENV ANDROID_PLATROOT /usr/local/$ANDROID_NDK/platforms
ENV ANDROID_PLATFORM 21
RUN \
$FETCH $ANDROID_NDK_PATH c685e5f106f8daa9b5449d0a4f21ee8c0afcb2f6 && \
7zr x `basename $ANDROID_NDK_PATH` "$ANDROID_NDK/platforms/*/arch-arm/*" -o/usr/local > /dev/null && \
7zr x `basename $ANDROID_NDK_PATH` "$ANDROID_NDK/toolchains/arm-linux-androideabi-4.8" -o/usr/local > /dev/null && \
rm -rf `basename $ANDROID_NDK_PATH`
7zr x `basename $ANDROID_NDK_PATH` "$ANDROID_NDK/toolchains/arm-linux-androideabi-4.9" -o/usr/local > /dev/null && \
rm -f `basename $ANDROID_NDK_PATH`
ENV PATH /usr/local/$ANDROID_NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin:$PATH
# Add these back as further Android support is added to Go
#7zr x `basename $ANDROID_NDK_PATH` "$ANDROID_NDK/toolchains/x86-4.9" -o/usr/local > /dev/null && \
#7zr x `basename $ANDROID_NDK_PATH` "$ANDROID_NDK/toolchains/mipsel-linux-android-4.9" -o/usr/local > /dev/null && \
#7zr x `basename $ANDROID_NDK_PATH` "$ANDROID_NDK/toolchains/aarch64-linux-android-4.9" -o/usr/local > /dev/null && \
#7zr x `basename $ANDROID_NDK_PATH` "$ANDROID_NDK/toolchains/x86_64-4.9" -o/usr/local > /dev/null && \
#7zr x `basename $ANDROID_NDK_PATH` "$ANDROID_NDK/toolchains/mips64el-linux-android-4.9" -o/usr/local > /dev/null && \
ENV PATH /usr/local/$ANDROID_NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin:$PATH
# Add these back as further Android support is added to Go
# ENV PATH /usr/local/$ANDROID_NDK/toolchains/x86-4.9/prebuilt/linux-x86_64/bin:$PATH
# ENV PATH /usr/local/$ANDROID_NDK/toolchains/mipsel-linux-android-4.9/prebuilt/linux-x86_64/bin:$PATH
# ENV PATH /usr/local/$ANDROID_NDK/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin:$PATH
# ENV PATH /usr/local/$ANDROID_NDK/toolchains/x86_64-4.9/prebuilt/linux-x86_64/bin:$PATH
# ENV PATH /usr/local/$ANDROID_NDK/toolchains/mips64el-linux-android-4.9/prebuilt/linux-x86_64/bin:$PATH
# Inject the old Go package downloader and tool-chain bootstrapper

View File

@ -8,7 +8,7 @@
#
# Needed environment variables:
# FETCH - Remote file fetcher and checksum verifier (injected by image)
# ROOT_DIST - 64 but Linux Go binary distribution package
# ROOT_DIST - 64 bit Linux Go binary distribution package
# ROOT_DIST_SHA1 - 64 bit Linux Go distribution package checksum
set -e
@ -39,7 +39,3 @@ GOOS=darwin GOARCH=amd64 CGO_ENABLED=1 CC=o64-clang go install std
echo "Bootstrapping darwin/386..."
GOOS=darwin GOARCH=386 CGO_ENABLED=1 CC=o32-clang go install std
echo "Bootstrapping android/arm..."
SYSROOT=$ANDROID_PLATROOT/$ANDROID_PLATFORM/arch-arm
GOOS=android GOARCH=arm GOARM=7 CGO_ENABLED=1 CC=arm-linux-androideabi-gcc CGO_CFLAGS="--sysroot=$SYSROOT" CGO_LDFLAGS="--sysroot=$SYSROOT" go install std

View File

@ -13,7 +13,10 @@
# PACK - Optional sub-package, if not the import path is being built
# OUT - Optional output prefix to override the package name
# FLAG_V - Optional verbosity flag to set on the Go builder
# FLAG_X - Optional flag to print the build progress commands
# FLAG_RACE - Optional race flag to set on the Go builder
# TARGETS - Comma separated list of build targets to compile for
# GO_VERSION - Bootstrapped version of Go to disable uncupported targets
# Download the canonical import path (may fail, don't allow failures beyond)
echo "Fetching main repository $1..."
@ -61,49 +64,188 @@ if [ "$OUT" != "" ]; then
fi
if [ "$FLAG_V" == "true" ]; then V=-v; fi
if [ "$FLAG_X" == "true" ]; then X=-x; fi
if [ "$FLAG_RACE" == "true" ]; then R=-race; fi
# Build for each platform individually
echo "Compiling for android/arm..."
export ANDROID_SYSROOT=$ANDROID_PLATROOT/$ANDROID_PLATFORM/arch-arm
CC="arm-linux-androideabi-gcc --sysroot=$ANDROID_SYSROOT" HOST=arm-linux-androideabi PREFIX=$ANDROID_SYSROOT/usr $BUILD_DEPS /deps
CC=arm-linux-androideabi-gcc GOOS=android GOARCH=arm GOARM=7 CGO_ENABLED=1 CGO_CFLAGS="--sysroot=$ANDROID_SYSROOT" CGO_LDFLAGS="--sysroot=$ANDROID_SYSROOT" go get -v -x -d ./$PACK
CC=arm-linux-androideabi-gcc GOOS=android GOARCH=arm GOARM=7 CGO_ENABLED=1 CGO_CFLAGS="--sysroot=$ANDROID_SYSROOT" CGO_LDFLAGS="--sysroot=$ANDROID_SYSROOT" go build -v -x $V $R -o $NAME-android-arm$R ./$PACK
# If no build targets were specified, inject a catch all wildcard
if [ "$TARGETS" == "" ]; then
TARGETS="./."
fi
echo "Compiling for linux/amd64..."
HOST=x86_64-linux PREFIX=/usr/local $BUILD_DEPS /deps
GOOS=linux GOARCH=amd64 CGO_ENABLED=1 go get -d ./$PACK
GOOS=linux GOARCH=amd64 CGO_ENABLED=1 go build $V $R -o $NAME-linux-amd64$R ./$PACK
# Build for each requested platform individually
builds=0
for TARGET in $TARGETS; do
# Split the target into platform and architecture
XGOOS=`echo $TARGET | cut -d '/' -f 1`
XGOARCH=`echo $TARGET | cut -d '/' -f 2`
echo "Compiling for linux/386..."
HOST=i686-linux PREFIX=/usr/local $BUILD_DEPS /deps
GOOS=linux GOARCH=386 CGO_ENABLED=1 go get -d ./$PACK
GOOS=linux GOARCH=386 CGO_ENABLED=1 go build $V -o $NAME-linux-386 ./$PACK
# Check and build for Android targets
if ([ $XGOOS == "." ] || [[ $XGOOS == android* ]]); then
# Split the platform version and configure the linker options
PLATFORM=`echo $XGOOS | cut -d '-' -f 2`
if [ $XGOOS == "." ] || [ "$PLATFORM" == "" ] || [ "$PLATFORM" == "." ]; then
PLATFORM=$ANDROID_PLATFORM
fi
if [ "$PLATFORM" -gt 16 ]; then
CGO_CCPIE="-fPIE"
CGO_LDPIE="-fPIE"
EXT_LDPIE="-extldflags=-pie"
fi
# Iterate over the requested architectures, bootstrap and
if [ $XGOARCH == "." ] || [ $XGOARCH == "arm" ]; then
if [ "$GO_VERSION" -lt 150 ]; then
echo "Go version too low, skipping android-$PLATFORM/arm..."
else
export ANDROID_SYSROOT=$ANDROID_PLATROOT/android-$PLATFORM/arch-arm
echo "Compiling for linux/arm..."
CC=arm-linux-gnueabi-gcc HOST=arm-linux PREFIX=/usr/local/arm $BUILD_DEPS /deps
CC=arm-linux-gnueabi-gcc GOOS=linux GOARCH=arm CGO_ENABLED=1 GOARM=5 go get -d ./$PACK
CC=arm-linux-gnueabi-gcc GOOS=linux GOARCH=arm CGO_ENABLED=1 GOARM=5 go build $V -o $NAME-linux-arm ./$PACK
echo "Bootstrapping android-$PLATFORM/arm..."
CC=arm-linux-androideabi-gcc GOOS=android GOARCH=arm GOARM=7 CGO_ENABLED=1 CGO_CFLAGS="--sysroot=$ANDROID_SYSROOT $CGO_CCPIE" CGO_LDFLAGS="--sysroot=$ANDROID_SYSROOT $CGO_LDPIE" go install std
echo "Compiling for windows/amd64..."
CC=x86_64-w64-mingw32-gcc HOST=x86_64-w64-mingw32 PREFIX=/usr/x86_64-w64-mingw32 $BUILD_DEPS /deps
CC=x86_64-w64-mingw32-gcc GOOS=windows GOARCH=amd64 CGO_ENABLED=1 go get -d ./$PACK
CC=x86_64-w64-mingw32-gcc GOOS=windows GOARCH=amd64 CGO_ENABLED=1 go build $V $R -o $NAME-windows-amd64$R.exe ./$PACK
echo "Compiling for android-$PLATFORM/arm..."
CC="arm-linux-androideabi-gcc --sysroot=$ANDROID_SYSROOT" HOST=arm-linux-androideabi PREFIX=$ANDROID_SYSROOT/usr $BUILD_DEPS /deps
CC=arm-linux-androideabi-gcc GOOS=android GOARCH=arm GOARM=7 CGO_ENABLED=1 CGO_CFLAGS="--sysroot=$ANDROID_SYSROOT $CGO_CCPIE" CGO_LDFLAGS="--sysroot=$ANDROID_SYSROOT $CGO_LDPIE" go get $V $X -d ./$PACK
CC=arm-linux-androideabi-gcc GOOS=android GOARCH=arm GOARM=7 CGO_ENABLED=1 CGO_CFLAGS="--sysroot=$ANDROID_SYSROOT $CGO_CCPIE" CGO_LDFLAGS="--sysroot=$ANDROID_SYSROOT $CGO_LDPIE" go build --ldflags="$EXT_LDPIE" $V $X $R -o $NAME-android-$PLATFORM-arm$R ./$PACK
builds=$((builds+1))
fi
fi
if ([ $XGOARCH == "." ] || [ $XGOARCH == "386" ]) && [ "$PLATFORM" -ge 9 ]; then
if [ "$GO_VERSION" -lt 160 ]; then
echo "Go version too low, skipping android-$PLATFORM/386..."
else
export ANDROID_SYSROOT=$ANDROID_PLATROOT/android-$PLATFORM/arch-x86
echo "Compiling for windows/386..."
CC=i686-w64-mingw32-gcc HOST=i686-w64-mingw32 PREFIX=/usr/i686-w64-mingw32 $BUILD_DEPS /deps
CC=i686-w64-mingw32-gcc GOOS=windows GOARCH=386 CGO_ENABLED=1 go get -d ./$PACK
CC=i686-w64-mingw32-gcc GOOS=windows GOARCH=386 CGO_ENABLED=1 go build $V -o $NAME-windows-386.exe ./$PACK
echo "Bootstrapping android-$PLATFORM/386..."
CC=i686-linux-android-gcc GOOS=android GOARCH=386 CGO_ENABLED=1 CGO_CFLAGS="--sysroot=$ANDROID_SYSROOT $CGO_CCPIE" CGO_LDFLAGS="--sysroot=$ANDROID_SYSROOT $CGO_LDPIE" go install std
echo "Compiling for darwin/amd64..."
CC=o64-clang HOST=x86_64-apple-darwin10 PREFIX=/usr/local $BUILD_DEPS /deps
CC=o64-clang GOOS=darwin GOARCH=amd64 CGO_ENABLED=1 go get -d ./$PACK
CC=o64-clang GOOS=darwin GOARCH=amd64 CGO_ENABLED=1 go build -ldflags=-s $V $R -o $NAME-darwin-amd64$R ./$PACK
echo "Compiling for android-$PLATFORM/386..."
CC="i686-linux-android-gcc --sysroot=$ANDROID_SYSROOT" HOST=i686-linux-android PREFIX=$ANDROID_SYSROOT/usr $BUILD_DEPS /deps
CC=i686-linux-android-gcc GOOS=android GOARCH=386 CGO_ENABLED=1 CGO_CFLAGS="--sysroot=$ANDROID_SYSROOT $CGO_CCPIE" CGO_LDFLAGS="--sysroot=$ANDROID_SYSROOT $CGO_LDPIE" go get $V $X -d ./$PACK
CC=i686-linux-android-gcc GOOS=android GOARCH=386 CGO_ENABLED=1 CGO_CFLAGS="--sysroot=$ANDROID_SYSROOT $CGO_CCPIE" CGO_LDFLAGS="--sysroot=$ANDROID_SYSROOT $CGO_LDPIE" go build --ldflags="$EXT_LDPIE" $V $X $R -o $NAME-android-$PLATFORM-386$R ./$PACK
builds=$((builds+1))
fi
fi
if ([ $XGOARCH == "." ] || [ $XGOARCH == "mips" ]) && [ "$PLATFORM" -ge 9 ]; then
if [ "$GO_VERSION" -lt 160 ]; then
echo "Go version too low, skipping android-$PLATFORM/mips..."
else
export ANDROID_SYSROOT=$ANDROID_PLATROOT/android-$PLATFORM/arch-mips
echo "Compiling for darwin/386..."
CC=o32-clang HOST=i386-apple-darwin10 PREFIX=/usr/local $BUILD_DEPS /deps
CC=o32-clang GOOS=darwin GOARCH=386 CGO_ENABLED=1 go get -d ./$PACK
CC=o32-clang GOOS=darwin GOARCH=386 CGO_ENABLED=1 go build -ldflags=-s $V -o $NAME-darwin-386 ./$PACK
echo "Bootstrapping android-$PLATFORM/mips..."
CC==mipsel-linux-android-gcc GOOS=android GOARCH=mips CGO_ENABLED=1 CGO_CFLAGS="--sysroot=$ANDROID_SYSROOT $CGO_CCPIE" CGO_LDFLAGS="--sysroot=$ANDROID_SYSROOT $CGO_LDPIE" go install std
echo "Moving binaries to host..."
cp `ls -t | head -n 8` /build
echo "Compiling for android-$PLATFORM/mips..."
CC="mipsel-linux-android-gcc --sysroot=$ANDROID_SYSROOT" HOST=mipsel-linux-android PREFIX=$ANDROID_SYSROOT/usr $BUILD_DEPS /deps
CC=mipsel-linux-android-gcc GOOS=android GOARCH=mips CGO_ENABLED=1 CGO_CFLAGS="--sysroot=$ANDROID_SYSROOT $CGO_CCPIE" CGO_LDFLAGS="--sysroot=$ANDROID_SYSROOT $CGO_LDPIE" go get $V $X -d ./$PACK
CC=mipsel-linux-android-gcc GOOS=android GOARCH=mips CGO_ENABLED=1 CGO_CFLAGS="--sysroot=$ANDROID_SYSROOT $CGO_CCPIE" CGO_LDFLAGS="--sysroot=$ANDROID_SYSROOT $CGO_LDPIE" go build --ldflags="$EXT_LDPIE" $V $X $R -o $NAME-android-$PLATFORM-mips$R ./$PACK
builds=$((builds+1))
fi
fi
if ([ $XGOARCH == "." ] || [ $XGOARCH == "arm64" ]) && [ "$PLATFORM" -ge 21 ]; then
if [ "$GO_VERSION" -lt 160 ]; then
echo "Go version too low, skipping android-$PLATFORM/arm64..."
else
export ANDROID_SYSROOT=$ANDROID_PLATROOT/android-$PLATFORM/arch-arm64
echo "Bootstrapping android-$PLATFORM/arm64..."
CC===aarch64-linux-android-gcc GOOS=android GOARCH=arm GOARM=7 CGO_ENABLED=1 CGO_CFLAGS="--sysroot=$ANDROID_SYSROOT $CGO_CCPIE" CGO_LDFLAGS="--sysroot=$ANDROID_SYSROOT $CGO_LDPIE" go install std
echo "Compiling for android-$PLATFORM/arm64..."
CC="aarch64-linux-android-gcc --sysroot=$ANDROID_SYSROOT" HOST=aarch64-linux-android PREFIX=$ANDROID_SYSROOT/usr $BUILD_DEPS /deps
CC=aarch64-linux-android-gcc GOOS=android GOARCH=arm64 GOARM=7 CGO_ENABLED=1 CGO_CFLAGS="--sysroot=$ANDROID_SYSROOT $CGO_CCPIE" CGO_LDFLAGS="--sysroot=$ANDROID_SYSROOT $CGO_LDPIE" go get $V $X -d ./$PACK
CC=aarch64-linux-android-gcc GOOS=android GOARCH=arm64 GOARM=7 CGO_ENABLED=1 CGO_CFLAGS="--sysroot=$ANDROID_SYSROOT $CGO_CCPIE" CGO_LDFLAGS="--sysroot=$ANDROID_SYSROOT $CGO_LDPIE" go build --ldflags="$EXT_LDPIE" $V $X $R -o $NAME-android-$PLATFORM-arm64$R ./$PACK
builds=$((builds+1))
fi
fi
if ([ $XGOARCH == "." ] || [ $XGOARCH == "amd64" ]) && [ "$PLATFORM" -ge 21 ]; then
if [ "$GO_VERSION" -lt 160 ]; then
echo "Go version too low, skipping android-$PLATFORM/amd64..."
else
export ANDROID_SYSROOT=$ANDROID_PLATROOT/android-$PLATFORM/arch-x86_64
echo "Bootstrapping android-$PLATFORM/amd64..."
CC=x86_64-linux-android-gcc GOOS=android GOARCH=amd64 CGO_ENABLED=1 CGO_CFLAGS="--sysroot=$ANDROID_SYSROOT $CGO_CCPIE" CGO_LDFLAGS="--sysroot=$ANDROID_SYSROOT $CGO_LDPIE" go install std
echo "Compiling for android-$PLATFORM/amd64..."
CC="x86_64-linux-android-gcc --sysroot=$ANDROID_SYSROOT" HOST=x86_64-linux-android PREFIX=$ANDROID_SYSROOT/usr $BUILD_DEPS /deps
CC=x86_64-linux-android-gcc GOOS=android GOARCH=amd64 CGO_ENABLED=1 CGO_CFLAGS="--sysroot=$ANDROID_SYSROOT $CGO_CCPIE" CGO_LDFLAGS="--sysroot=$ANDROID_SYSROOT $CGO_LDPIE" go get $V $X -d ./$PACK
CC=x86_64-linux-android-gcc GOOS=android GOARCH=amd64 CGO_ENABLED=1 CGO_CFLAGS="--sysroot=$ANDROID_SYSROOT $CGO_CCPIE" CGO_LDFLAGS="--sysroot=$ANDROID_SYSROOT $CGO_LDPIE" go build --ldflags="$EXT_LDPIE" $V $X $R -o $NAME-android-$PLATFORM-amd64$R ./$PACK
builds=$((builds+1))
fi
fi
if ([ $XGOARCH == "." ] || [ $XGOARCH == "mips64" ]) && [ "$PLATFORM" -ge 21 ]; then
if [ "$GO_VERSION" -lt 160 ]; then
echo "Go version too low, skipping android-$PLATFORM/mips64..."
else
export ANDROID_SYSROOT=$ANDROID_PLATROOT/android-$PLATFORM/arch-mips64
echo "Bootstrapping android-$PLATFORM/mips64..."
CC=mips64el-linux-android-gcc GOOS=android GOARCH=mips64 CGO_ENABLED=1 CGO_CFLAGS="--sysroot=$ANDROID_SYSROOT $CGO_CCPIE" CGO_LDFLAGS="--sysroot=$ANDROID_SYSROOT $CGO_LDPIE" go install std
echo "Compiling for android-$PLATFORM/mips64..."
CC="mips64el-linux-android-gcc --sysroot=$ANDROID_SYSROOT" HOST=mips64el-linux-android PREFIX=$ANDROID_SYSROOT/usr $BUILD_DEPS /deps
CC=mips64el-linux-android-gcc GOOS=android GOARCH=mips64 CGO_ENABLED=1 CGO_CFLAGS="--sysroot=$ANDROID_SYSROOT $CGO_CCPIE" CGO_LDFLAGS="--sysroot=$ANDROID_SYSROOT $CGO_LDPIE" go get $V $X -d ./$PACK
CC=mips64el-linux-android-gcc GOOS=android GOARCH=mips64 CGO_ENABLED=1 CGO_CFLAGS="--sysroot=$ANDROID_SYSROOT $CGO_CCPIE" CGO_LDFLAGS="--sysroot=$ANDROID_SYSROOT $CGO_LDPIE" go build --ldflags="$EXT_LDPIE" $V $X $R -o $NAME-android-$PLATFORM-mips64$R ./$PACK
builds=$((builds+1))
fi
fi
fi
# Check and build for Linux targets
if ([ $XGOOS == "." ] || [ $XGOOS == "linux" ]) && ([ $XGOARCH == "." ] || [ $XGOARCH == "amd64" ]); then
echo "Compiling for linux/amd64..."
HOST=x86_64-linux PREFIX=/usr/local $BUILD_DEPS /deps
GOOS=linux GOARCH=amd64 CGO_ENABLED=1 go get $V $X -d ./$PACK
GOOS=linux GOARCH=amd64 CGO_ENABLED=1 go build $V $X $R -o $NAME-linux-amd64$R ./$PACK
builds=$((builds+1))
fi
if ([ $XGOOS == "." ] || [ $XGOOS == "linux" ]) && ([ $XGOARCH == "." ] || [ $XGOARCH == "386" ]); then
echo "Compiling for linux/386..."
HOST=i686-linux PREFIX=/usr/local $BUILD_DEPS /deps
GOOS=linux GOARCH=386 CGO_ENABLED=1 go get $V $X -d ./$PACK
GOOS=linux GOARCH=386 CGO_ENABLED=1 go build $V $X -o $NAME-linux-386 ./$PACK
builds=$((builds+1))
fi
if ([ $XGOOS == "." ] || [ $XGOOS == "linux" ]) && ([ $XGOARCH == "." ] || [ $XGOARCH == "arm" ]); then
echo "Compiling for linux/arm..."
CC=arm-linux-gnueabi-gcc HOST=arm-linux PREFIX=/usr/local/arm $BUILD_DEPS /deps
CC=arm-linux-gnueabi-gcc GOOS=linux GOARCH=arm CGO_ENABLED=1 GOARM=5 go get $V $X -d ./$PACK
CC=arm-linux-gnueabi-gcc GOOS=linux GOARCH=arm CGO_ENABLED=1 GOARM=5 go build $V $X -o $NAME-linux-arm ./$PACK
builds=$((builds+1))
fi
# Check and build for Windows targets
if ([ $XGOOS == "." ] || [ $XGOOS == "windows" ]) && ([ $XGOARCH == "." ] || [ $XGOARCH == "amd64" ]); then
echo "Compiling for windows/amd64..."
CC=x86_64-w64-mingw32-gcc HOST=x86_64-w64-mingw32 PREFIX=/usr/x86_64-w64-mingw32 $BUILD_DEPS /deps
CC=x86_64-w64-mingw32-gcc GOOS=windows GOARCH=amd64 CGO_ENABLED=1 go get $V $X -d ./$PACK
CC=x86_64-w64-mingw32-gcc GOOS=windows GOARCH=amd64 CGO_ENABLED=1 go build $V $X $R -o $NAME-windows-amd64$R.exe ./$PACK
builds=$((builds+1))
fi
if ([ $XGOOS == "." ] || [ $XGOOS == "windows" ]) && ([ $XGOARCH == "." ] || [ $XGOARCH == "386" ]); then
echo "Compiling for windows/386..."
CC=i686-w64-mingw32-gcc HOST=i686-w64-mingw32 PREFIX=/usr/i686-w64-mingw32 $BUILD_DEPS /deps
CC=i686-w64-mingw32-gcc GOOS=windows GOARCH=386 CGO_ENABLED=1 go get $V $X -d ./$PACK
CC=i686-w64-mingw32-gcc GOOS=windows GOARCH=386 CGO_ENABLED=1 go build $V $X -o $NAME-windows-386.exe ./$PACK
builds=$((builds+1))
fi
# Check and build for OSX targets
if ([ $XGOOS == "." ] || [ $XGOOS == "darwin" ]) && ([ $XGOARCH == "." ] || [ $XGOARCH == "amd64" ]); then
echo "Compiling for darwin/amd64..."
CC=o64-clang HOST=x86_64-apple-darwin10 PREFIX=/usr/local $BUILD_DEPS /deps
CC=o64-clang GOOS=darwin GOARCH=amd64 CGO_ENABLED=1 go get $V $X -d ./$PACK
CC=o64-clang GOOS=darwin GOARCH=amd64 CGO_ENABLED=1 go build -ldflags=-s $V $X $R -o $NAME-darwin-amd64$R ./$PACK
builds=$((builds+1))
fi
if ([ $XGOOS == "." ] || [ $XGOOS == "darwin" ]) && ([ $XGOARCH == "." ] || [ $XGOARCH == "386" ]); then
echo "Compiling for darwin/386..."
CC=o32-clang HOST=i386-apple-darwin10 PREFIX=/usr/local $BUILD_DEPS /deps
CC=o32-clang GOOS=darwin GOARCH=386 CGO_ENABLED=1 go get $V $X -d ./$PACK
CC=o32-clang GOOS=darwin GOARCH=386 CGO_ENABLED=1 go build -ldflags=-s $V $X -o $NAME-darwin-386 ./$PACK
builds=$((builds+1))
fi
done
if [ "$builds" -eq 0 ]; then
echo "No build targets matched!"
else
echo "Moving $builds binaries to host..."
cp `ls -t | head -n $builds` /build
fi

View File

@ -31,3 +31,5 @@ RUN \
export DIST_WIN_32_SHA1=e4e5279ce7d8cafdf210a522a70677d5b9c7589d && \
\
$BOOTSTRAP
ENV GO_VERSION 130

View File

@ -31,3 +31,5 @@ RUN \
export DIST_WIN_32_SHA1=64f99e40e79e93a622e73d7d55a5b8340f07747f && \
\
$BOOTSTRAP
ENV GO_VERSION 131

View File

@ -31,3 +31,5 @@ RUN \
export DIST_WIN_32_SHA1=ba99083b22e0b22b560bb2d28b9b99b405d01b6b && \
\
$BOOTSTRAP
ENV GO_VERSION 133

View File

@ -31,3 +31,5 @@ RUN \
export DIST_WIN_32_SHA1=0e074e66a7816561d7947ff5c3514be96f347dc4 && \
\
$BOOTSTRAP
ENV GO_VERSION 142

View File

@ -31,3 +31,5 @@ RUN \
export DIST_WIN_32_SHA1=f44240a1750dd051476ae78e9ad0502bc5c7661d && \
\
$BOOTSTRAP
ENV GO_VERSION 140

View File

@ -13,3 +13,5 @@ RUN \
export ROOT_DIST_SHA1=5817fa4b2252afdb02e11e8b9dc1d9173ef3bd5a && \
\
$BOOTSTRAP_PURE
ENV GO_VERSION 150

View File

@ -13,3 +13,5 @@ RUN \
export ROOT_DIST_SHA1=46eecd290d8803887dec718c691cc243f2175fe0 && \
\
$BOOTSTRAP_PURE
ENV GO_VERSION 151

9
xgo.go
View File

@ -13,6 +13,7 @@ import (
"log"
"os"
"os/exec"
"strings"
)
// Cross compilation docker containers
@ -26,9 +27,11 @@ var outPrefix = flag.String("out", "", "Prefix to use for output naming (empty =
var srcRemote = flag.String("remote", "", "Version control remote repository to build")
var srcBranch = flag.String("branch", "", "Version control branch to build")
var crossDeps = flag.String("deps", "", "CGO dependencies (configure/make based archives)")
var targets = flag.String("targets", "*/*", "Comma separated targets to build for")
// Command line arguments to pass to go build
var buildVerbose = flag.Bool("v", false, "Print the names of packages as they are compiled")
var buildSteps = flag.Bool("x", false, "Print the command as executing the builds")
var buildRace = flag.Bool("race", false, "Enable data race detection (supported only on amd64)")
func main() {
@ -56,7 +59,7 @@ func main() {
fmt.Println("found.")
}
// Cross compile the requested package into the local folder
if err := compile(flag.Args()[0], *srcRemote, *srcBranch, *inPackage, *crossDeps, *outPrefix, *buildVerbose, *buildRace); err != nil {
if err := compile(flag.Args()[0], *srcRemote, *srcBranch, *inPackage, *crossDeps, *outPrefix, *buildVerbose, *buildSteps, *buildRace, strings.Split(*targets, ",")); err != nil {
log.Fatalf("Failed to cross compile package: %v.", err)
}
}
@ -88,7 +91,7 @@ func pullDockerImage(image string) error {
}
// Cross compiles a requested package into the current working directory.
func compile(repo string, remote string, branch string, pack string, deps string, prefix string, verbose bool, race bool) error {
func compile(repo string, remote string, branch string, pack string, deps string, prefix string, verbose bool, steps bool, race bool, targets []string) error {
folder, err := os.Getwd()
if err != nil {
log.Fatalf("Failed to retrieve the working directory: %v.", err)
@ -102,7 +105,9 @@ func compile(repo string, remote string, branch string, pack string, deps string
"-e", "DEPS="+deps,
"-e", "OUT="+prefix,
"-e", fmt.Sprintf("FLAG_V=%v", verbose),
"-e", fmt.Sprintf("FLAG_X=%v", steps),
"-e", fmt.Sprintf("FLAG_RACE=%v", race),
"-e", "TARGETS="+strings.Replace(strings.Join(targets, " "), "*", ".", -1),
dockerDist+*goVersion, repo))
}