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: Fri, 05 Aug 2022 19:50:13
Message-Id: 1659729000.9d299a398903a01b82022a880360d0a4b7b1e791.mgorny@gentoo
1 commit: 9d299a398903a01b82022a880360d0a4b7b1e791
2 Author: Michał Górny <mgorny <AT> gentoo <DOT> org>
3 AuthorDate: Fri Aug 5 19:48:45 2022 +0000
4 Commit: Michał Górny <mgorny <AT> gentoo <DOT> org>
5 CommitDate: Fri Aug 5 19:50:00 2022 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=9d299a39
7
8 sys-libs/libcxx: Add 16.* live ebuilds
9
10 Signed-off-by: Michał Górny <mgorny <AT> gentoo.org>
11
12 sys-libs/libcxx/libcxx-16.0.0.9999.ebuild | 228 ++++++++++++++++++++++++++++++
13 1 file changed, 228 insertions(+)
14
15 diff --git a/sys-libs/libcxx/libcxx-16.0.0.9999.ebuild b/sys-libs/libcxx/libcxx-16.0.0.9999.ebuild
16 new file mode 100644
17 index 000000000000..d95f996ca33b
18 --- /dev/null
19 +++ b/sys-libs/libcxx/libcxx-16.0.0.9999.ebuild
20 @@ -0,0 +1,228 @@
21 +# Copyright 1999-2022 Gentoo Authors
22 +# Distributed under the terms of the GNU General Public License v2
23 +
24 +EAPI=8
25 +
26 +CMAKE_ECLASS=cmake
27 +PYTHON_COMPAT=( python3_{8..11} )
28 +inherit cmake-multilib flag-o-matic llvm llvm.org python-any-r1 \
29 + toolchain-funcs
30 +
31 +DESCRIPTION="New implementation of the C++ standard library, targeting C++11"
32 +HOMEPAGE="https://libcxx.llvm.org/"
33 +
34 +LICENSE="Apache-2.0-with-LLVM-exceptions || ( UoI-NCSA MIT )"
35 +SLOT="0"
36 +KEYWORDS=""
37 +IUSE="+clang +libcxxabi static-libs test"
38 +REQUIRED_USE="test? ( clang )"
39 +RESTRICT="!test? ( test )"
40 +
41 +RDEPEND="
42 + libcxxabi? (
43 + ~sys-libs/libcxxabi-${PV}[static-libs?,${MULTILIB_USEDEP}]
44 + )
45 + !libcxxabi? ( >=sys-devel/gcc-4.7:=[cxx] )
46 +"
47 +# llvm-6 for new lit options
48 +# clang-3.9.0 installs necessary target symlinks unconditionally
49 +# which removes the need for MULTILIB_USEDEP
50 +DEPEND="
51 + ${RDEPEND}
52 + >=sys-devel/llvm-6
53 +"
54 +BDEPEND="
55 + clang? (
56 + sys-devel/clang
57 + )
58 + !test? (
59 + ${PYTHON_DEPS}
60 + )
61 + test? (
62 + >=dev-util/cmake-3.16
63 + sys-devel/gdb[python]
64 + $(python_gen_any_dep 'dev-python/lit[${PYTHON_USEDEP}]')
65 + )
66 +"
67 +
68 +LLVM_COMPONENTS=( runtimes libcxx{,abi} llvm/{cmake,utils/llvm-lit} cmake )
69 +LLVM_PATCHSET=9999-1
70 +llvm.org_set_globals
71 +
72 +python_check_deps() {
73 + use test || return 0
74 + has_version "dev-python/lit[${PYTHON_USEDEP}]"
75 +}
76 +
77 +pkg_setup() {
78 + # Darwin Prefix builds do not have llvm installed yet, so rely on
79 + # bootstrap-prefix to set the appropriate path vars to LLVM instead
80 + # of using llvm_pkg_setup.
81 + if [[ ${CHOST} != *-darwin* ]] || has_version dev-lang/llvm; then
82 + llvm_pkg_setup
83 + fi
84 + python-any-r1_pkg_setup
85 +
86 + if ! use libcxxabi && ! tc-is-gcc ; then
87 + eerror "To build ${PN} against libsupc++, you have to use gcc. Other"
88 + eerror "compilers are not supported. Please set CC=gcc and CXX=g++"
89 + eerror "and try again."
90 + die
91 + fi
92 +}
93 +
94 +test_compiler() {
95 + $(tc-getCXX) ${CXXFLAGS} ${LDFLAGS} "${@}" -o /dev/null -x c++ - \
96 + <<<'int main() { return 0; }' &>/dev/null
97 +}
98 +
99 +src_configure() {
100 + # note: we need to do this before multilib kicks in since it will
101 + # alter the CHOST
102 + local cxxabi cxxabi_incs
103 + if use libcxxabi; then
104 + cxxabi=system-libcxxabi
105 + cxxabi_incs="${EPREFIX}/usr/include/c++/v1"
106 + else
107 + local gcc_inc="${EPREFIX}/usr/lib/gcc/${CHOST}/$(gcc-fullversion)/include/g++-v$(gcc-major-version)"
108 + cxxabi=libsupc++
109 + cxxabi_incs="${gcc_inc};${gcc_inc}/${CHOST}"
110 + fi
111 +
112 + multilib-minimal_src_configure
113 +}
114 +
115 +multilib_src_configure() {
116 + if use clang && ! tc-is-clang; then
117 + # Only do this conditionally to allow overriding with
118 + # e.g. CC=clang-13 in case of breakage
119 + local -x CC=${CHOST}-clang
120 + local -x CXX=${CHOST}-clang++
121 + strip-unsupported-flags
122 + fi
123 +
124 + # link against compiler-rt instead of libgcc if this is what clang does
125 + local want_compiler_rt=OFF
126 + if tc-is-clang; then
127 + local compiler_rt=$($(tc-getCC) ${CFLAGS} ${CPPFLAGS} \
128 + ${LDFLAGS} -print-libgcc-file-name)
129 + if [[ ${compiler_rt} == *libclang_rt* ]]; then
130 + want_compiler_rt=ON
131 + fi
132 + fi
133 +
134 + # bootstrap: cmake is unhappy if compiler can't link to stdlib
135 + local nolib_flags=( -nodefaultlibs -lc )
136 + if ! test_compiler; then
137 + if test_compiler "${nolib_flags[@]}"; then
138 + local -x LDFLAGS="${LDFLAGS} ${nolib_flags[*]}"
139 + ewarn "${CXX} seems to lack runtime, trying with ${nolib_flags[*]}"
140 + fi
141 + fi
142 +
143 + local libdir=$(get_libdir)
144 + local mycmakeargs=(
145 + -DCMAKE_CXX_COMPILER_TARGET="${CHOST}"
146 + -DPython3_EXECUTABLE="${PYTHON}"
147 + -DLLVM_ENABLE_RUNTIMES=libcxx
148 + -DLLVM_INCLUDE_TESTS=OFF
149 + -DLLVM_LIBDIR_SUFFIX=${libdir#lib}
150 +
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_INCLUDE_BENCHMARKS=OFF
159 + -DLIBCXX_INCLUDE_TESTS=$(usex test)
160 + -DLIBCXX_USE_COMPILER_RT=${want_compiler_rt}
161 + )
162 +
163 + if use test; then
164 + local clang_path=$(type -P "${CHOST:+${CHOST}-}clang" 2>/dev/null)
165 + [[ -n ${clang_path} ]] || die "Unable to find ${CHOST}-clang for tests"
166 +
167 + mycmakeargs+=(
168 + -DLLVM_EXTERNAL_LIT="${EPREFIX}/usr/bin/lit"
169 + -DLLVM_LIT_ARGS="$(get_lit_flags)"
170 + -DPython3_EXECUTABLE="${PYTHON}"
171 + )
172 + fi
173 + cmake_src_configure
174 +}
175 +
176 +multilib_src_compile() {
177 + cmake_src_compile
178 + if [[ ${CHOST} != *-darwin* ]] ; then
179 + gen_shared_ldscript
180 + use static-libs && gen_static_ldscript
181 + fi
182 +}
183 +
184 +multilib_src_test() {
185 + local -x LIT_PRESERVES_TMP=1
186 + cmake_build check-cxx
187 +}
188 +
189 +multilib_src_install() {
190 + cmake_src_install
191 + # since we've replaced libc++.{a,so} with ldscripts, now we have to
192 + # install the extra symlinks
193 + if [[ ${CHOST} != *-darwin* ]] ; then
194 + dolib.so lib/libc++_shared.so
195 + use static-libs && dolib.a lib/libc++_static.a
196 + fi
197 +}
198 +
199 +# Usage: deps
200 +gen_ldscript() {
201 + local output_format
202 + output_format=$($(tc-getCC) ${CFLAGS} ${LDFLAGS} -Wl,--verbose 2>&1 | sed -n 's/^OUTPUT_FORMAT("\([^"]*\)",.*/\1/p')
203 + [[ -n ${output_format} ]] && output_format="OUTPUT_FORMAT ( ${output_format} )"
204 +
205 + cat <<-END_LDSCRIPT
206 +/* GNU ld script
207 + Include missing dependencies
208 +*/
209 +${output_format}
210 +GROUP ( $@ )
211 +END_LDSCRIPT
212 +}
213 +
214 +gen_static_ldscript() {
215 + # Move it first.
216 + mv lib/libc++{,_static}.a || die
217 + # Generate libc++.a ldscript for inclusion of its dependencies so that
218 + # clang++ -stdlib=libc++ -static works out of the box.
219 + local deps=(
220 + libc++_static.a
221 + $(usex libcxxabi libc++abi.a libsupc++.a)
222 + )
223 + # On Linux/glibc it does not link without libpthread or libdl. It is
224 + # fine on FreeBSD.
225 + use elibc_glibc && deps+=( libpthread.a libdl.a )
226 +
227 + gen_ldscript "${deps[*]}" > lib/libc++.a || die
228 +}
229 +
230 +gen_shared_ldscript() {
231 + # Move it first.
232 + mv lib/libc++{,_shared}.so || die
233 + local deps=(
234 + libc++_shared.so
235 + # libsupc++ doesn't have a shared version
236 + $(usex libcxxabi libc++abi.so libsupc++.a)
237 + )
238 +
239 + gen_ldscript "${deps[*]}" > lib/libc++.so || die
240 +}
241 +
242 +pkg_postinst() {
243 + elog "This package (${PN}) is mainly intended as a replacement for the C++"
244 + elog "standard library when using clang."
245 + elog "To use it, instead of libstdc++, use:"
246 + elog " clang++ -stdlib=libc++"
247 + elog "to compile your C++ programs."
248 +}