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