llvm-svn
llvm-svn copied to clipboard
Add the "libc++" C++ Standard Library to the build
libc++ is a new implementation of the C++ standard library from the LLVM project, targeting C++11. It may be helpful to include it in the build for various reasons.
Here's an excerpt from libc++'s site:
Why a new C++ Standard Library for C++11?
After its initial introduction, many people have asked "why start a new library instead of contributing to an existing library?" (like Apache's libstdcxx, GNU's libstdc++, STLport, etc). There are many contributing reasons, but some of the major ones are:
- From years of experience (including having implemented the standard library before), we've learned many things about implementing the standard containers which require ABI breakage and fundamental changes to how they are implemented. For example, it is generally accepted that building std::string using the "short string optimization" instead of using Copy On Write (COW) is a superior approach for multicore machines (particularly in C++11, which has rvalue references). Breaking ABI compatibility with old versions of the library was determined to be critical to achieving the performance goals of libc++.
- Mainline libstdc++ has switched to GPL3, a license which the developers of libc++ cannot use. libstdc++ 4.2 (the last GPL2 version) could be independently extended to support C++11, but this would be a fork of the codebase (which is often seen as worse for a project than starting a new independent one). Another problem with libstdc++ is that it is tightly integrated with G++ development, tending to be tied fairly closely to the matching version of G++.
- STLport and the Apache libstdcxx library are two other popular candidates, but both lack C++11 support. Our experience (and the experience of libstdc++ developers) is that adding support for C++11 (in particular rvalue references and move-only types) requires changes to almost every class and function, essentially amounting to a rewrite. Faced with a rewrite, we decided to start from scratch and evaluate every design decision from first principles based on experience. Further, both projects are apparently abandoned: STLport 5.2.1 was released in Oct'08, and STDCXX 4.2.1 in May'08.
It would be awesome if binary snapshots for libc++ were also hosted on your [llvm-svn]
repo, especially now that it was dropped from [community]
.
It might also be worth it to mention that as of February 2017 there is a PKGBUILD recipe for libc++ being hosted on AUR: https://aur.archlinux.org/pkgbase/libc%2B%2B/
@brunocodutra Yup, I noticed that on aur-general too and was thinking along the same lines as you. Unfortunately, I've been rather busy with other things recently, so I even haven't yet dealt with the problem of a couple of AMD-related tests failing (in fact, I've debugged it and it seems trivial to fix, but I'll still need some help from upstream). I'll try to catch up on these things though. Thanks for the notice! ;)
If it's of any help, here is a fork of libc++'s PKGBUILD, that I use to build from trunk
# Maintainer: Llewelyn Trahaearn <woefulderelict [at] gmail [dot] com>
# Contributor: Daniel Micay <danielmicay [at] gmail [dot] com>
# Contributor: MThinkCpp <mtc [dot] maintainer [at] outlook [dot] com>
pkgbase=('libc++')
pkgname=("${pkgbase}-svn" "${pkgbase}abi-svn" "${pkgbase}experimental-svn")
pkgver=5.0.0svn_r295435
pkgrel=1
url="http://libcxx.llvm.org/"
license=('MIT' 'custom:University of Illinois/NCSA Open Source License')
arch=('i686' 'x86_64')
depends=('gcc-libs')
makedepends=('clang' 'cmake' 'python' 'libunwind')
source=("llvm::svn+http://llvm.org/svn/llvm-project/llvm/trunk"
"libcxx::svn+http://llvm.org/svn/llvm-project/libcxx/trunk"
"libcxxabi::svn+http://llvm.org/svn/llvm-project/libcxxabi/trunk")
sha512sums=('SKIP' 'SKIP' 'SKIP')
pkgver() {
cd "${srcdir}/llvm"
# This will almost match the output of `llvm-config --version` when the
# LLVM_APPEND_VC_REV cmake flag is turned on. The only difference is
# dash being replaced with underscore because of Pacman requirements.
echo $(awk -F 'MAJOR |MINOR |PATCH |SUFFIX |)' \
'BEGIN { ORS="." ; i=0 } \
/set\(LLVM_VERSION_/ { print $2 ; i++ ; if (i==2) ORS="" } \
END { print "\n" }' \
CMakeLists.txt)_r$(svnversion | tr -d [A-z])
}
prepare() {
[[ -d llvm/projects/libcxx ]] || ln -s ${srcdir}/libcxx llvm/projects/
[[ -d llvm/projects/libcxxabi ]] || ln -s ${srcdir}/libcxxabi llvm/projects/
sed -i 's/CREDITS.TXT/CREDITS/' llvm/projects/libcxx/LICENSE.TXT
sed -i 's/CREDITS.TXT/CREDITS/' llvm/projects/libcxxabi/LICENSE.TXT
[[ -d build ]] || mkdir build
}
build() {
cd build
CC=clang CXX=clang++ cmake \
-G "Unix Makefiles" \
-DLIBCXX_ENABLE_EXPERIMENTAL_LIBRARY=On \
-DLIBCXX_INSTALL_EXPERIMENTAL_LIBRARY=Off \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/usr \
${srcdir}/llvm
make cxx cxx_experimental
}
package_libc++-svn() {
pkgdesc='A new implementation of the C++ standard library, targeting C++11.'
depends=("libc++abi-svn=${pkgver}-${pkgrel}")
provides=("libc++")
conflicts=("libc++")
replaces=("libc++")
cd ${srcdir}/build
make DESTDIR="${pkgdir}" install-libcxx
install -Dm644 ${srcdir}/llvm/projects/libcxx/CREDITS.TXT "${pkgdir}/usr/share/licenses/${pkgname}/CREDITS"
install -Dm644 ${srcdir}/llvm/projects/libcxx/LICENSE.TXT "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}
package_libc++abi-svn() {
pkgdesc='A new implementation of low level support for a standard C++ library'
provides=("libc++abi")
conflicts=("libc++abi")
replaces=("libc++abi")
cd ${srcdir}/build
make DESTDIR="${pkgdir}" install-libcxxabi
install -Dm644 ${srcdir}/llvm/projects/libcxxabi/CREDITS.TXT "${pkgdir}/usr/share/licenses/${pkgname}/CREDITS"
install -Dm644 ${srcdir}/llvm/projects/libcxxabi/LICENSE.TXT "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}
package_libc++experimental-svn() {
pkgdesc='A new implementation of the C++ standard library, targeting C++11 (experimental library)'
depends=("libc++-svn=$pkgver-$pkgrel")
provides=("libc++experimental")
conflicts=("libc++experimental")
replaces=("libc++experimental")
install -Dm644 ${srcdir}/build/lib/libc++experimental.a ${pkgdir}/usr/lib/libc++experimental.a
install -Dm644 ${srcdir}/llvm/projects/libcxx/CREDITS.TXT "${pkgdir}/usr/share/licenses/${pkgname}/CREDITS"
install -Dm644 ${srcdir}/llvm/projects/libcxx/LICENSE.TXT "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}
The discussion continues in #10.