Gentoo Archives: gentoo-commits

From: "Michał Górny" <mgorny@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: sys-libs/libcxx/
Date: Thu, 28 Jan 2021 09:04:11
Message-Id: 1611824561.9267f6e1dd8ba1dad9c8099f121606d3aa431165.mgorny@gentoo
1 commit: 9267f6e1dd8ba1dad9c8099f121606d3aa431165
2 Author: Michał Górny <mgorny <AT> gentoo <DOT> org>
3 AuthorDate: Thu Jan 28 09:01:01 2021 +0000
4 Commit: Michał Górny <mgorny <AT> gentoo <DOT> org>
5 CommitDate: Thu Jan 28 09:02:41 2021 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=9267f6e1
7
8 sys-libs/libcxx: Add 13.x live ebuild
9
10 Signed-off-by: Michał Górny <mgorny <AT> gentoo.org>
11
12 sys-libs/libcxx/libcxx-13.0.0.9999.ebuild | 218 ++++++++++++++++++++++++++++++
13 1 file changed, 218 insertions(+)
14
15 diff --git a/sys-libs/libcxx/libcxx-13.0.0.9999.ebuild b/sys-libs/libcxx/libcxx-13.0.0.9999.ebuild
16 new file mode 100644
17 index 00000000000..6bfe1aa438b
18 --- /dev/null
19 +++ b/sys-libs/libcxx/libcxx-13.0.0.9999.ebuild
20 @@ -0,0 +1,218 @@
21 +# Copyright 1999-2021 Gentoo Authors
22 +# Distributed under the terms of the GNU General Public License v2
23 +
24 +EAPI=7
25 +
26 +CMAKE_ECLASS=cmake
27 +PYTHON_COMPAT=( python3_{6..9} )
28 +inherit cmake-multilib llvm llvm.org python-any-r1 toolchain-funcs
29 +
30 +DESCRIPTION="New implementation of the C++ standard library, targeting C++11"
31 +HOMEPAGE="https://libcxx.llvm.org/"
32 +
33 +LICENSE="Apache-2.0-with-LLVM-exceptions || ( UoI-NCSA MIT )"
34 +SLOT="0"
35 +KEYWORDS=""
36 +IUSE="elibc_glibc elibc_musl +libcxxabi +libunwind +static-libs test"
37 +REQUIRED_USE="libunwind? ( libcxxabi )"
38 +RESTRICT="!test? ( test )"
39 +
40 +RDEPEND="
41 + libcxxabi? ( ~sys-libs/libcxxabi-${PV}[libunwind=,static-libs?,${MULTILIB_USEDEP}] )
42 + !libcxxabi? ( >=sys-devel/gcc-4.7:=[cxx] )"
43 +# llvm-6 for new lit options
44 +# clang-3.9.0 installs necessary target symlinks unconditionally
45 +# which removes the need for MULTILIB_USEDEP
46 +DEPEND="${RDEPEND}
47 + >=sys-devel/llvm-6"
48 +BDEPEND="
49 + test? (
50 + >=dev-util/cmake-3.16
51 + >=sys-devel/clang-3.9.0
52 + $(python_gen_any_dep 'dev-python/lit[${PYTHON_USEDEP}]')
53 + )"
54 +
55 +DOCS=( CREDITS.TXT )
56 +
57 +LLVM_COMPONENTS=( libcxx{,abi} llvm/{cmake/modules,utils/llvm-lit} )
58 +llvm.org_set_globals
59 +
60 +python_check_deps() {
61 + has_version "dev-python/lit[${PYTHON_USEDEP}]"
62 +}
63 +
64 +pkg_setup() {
65 + # Darwin Prefix builds do not have llvm installed yet, so rely on
66 + # bootstrap-prefix to set the appropriate path vars to LLVM instead
67 + # of using llvm_pkg_setup.
68 + if [[ ${CHOST} != *-darwin* ]] || has_version dev-lang/llvm; then
69 + llvm_pkg_setup
70 + fi
71 + use test && python-any-r1_pkg_setup
72 +
73 + if ! use libcxxabi && ! tc-is-gcc ; then
74 + eerror "To build ${PN} against libsupc++, you have to use gcc. Other"
75 + eerror "compilers are not supported. Please set CC=gcc and CXX=g++"
76 + eerror "and try again."
77 + die
78 + fi
79 +}
80 +
81 +src_prepare() {
82 + # Add link flag "-Wl,-z,defs" to avoid underlinking; this is needed in a
83 + # out-of-tree build.
84 + eapply "${FILESDIR}/${PN}-3.9-cmake-link-flags.patch"
85 +
86 + llvm.org_src_prepare
87 +}
88 +
89 +test_compiler() {
90 + $(tc-getCXX) ${CXXFLAGS} ${LDFLAGS} "${@}" -o /dev/null -x c++ - \
91 + <<<'int main() { return 0; }' &>/dev/null
92 +}
93 +
94 +src_configure() {
95 + # note: we need to do this before multilib kicks in since it will
96 + # alter the CHOST
97 + local cxxabi cxxabi_incs
98 + if use libcxxabi; then
99 + cxxabi=libcxxabi
100 + cxxabi_incs="${EPREFIX}/usr/include/libcxxabi"
101 + else
102 + local gcc_inc="${EPREFIX}/usr/lib/gcc/${CHOST}/$(gcc-fullversion)/include/g++-v$(gcc-major-version)"
103 + cxxabi=libsupc++
104 + cxxabi_incs="${gcc_inc};${gcc_inc}/${CHOST}"
105 + fi
106 +
107 + multilib-minimal_src_configure
108 +}
109 +
110 +multilib_src_configure() {
111 + # we want -lgcc_s for unwinder, and for compiler runtime when using
112 + # gcc, clang with gcc runtime (or any unknown compiler)
113 + local extra_libs=() want_gcc_s=ON want_compiler_rt=OFF
114 + if use libunwind; then
115 + # work-around missing -lunwind upstream
116 + extra_libs+=( -lunwind )
117 + # if we're using libunwind and clang with compiler-rt, we want
118 + # to link to compiler-rt instead of -lgcc_s
119 + if tc-is-clang; then
120 + local compiler_rt=$($(tc-getCC) ${CFLAGS} ${CPPFLAGS} \
121 + ${LDFLAGS} -print-libgcc-file-name)
122 + if [[ ${compiler_rt} == *libclang_rt* ]]; then
123 + want_gcc_s=OFF
124 + want_compiler_rt=ON
125 + extra_libs+=( "${compiler_rt}" )
126 + fi
127 + fi
128 + elif [[ ${CHOST} == *-darwin* ]] && tc-is-clang; then
129 + # clang-based darwin prefix disables libunwind useflag during
130 + # bootstrap, because libunwind is not in the prefix yet.
131 + # override the default, though, because clang based libcxx
132 + # should never use gcc_s on Darwin.
133 + want_gcc_s=OFF
134 + # compiler_rt is not available in EPREFIX during bootstrap,
135 + # so we cannot link to it yet anyway, so keep the defaults
136 + # of want_compiler_rt=OFF and extra_libs=()
137 + fi
138 +
139 + # bootstrap: cmake is unhappy if compiler can't link to stdlib
140 + local nolib_flags=( -nodefaultlibs -lc )
141 + if ! test_compiler; then
142 + if test_compiler "${nolib_flags[@]}"; then
143 + local -x LDFLAGS="${LDFLAGS} ${nolib_flags[*]}"
144 + ewarn "${CXX} seems to lack runtime, trying with ${nolib_flags[*]}"
145 + fi
146 + fi
147 +
148 + local libdir=$(get_libdir)
149 + local mycmakeargs=(
150 + -DLIBCXX_LIBDIR_SUFFIX=${libdir#lib}
151 + -DLIBCXX_ENABLE_SHARED=ON
152 + -DLIBCXX_ENABLE_STATIC=$(usex static-libs)
153 + -DLIBCXX_CXX_ABI=${cxxabi}
154 + -DLIBCXX_CXX_ABI_INCLUDE_PATHS=${cxxabi_incs}
155 + # we're using our own mechanism for generating linker scripts
156 + -DLIBCXX_ENABLE_ABI_LINKER_SCRIPT=OFF
157 + -DLIBCXX_HAS_MUSL_LIBC=$(usex elibc_musl)
158 + -DLIBCXX_HAS_GCC_S_LIB=${want_gcc_s}
159 + -DLIBCXX_INCLUDE_TESTS=$(usex test)
160 + -DLIBCXX_USE_COMPILER_RT=${want_compiler_rt}
161 + -DCMAKE_SHARED_LINKER_FLAGS="${extra_libs[*]} ${LDFLAGS}"
162 + )
163 +
164 + if use test; then
165 + local clang_path=$(type -P "${CHOST:+${CHOST}-}clang" 2>/dev/null)
166 + [[ -n ${clang_path} ]] || die "Unable to find ${CHOST}-clang for tests"
167 +
168 + mycmakeargs+=(
169 + -DLLVM_EXTERNAL_LIT="${EPREFIX}/usr/bin/lit"
170 + -DLLVM_LIT_ARGS="$(get_lit_flags);--param=cxx_under_test=${clang_path}"
171 + -DPython3_EXECUTABLE="${PYTHON}"
172 + )
173 + fi
174 + cmake_src_configure
175 +}
176 +
177 +multilib_src_test() {
178 + local -x LIT_PRESERVES_TMP=1
179 + cmake_build check-cxx
180 +}
181 +
182 +# Usage: deps
183 +gen_ldscript() {
184 + local output_format
185 + output_format=$($(tc-getCC) ${CFLAGS} ${LDFLAGS} -Wl,--verbose 2>&1 | sed -n 's/^OUTPUT_FORMAT("\([^"]*\)",.*/\1/p')
186 + [[ -n ${output_format} ]] && output_format="OUTPUT_FORMAT ( ${output_format} )"
187 +
188 + cat <<-END_LDSCRIPT
189 +/* GNU ld script
190 + Include missing dependencies
191 +*/
192 +${output_format}
193 +GROUP ( $@ )
194 +END_LDSCRIPT
195 +}
196 +
197 +gen_static_ldscript() {
198 + local libdir=$(get_libdir)
199 + local cxxabi_lib=$(usex libcxxabi "libc++abi.a" "libsupc++.a")
200 +
201 + # Move it first.
202 + mv "${ED}/usr/${libdir}/libc++.a" "${ED}/usr/${libdir}/libc++_static.a" || die
203 + # Generate libc++.a ldscript for inclusion of its dependencies so that
204 + # clang++ -stdlib=libc++ -static works out of the box.
205 + local deps="libc++_static.a ${cxxabi_lib} $(usex libunwind libunwind.a libgcc_eh.a)"
206 + # On Linux/glibc it does not link without libpthread or libdl. It is
207 + # fine on FreeBSD.
208 + use elibc_glibc && deps+=" libpthread.a libdl.a"
209 +
210 + gen_ldscript "${deps}" > "${ED}/usr/${libdir}/libc++.a" || die
211 +}
212 +
213 +gen_shared_ldscript() {
214 + local libdir=$(get_libdir)
215 + # libsupc++ doesn't have a shared version
216 + local cxxabi_lib=$(usex libcxxabi "libc++abi.so" "libsupc++.a")
217 +
218 + mv "${ED}/usr/${libdir}/libc++.so" "${ED}/usr/${libdir}/libc++_shared.so" || die
219 + local deps="libc++_shared.so ${cxxabi_lib} $(usex libunwind libunwind.so libgcc_s.so)"
220 +
221 + gen_ldscript "${deps}" > "${ED}/usr/${libdir}/libc++.so" || die
222 +}
223 +
224 +multilib_src_install() {
225 + cmake_src_install
226 + if [[ ${CHOST} != *-darwin* ]] ; then
227 + gen_shared_ldscript
228 + use static-libs && gen_static_ldscript
229 + fi
230 +}
231 +
232 +pkg_postinst() {
233 + elog "This package (${PN}) is mainly intended as a replacement for the C++"
234 + elog "standard library when using clang."
235 + elog "To use it, instead of libstdc++, use:"
236 + elog " clang++ -stdlib=libc++"
237 + elog "to compile your C++ programs."
238 +}