Skip to content

Commit

Permalink
[build-boost] Build Boost with LLVM libc++ in addition to GNU libstdc++
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitry Moskalchuk <dm@crystax.net>
  • Loading branch information
dmsck committed Sep 7, 2015
1 parent c14a8c4 commit a2b3307
Show file tree
Hide file tree
Showing 11 changed files with 178 additions and 84 deletions.
144 changes: 109 additions & 35 deletions build/tools/build-boost.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ register_var_option "--version=<ver>" BOOST_VERSION "Boost version to build"
ICU_VERSION=
register_var_option "--with-icu=<version>" ICU_VERSION "ICU version to build with [without ICU]"

STDLIBS=""
for VERSION in $DEFAULT_GCC_VERSION_LIST; do
STDLIBS="$STDLIBS gnu-$VERSION"
done
for VERSION in $DEFAULT_LLVM_VERSION_LIST; do
STDLIBS="$STDLIBS llvm-$VERSION"
done
STDLIBS=$(spaces_to_commas $STDLIBS)
register_var_option "--stdlibs=<list>" STDLIBS "List of Standard C++ Library implementations to build with"

register_jobs_option

extract_parameters "$@"
Expand Down Expand Up @@ -100,6 +110,8 @@ fail_panic "Could not create Boost $BOOST_VERSION destination directory: $BOOST_

ABIS=$(commas_to_spaces $ABIS)

STDLIBS=$(commas_to_spaces $STDLIBS)

if [ -z "$OPTION_BUILD_DIR" ]; then
BUILD_DIR=$NDK_TMPDIR/build-boost
else
Expand Down Expand Up @@ -232,16 +244,54 @@ build_boost_for_abi ()
;;
esac

local TOOLCHAIN_VERSION
local LLVMTRIPLE
case $ABI in
armeabi)
LLVMTRIPLE="armv5te-none-linux-androideabi"
;;
armeabi-v7a*)
LLVMTRIPLE="armv7-none-linux-androideabi"
;;
arm64-v8a)
LLVMTRIPLE="aarch64-none-linux-android"
;;
x86)
LLVMTRIPLE="i686-none-linux-android"
;;
x86_64)
LLVMTRIPLE="x86_64-none-linux-android"
;;
mips)
LLVMTRIPLE="mipsel-none-linux-android"
;;
mips64)
LLVMTRIPLE="mips64el-none-linux-android"
;;
*)
echo "ERROR: Unknown ABI: '$ABI'" 1>&2
exit 1
esac

local GCC_VERSION
case $LIBSTDCXX in
gnu-*)
TOOLCHAIN_VERSION=$(expr "$LIBSTDCXX" : "^gnu-\(.*\)$")
GCC_VERSION=$(expr "$LIBSTDCXX" : "^gnu-\(.*\)$")
;;
*)
TOOLCHAIN_VERSION=$DEFAULT_GCC_VERSION
GCC_VERSION=$DEFAULT_GCC_VERSION
esac

local TCPATH=$NDK_DIR/toolchains/$TCNAME-$TOOLCHAIN_VERSION/prebuilt/$HOST_TAG
local LLVM_VERSION
case $LIBSTDCXX in
llvm-*)
LLVM_VERSION=$(expr "$LIBSTDCXX" : "^llvm-\(.*\)$")
;;
*)
LLVM_VERSION=$DEFAULT_LLVM_VERSION
esac

local GCC_DIR=$NDK_DIR/toolchains/$TCNAME-$GCC_VERSION/prebuilt/$HOST_TAG
local LLVM_DIR=$NDK_DIR/toolchains/llvm-$LLVM_VERSION/prebuilt/$HOST_TAG

local SRCDIR=$BUILDDIR/src
copy_directory $BOOST_SRCDIR $SRCDIR
Expand Down Expand Up @@ -270,8 +320,16 @@ build_boost_for_abi ()
{
echo "import option ;"
echo "import feature ;"
echo "using gcc : $ARCH : g++ ;"
echo "project : default-build <toolset>gcc ;"
case $LIBSTDCXX in
gnu-*)
echo "using gcc : $ARCH : g++ ;"
echo "project : default-build <toolset>gcc ;"
;;
llvm-*)
echo "using clang : $ARCH : clang++ ;"
echo "project : default-build <toolset>clang ;"
;;
esac
echo "libraries = ;"
echo "option.set keep-going : false ;"
} | cat >project-config.jam
Expand All @@ -288,19 +346,29 @@ build_boost_for_abi ()
ICU=$NDK_DIR/sources/icu/$ICU_VERSION
fi

local CXX CXXNAME
local LIBSTDCXX_CFLAGS LIBSTDCXX_LDFLAGS LIBSTDCXX_LDLIBS
local TOOLSET
case $LIBSTDCXX in
gnu-*)
CXX=$GCC_DIR/bin/$TCPREFIX-g++
CXXNAME=g++
local GNULIBCXX=$NDK_DIR/sources/cxx-stl/gnu-libstdc++/$(expr "$LIBSTDCXX" : "^gnu-\(.*\)$")
LIBSTDCXX_CFLAGS="-I$GNULIBCXX/include -I$GNULIBCXX/libs/$ABI/include"
LIBSTDCXX_LDFLAGS="-L$GNULIBCXX/libs/$ABI"
LIBSTDCXX_LDLIBS="-lgnustl_${TYPE}"
TOOLSET=gcc-$ARCH
;;
llvm-*)
local LLVMLIBCXX=$NDK_DIR/sources/cxx-stl/llvm-libc++
LIBSTDCXX_CFLAGS="-I$LLVMLIBCXX/libcxx/include"
CXX="$LLVM_DIR/bin/clang++ -target $LLVMTRIPLE -gcc-toolchain $GCC_DIR"
CXXNAME=clang++
local LLVMLIBCXX=$NDK_DIR/sources/cxx-stl/llvm-libc++/$(expr "$LIBSTDCXX" : "^llvm-\(.*\)$")
local LLVMLIBCXXABI=$NDK_DIR/sources/cxx-stl/llvm-libc++abi
LIBSTDCXX_CFLAGS="-I$LLVMLIBCXX/libcxx/include -I$LLVMLIBCXXABI/libcxxabi/include"
LIBSTDCXX_LDFLAGS="-L$LLVMLIBCXX/libs/$ABI"
LIBSTDCXX_LDLIBS="-lc++_${TYPE}"
TOOLSET=clang-$ARCH
FLAGS="$FLAGS -fno-integrated-as"
;;
*)
echo "ERROR: Unknown C++ Standard Library: '$LIBSTDCXX'" 1>&2
Expand All @@ -310,14 +378,13 @@ build_boost_for_abi ()
FLAGS="$FLAGS --sysroot=$SYSROOT"
FLAGS="$FLAGS -fPIC"

local TOOL

for TOOL in gcc g++ c++ cpp; do
mktool $TMPTARGETTCDIR/$TOOL <<EOF
mktool $TMPTARGETTCDIR/$CXXNAME <<EOF
#!/bin/sh
if echo "\$@" | tr ' ' '\\n' | grep -q -x -e -c; then
LINKER=no
elif echo "\$@" | tr ' ' '\\n' | grep -q -x -e -emit-pth; then
LINKER=no
else
LINKER=yes
fi
Expand Down Expand Up @@ -362,15 +429,14 @@ if [ "x\$LINKER" = "xyes" ]; then
PARAMS="\$PARAMS $LIBSTDCXX_LDLIBS"
fi
exec $TCPATH/bin/$TCPREFIX-$TOOL \$PARAMS
exec $CXX \$PARAMS
EOF
fail_panic "Could not create target tool $TOOL"
done
fail_panic "Could not create target $CXXNAME wrapper"

for TOOL in as ar ranlib strip gcc-ar gcc-ranlib; do
for TOOL in as ar ranlib strip; do
{
echo "#!/bin/sh"
echo "exec $TCPATH/bin/$TCPREFIX-$TOOL \"\$@\""
echo "exec $GCC_DIR/bin/$TCPREFIX-$TOOL \"\$@\""
} | mktool $TMPTARGETTCDIR/$TOOL
fail_panic "Could not create target tool $TOOL"
done
Expand Down Expand Up @@ -439,7 +505,7 @@ EOF
threading=multi \
threadapi=pthread \
target-os=android \
toolset=gcc-$ARCH \
toolset=$TOOLSET \
$EXTRA_OPTIONS \
--layout=system \
--prefix=$PREFIX \
Expand Down Expand Up @@ -525,14 +591,9 @@ for ABI in $ABIS; do
fi
fi
if [ "$DO_BUILD_PACKAGE" = "yes" ]; then
GNULIBSTDCXX_VERSIONS=$(for e in $(ls -1d $NDK_DIR/sources/cxx-stl/gnu-libstdc++/* 2>/dev/null); do test -d $e && basename $e; done)
CXXIMPLS=""
for GNULIBSTDCXX_VERSION in $GNULIBSTDCXX_VERSIONS; do
CXXIMPLS="$CXXIMPLS gnu-$GNULIBSTDCXX_VERSION"
done
for CXXIMPL in $CXXIMPLS; do
for STDLIB in $STDLIBS; do
for TYPE in shared static; do
build_boost_for_abi $ABI "$BUILD_DIR/$ABI/$TYPE/$CXXIMPL" "$TYPE" "$CXXIMPL"
build_boost_for_abi $ABI "$BUILD_DIR/$ABI/$TYPE/$STDLIB" "$TYPE" "$STDLIB"
done
done
fi
Expand All @@ -556,15 +617,22 @@ log "Generating $BOOST_DSTDIR/Android.mk"
echo ""
echo 'LOCAL_PATH := $(call my-dir)'
echo ''
echo 'define boost-libstdcxx-subdir'
echo '$(strip $(if $(filter c++_%,$(APP_STL)),\'
echo ' llvm,\'
echo ' gnu\'
echo '))-$(strip $(if $(filter c++_%,$(APP_STL)),\'
echo ' $(if $(filter clang%,$(NDK_TOOLCHAIN_VERSION)),$(patsubst clang%,%,$(NDK_TOOLCHAIN_VERSION)),'$DEFAULT_LLVM_VERSION'),\'
echo ' $(if $(filter clang%,$(NDK_TOOLCHAIN_VERSION)),'$DEFAULT_GCC_VERSION',$(NDK_TOOLCHAIN_VERSION))\'
echo '))'
echo 'endef'
echo 'ifeq (,$(filter gnustl_% c++_%,$(APP_STL)))'
echo '$(error $(strip \'
echo ' We do not support APP_STL '"'"'$(APP_STL)'"'"' for Boost libraries! \'
echo ' Please use either "gnustl_shared", "gnustl_static", "c++_shared" or "c++_static". \'
echo ')'
echo 'endif'
echo ''
echo '__boost_libstdcxx_subdir := $(strip \'
echo ' $(strip $(if $(filter c++_%,$(APP_STL)),\'
echo ' llvm,\'
echo ' gnu\'
echo ' ))-$(strip $(if $(filter c++_%,$(APP_STL)),\'
echo ' $(if $(filter clang%,$(NDK_TOOLCHAIN_VERSION)),$(patsubst clang%,%,$(NDK_TOOLCHAIN_VERSION)),'$DEFAULT_LLVM_VERSION'),\'
echo ' $(if $(filter clang%,$(NDK_TOOLCHAIN_VERSION)),'$DEFAULT_GCC_VERSION',$(NDK_TOOLCHAIN_VERSION))\'
echo ' ))\'
echo ')'

for SUFFIX in a so; do
if [ "$SUFFIX" = "a" ]; then
Expand Down Expand Up @@ -626,6 +694,12 @@ log "Generating $BOOST_DSTDIR/Android.mk"
fi
;;
esac
;;
boost_locale)
if [ "$BOOST_ABI" = "armeabi" -a "$LIBTYPE" = "static" ]; then
SKIP=yes
fi
;;
esac

if [ "$SKIP" = "yes" ]; then
Expand All @@ -636,7 +710,7 @@ log "Generating $BOOST_DSTDIR/Android.mk"
echo 'ifneq (,$(filter '$BOOST_ABI',$(TARGET_ARCH_ABI)))'
echo 'include $(CLEAR_VARS)'
echo 'LOCAL_MODULE := '$LIB'_'$LIBTYPE
echo 'LOCAL_SRC_FILES := libs/$(TARGET_ARCH_ABI)/$(call boost-libstdcxx-subdir)/lib'$LIB'.'$SUFFIX
echo 'LOCAL_SRC_FILES := libs/$(TARGET_ARCH_ABI)/$(__boost_libstdcxx_subdir)/lib'$LIB'.'$SUFFIX
echo 'LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include'
echo 'ifneq (,$(filter clang%,$(NDK_TOOLCHAIN_VERSION)))'
echo 'LOCAL_EXPORT_LDLIBS := -latomic'
Expand Down
66 changes: 66 additions & 0 deletions tests/build/crystax-test-boost-dependencies/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/bin/bash

cd $(dirname $0) || exit 1

if [ -z "$NDK" ]; then
NDK=$(cd ../../.. && pwd)
fi

source $NDK/build/tools/dev-defaults.sh || exit 1

if [ -z "$NDK_TOOLCHAIN_VERSION" ]; then
TOOLCHAIN_VERSIONS="$DEFAULT_GCC_VERSION_LIST"
for VERSION in $DEFAULT_LLVM_VERSION_LIST; do
TOOLCHAIN_VERSIONS="$TOOLCHAIN_VERSIONS clang${VERSION}"
done
else
TOOLCHAIN_VERSIONS=$NDK_TOOLCHAIN_VERSION
fi

BOOST_VERSIONS=$(ls -1 $NDK/sources/boost/ 2>/dev/null)
if [ -z "$BOOST_VERSIONS" ]; then
echo "*** ERROR: Can't find Boost libraries in $NDK/sources/boost" 1>&2
exit 1
fi

run()
{
echo "## COMMAND: $@"
"$@"
}

cleanup()
{
rm -Rf obj libs
}

for TV in $TOOLCHAIN_VERSIONS; do
for VERSION in $BOOST_VERSIONS; do
for LIBCXX in gnustl c++; do
for LIBTYPE in shared static; do
cleanup || exit 1

{
echo 'LOCAL_PATH := $(call my-dir)'
echo ''
echo 'include $(CLEAR_VARS)'
echo 'LOCAL_MODULE := test-boost'$VERSION'-dependencies'
echo 'LOCAL_SRC_FILES := test.cpp'
echo 'LOCAL_STATIC_LIBRARIES := boost_regex_'$LIBTYPE
echo 'include $(BUILD_EXECUTABLE)'
echo ''
echo '$(call import-module,boost+icu/'$VERSION')'
} | cat >jni/Android.mk || exit 1

run $NDK/ndk-build -B "$@" APP_ABI=all APP_STL=${LIBCXX}_${LIBTYPE} NDK_TOOLCHAIN_VERSION=$TV V=1
if [ $? -ne 0 ]; then
echo "*** ERROR: Can't build Boost dependencies test" 1>&2
exit 1
fi
done
done
done
done

cleanup
exit 0
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := test
LOCAL_SRC_FILES := test.cpp
LOCAL_MODULE := test-boost1.57.0-dependencies
LOCAL_SRC_FILES := test.cpp
LOCAL_STATIC_LIBRARIES := boost_regex_shared
LOCAL_STATIC_LIBRARIES += boost_exception_static
include $(BUILD_EXECUTABLE)

$(call import-module,boost+icu/1.57.0)

This file was deleted.

This file was deleted.

This file was deleted.

13 changes: 0 additions & 13 deletions tests/build/crystax-test-boost1.58.0-dependencies/jni/test.cpp

This file was deleted.

This file was deleted.

This file was deleted.

13 changes: 0 additions & 13 deletions tests/build/crystax-test-boost1.59.0-dependencies/jni/test.cpp

This file was deleted.

0 comments on commit a2b3307

Please sign in to comment.