diff --git a/README.md b/README.md index 5f6fb07..77afcb9 100644 --- a/README.md +++ b/README.md @@ -179,22 +179,23 @@ argument: * `--targets=*/arm`: builds ARM binaries for all platforms * `--targets=*/*`: builds all suppoted targets (default) -The Android platform is handled a bit differently currently due to the multitude -of available platform versions (23 as of writing, some obsolted). As it is mostly -pointless to build for all possible versions, `xgo` by default builds only against -the latest release, controllable via a numerical argument after the platform: +### Platform versions - * `--targets=android-16/*`: build all supported architectures for Jelly Bean - * `--targets=android-16/arm,android-21/arm`: build for Jelly Bean and Lollipop +By default `xgo` tries to cross compile to the lowest possible versions of every +supported platform, in order to produce binaries that are portable among various +versions of the same operating system. This however can lead to issues if a used +dependency is only supported by more recent systems. As such, `xgo` supports the +selection of specific platform versions by appending them to the OS target string. -Note, `xgo` honors the Android's position independent executables (PIE) security -requirement, builing all binaries equal and above to Jelly Bean with PIE enabled. + * `--targets=android-16/*`: cross compile to Android Jelly Bean + * `--targets=darwin-10.9/*`: cross compile to Mac OS X Mavericks + * `--targets=windows-6.0/*`: cross compile to Windows Vista - $ readelf -h iris-android-15-arm | grep Type - Type: EXEC (Executable file) - $ readelf -h iris-android-21-arm | grep Type - Type: DYN (Shared object file) +The supported platforms are: + * All Android APIs up to Android Lollipop 5.0 ([API level ids](https://source.android.com/source/build-numbers.html)) + * All Windows APIs up to Windows 8.1 limited by `mingw-w64` ([API level ids](https://en.wikipedia.org/wiki/Windows_NT#Releases)) + * OSX APIs in the range of 10.6 - 10.9 ### CGO dependencies diff --git a/docker/base/build.sh b/docker/base/build.sh index ee8b9be..791307b 100644 --- a/docker/base/build.sh +++ b/docker/base/build.sh @@ -118,8 +118,8 @@ for TARGET in $TARGETS; do 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 + if [ "$PLATFORM" == "" ] || [ "$PLATFORM" == "." ] || [ "$PLATFORM" == "android" ]; then + PLATFORM=16 # Jelly Bean 4.0.0 fi if [ "$PLATFORM" -ge 16 ]; then CGO_CCPIE="-fPIE" @@ -169,46 +169,51 @@ for TARGET in $TARGETS; do if [ $XGOOS == "." ] || [[ $XGOOS == windows* ]]; then # Split the platform version and configure the Windows NT version PLATFORM=`echo $XGOOS | cut -d '-' -f 2` - if [ "$PLATFORM" != "" ] && [ "$PLATFORM" != "windows" ]; then - MAJOR=`echo $PLATFORM | cut -d '.' -f 1` - if [ "${PLATFORM/.}" != "$PLATFORM" ] ; then - MINOR=`echo $PLATFORM | cut -d '.' -f 2` - fi - CGO_NTDEF="-D_WIN32_WINNT=0x`printf "%02d" $MAJOR``printf "%02d" $MINOR`" + if [ "$PLATFORM" == "" ] || [ "$PLATFORM" == "." ] || [ "$PLATFORM" == "windows" ]; then + PLATFORM=4.0 # Windows NT fi + + MAJOR=`echo $PLATFORM | cut -d '.' -f 1` + if [ "${PLATFORM/.}" != "$PLATFORM" ] ; then + MINOR=`echo $PLATFORM | cut -d '.' -f 2` + fi + CGO_NTDEF="-D_WIN32_WINNT=0x`printf "%02d" $MAJOR``printf "%02d" $MINOR`" + # Build the requested windows binaries if [ $XGOARCH == "." ] || [ $XGOARCH == "amd64" ]; then - echo "Compiling for $XGOOS/amd64..." + echo "Compiling for windows-$PLATFORM/amd64..." CC=x86_64-w64-mingw32-gcc-posix CXX=x86_64-w64-mingw32-g++-posix HOST=x86_64-w64-mingw32 PREFIX=/usr/x86_64-w64-mingw32 $BUILD_DEPS /deps CC=x86_64-w64-mingw32-gcc-posix CXX=x86_64-w64-mingw32-g++-posix GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CGO_CFLAGS="$CGO_NTDEF" CGO_CXXFLAGS="$CGO_NTDEF" go get $V $X "${T[@]}" --ldflags="$LD" -d ./$PACK - CC=x86_64-w64-mingw32-gcc-posix CXX=x86_64-w64-mingw32-g++-posix GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CGO_CFLAGS="$CGO_NTDEF" CGO_CXXFLAGS="$CGO_NTDEF" go build $V $X "${T[@]}" --ldflags="$LD" $R -o /build/$NAME-$XGOOS-amd64$R.exe ./$PACK + CC=x86_64-w64-mingw32-gcc-posix CXX=x86_64-w64-mingw32-g++-posix GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CGO_CFLAGS="$CGO_NTDEF" CGO_CXXFLAGS="$CGO_NTDEF" go build $V $X "${T[@]}" --ldflags="$LD" $R -o /build/$NAME-windows-$PLATFORM-amd64$R.exe ./$PACK fi if [ $XGOARCH == "." ] || [ $XGOARCH == "386" ]; then - echo "Compiling for $XGOOS/386..." + echo "Compiling for windows-$PLATFORM/386..." CC=i686-w64-mingw32-gcc-posix CXX=i686-w64-mingw32-g++-posix HOST=i686-w64-mingw32 PREFIX=/usr/i686-w64-mingw32 $BUILD_DEPS /deps CC=i686-w64-mingw32-gcc-posix CXX=i686-w64-mingw32-g++-posix GOOS=windows GOARCH=386 CGO_ENABLED=1 CGO_CFLAGS="$CGO_NTDEF" CGO_CXXFLAGS="$CGO_NTDEF" go get $V $X "${T[@]}" --ldflags="$LD" -d ./$PACK - CC=i686-w64-mingw32-gcc-posix CXX=i686-w64-mingw32-g++-posix GOOS=windows GOARCH=386 CGO_ENABLED=1 CGO_CFLAGS="$CGO_NTDEF" CGO_CXXFLAGS="$CGO_NTDEF" go build $V $X "${T[@]}" --ldflags="$LD" -o /build/$NAME-$XGOOS-386.exe ./$PACK + CC=i686-w64-mingw32-gcc-posix CXX=i686-w64-mingw32-g++-posix GOOS=windows GOARCH=386 CGO_ENABLED=1 CGO_CFLAGS="$CGO_NTDEF" CGO_CXXFLAGS="$CGO_NTDEF" go build $V $X "${T[@]}" --ldflags="$LD" -o /build/$NAME-windows-$PLATFORM-386.exe ./$PACK fi fi # Check and build for OSX targets if [ $XGOOS == "." ] || [[ $XGOOS == darwin* ]]; then # Split the platform version and configure the deployment target PLATFORM=`echo $XGOOS | cut -d '-' -f 2` - if [ "$PLATFORM" != "" ] && [ "$PLATFORM" != "darwin" ]; then - export MACOSX_DEPLOYMENT_TARGET=$PLATFORM + if [ "$PLATFORM" == "" ] || [ "$PLATFORM" == "." ] || [ "$PLATFORM" == "darwin" ]; then + PLATFORM=10.6 # OS X Snow Leopard fi + export MACOSX_DEPLOYMENT_TARGET=$PLATFORM + # Build the requested darwin binaries if [ $XGOARCH == "." ] || [ $XGOARCH == "amd64" ]; then - echo "Compiling for $XGOOS/amd64..." + echo "Compiling for darwin-$PLATFORM/amd64..." CC=o64-clang CXX=o64-clang++ HOST=x86_64-apple-darwin13 PREFIX=/usr/local $BUILD_DEPS /deps CC=o64-clang CXX=o64-clang++ GOOS=darwin GOARCH=amd64 CGO_ENABLED=1 go get $V $X "${T[@]}" --ldflags="-s $LD" -d ./$PACK - CC=o64-clang CXX=o64-clang++ GOOS=darwin GOARCH=amd64 CGO_ENABLED=1 go build $V $X "${T[@]}" --ldflags="-s $LD" $R -o /build/$NAME-$XGOOS-amd64$R ./$PACK + CC=o64-clang CXX=o64-clang++ GOOS=darwin GOARCH=amd64 CGO_ENABLED=1 go build $V $X "${T[@]}" --ldflags="-s $LD" $R -o /build/$NAME-darwin-$PLATFORM-amd64$R ./$PACK fi if [ $XGOARCH == "." ] || [ $XGOARCH == "386" ]; then - echo "Compiling for $XGOOS/386..." + echo "Compiling for darwin-$PLATFORM/386..." CC=o32-clang CXX=o32-clang++ HOST=i386-apple-darwin13 PREFIX=/usr/local $BUILD_DEPS /deps CC=o32-clang CXX=o32-clang++ GOOS=darwin GOARCH=386 CGO_ENABLED=1 go get $V $X "${T[@]}" --ldflags="-s $LD" -d ./$PACK - CC=o32-clang CXX=o32-clang++ GOOS=darwin GOARCH=386 CGO_ENABLED=1 go build $V $X "${T[@]}" --ldflags="-s $LD" -o /build/$NAME-$XGOOS-386 ./$PACK + CC=o32-clang CXX=o32-clang++ GOOS=darwin GOARCH=386 CGO_ENABLED=1 go build $V $X "${T[@]}" --ldflags="-s $LD" -o /build/$NAME-darwin-$PLATFORM-386 ./$PACK fi # Remove any automatically injected deployment target vars unset MACOSX_DEPLOYMENT_TARGET