* [gentoo-dev] [PATCH 0/3] toolchain-funcs.eclass: support for querying C++ stdlib and compiler runtime
@ 2022-10-08 9:43 Michał Górny
2022-10-08 9:43 ` [gentoo-dev] [PATCH 1/3] toolchain-funcs.eclass: Add tc-get-cxx-stdlib() to get C++ stdlib Michał Górny
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Michał Górny @ 2022-10-08 9:43 UTC (permalink / raw
To: gentoo-dev; +Cc: Michał Górny
Hi,
Here's a patchset adding two new functions along with tests:
- tc-get-cxx-stdlib() that determines C++ stdlib used (libc++ vs
libstdc++)
- tc-get-c-rtlib() that determines C compiler runtime used (libgcc vs
compiler-rt)
I've also included a fix for tests failing if ld.gold is not installed.
Michał Górny (3):
toolchain-funcs.eclass: Add tc-get-cxx-stdlib() to get C++ stdlib
toolchain-funcs.eclass: Add tc-get-c-rtlib() to get CC runtime
eclass/tests/toolchain-funcs.sh: Handle missing ld.gold gracefully
eclass/tests/toolchain-funcs.sh | 96 ++++++++++++++++++++++-----------
eclass/toolchain-funcs.eclass | 64 ++++++++++++++++++++++
2 files changed, 130 insertions(+), 30 deletions(-)
--
2.38.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [gentoo-dev] [PATCH 1/3] toolchain-funcs.eclass: Add tc-get-cxx-stdlib() to get C++ stdlib
2022-10-08 9:43 [gentoo-dev] [PATCH 0/3] toolchain-funcs.eclass: support for querying C++ stdlib and compiler runtime Michał Górny
@ 2022-10-08 9:43 ` Michał Górny
2022-10-08 9:43 ` [gentoo-dev] [PATCH 2/3] toolchain-funcs.eclass: Add tc-get-c-rtlib() to get CC runtime Michał Górny
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Michał Górny @ 2022-10-08 9:43 UTC (permalink / raw
To: gentoo-dev; +Cc: Michał Górny
Add a new tc-get-cxx-stdlib() that attempts to get the C++ stdlib
variant used by the current C++ compiler. Currently it supports libc++
and libstdc++ (GCC's stdlib).
Signed-off-by: Michał Górny <mgorny@gentoo.org>
---
eclass/tests/toolchain-funcs.sh | 22 ++++++++++++++++++++
eclass/toolchain-funcs.eclass | 36 +++++++++++++++++++++++++++++++++
2 files changed, 58 insertions(+)
diff --git a/eclass/tests/toolchain-funcs.sh b/eclass/tests/toolchain-funcs.sh
index 56379b10cded..5a35a44ce018 100755
--- a/eclass/tests/toolchain-funcs.sh
+++ b/eclass/tests/toolchain-funcs.sh
@@ -198,4 +198,26 @@ for compiler in gcc clang not-really-a-compiler; do
fi
done
+if type -P gcc &>/dev/null; then
+ tbegin "tc-get-cxx-stdlib (gcc)"
+ [[ $(CXX=g++ tc-get-cxx-stdlib) == libstdc++ ]]
+ tend $?
+fi
+
+if type -P clang &>/dev/null; then
+ for stdlib in libc++ libstdc++; do
+ if clang++ -stdlib=${stdlib} -x c++ -E -P - &>/dev/null \
+ <<<'#include <ciso646>'
+ then
+ tbegin "tc-get-cxx-stdlib (clang, ${stdlib})"
+ [[ $(CXX=clang++ CXXFLAGS="-stdlib=${stdlib}" tc-get-cxx-stdlib) == ${stdlib} ]]
+ tend $?
+ fi
+ done
+
+ tbegin "tc-get-cxx-stdlib (clang, invalid)"
+ ! CXX=clang++ CXXFLAGS="-stdlib=invalid" tc-get-cxx-stdlib
+ tend $?
+fi
+
texit
diff --git a/eclass/toolchain-funcs.eclass b/eclass/toolchain-funcs.eclass
index 48bf11606c4a..92494158201e 100644
--- a/eclass/toolchain-funcs.eclass
+++ b/eclass/toolchain-funcs.eclass
@@ -1173,4 +1173,40 @@ gen_usr_ldscript() {
done
}
+# @FUNCTION: tc-get-cxx-stdlib
+# @DESCRIPTION:
+# Attempt to identify the C++ standard library used by the compiler.
+# If the library is identified, the function returns 0 and prints one
+# of the following:
+#
+# - ``libc++`` for ``sys-libs/libcxx``
+# - ``libstdc++`` for ``sys-devel/gcc``'s libstdc++
+#
+# If the library is not recognized, the function returns 1.
+tc-get-cxx-stdlib() {
+ local code='#include <ciso646>
+
+#if defined(_LIBCPP_VERSION)
+ HAVE_LIBCXX
+#elif defined(__GLIBCXX__)
+ HAVE_LIBSTDCPP
+#endif
+'
+ local res=$(
+ $(tc-getCXX) ${CXXFLAGS} ${CPPFLAGS} -x c++ -E -P - \
+ <<<"${code}" 2>/dev/null
+ )
+
+ case ${res} in
+ *HAVE_LIBCXX*)
+ echo libc++;;
+ *HAVE_LIBSTDCPP*)
+ echo libstdc++;;
+ *)
+ return 1;;
+ esac
+
+ return 0
+}
+
fi
--
2.38.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [gentoo-dev] [PATCH 2/3] toolchain-funcs.eclass: Add tc-get-c-rtlib() to get CC runtime
2022-10-08 9:43 [gentoo-dev] [PATCH 0/3] toolchain-funcs.eclass: support for querying C++ stdlib and compiler runtime Michał Górny
2022-10-08 9:43 ` [gentoo-dev] [PATCH 1/3] toolchain-funcs.eclass: Add tc-get-cxx-stdlib() to get C++ stdlib Michał Górny
@ 2022-10-08 9:43 ` Michał Górny
2022-10-08 9:43 ` [gentoo-dev] [PATCH 3/3] eclass/tests/toolchain-funcs.sh: Handle missing ld.gold gracefully Michał Górny
2022-10-09 21:30 ` [gentoo-dev] [PATCH 0/3] toolchain-funcs.eclass: support for querying C++ stdlib and compiler runtime Sam James
3 siblings, 0 replies; 5+ messages in thread
From: Michał Górny @ 2022-10-08 9:43 UTC (permalink / raw
To: gentoo-dev; +Cc: Michał Górny
Add a new tc-get-c-rtlib() that attempts to get the runtime used
by the current C compiler. Currently it supports compiler-rt
and libgcc.
Signed-off-by: Michał Górny <mgorny@gentoo.org>
---
eclass/tests/toolchain-funcs.sh | 10 ++++++++++
eclass/toolchain-funcs.eclass | 28 ++++++++++++++++++++++++++++
2 files changed, 38 insertions(+)
diff --git a/eclass/tests/toolchain-funcs.sh b/eclass/tests/toolchain-funcs.sh
index 5a35a44ce018..d8a357fb24fe 100755
--- a/eclass/tests/toolchain-funcs.sh
+++ b/eclass/tests/toolchain-funcs.sh
@@ -202,6 +202,10 @@ if type -P gcc &>/dev/null; then
tbegin "tc-get-cxx-stdlib (gcc)"
[[ $(CXX=g++ tc-get-cxx-stdlib) == libstdc++ ]]
tend $?
+
+ tbegin "tc-get-c-rtlib (gcc)"
+ [[ $(CC=gcc tc-get-c-rtlib) == libgcc ]]
+ tend $?
fi
if type -P clang &>/dev/null; then
@@ -218,6 +222,12 @@ if type -P clang &>/dev/null; then
tbegin "tc-get-cxx-stdlib (clang, invalid)"
! CXX=clang++ CXXFLAGS="-stdlib=invalid" tc-get-cxx-stdlib
tend $?
+
+ for rtlib in compiler-rt libgcc; do
+ tbegin "tc-get-c-rtlib (clang, ${rtlib})"
+ [[ $(CC=clang CFLAGS="--rtlib=${rtlib}" tc-get-c-rtlib) == ${rtlib} ]]
+ tend $?
+ done
fi
texit
diff --git a/eclass/toolchain-funcs.eclass b/eclass/toolchain-funcs.eclass
index 92494158201e..32e446cb2368 100644
--- a/eclass/toolchain-funcs.eclass
+++ b/eclass/toolchain-funcs.eclass
@@ -1209,4 +1209,32 @@ tc-get-cxx-stdlib() {
return 0
}
+# @FUNCTION: tc-get-c-rtlib
+# @DESCRIPTION:
+# Attempt to identify the runtime used by the C/C++ compiler.
+# If the runtime is identifed, the function returns 0 and prints one
+# of the following:
+#
+# - ``compiler-rt`` for ``sys-libs/compiler-rt``
+# - ``libgcc`` for ``sys-devel/gcc``'s libgcc
+#
+# If the runtime is not recognized, the function returns 1.
+tc-get-c-rtlib() {
+ local res=$(
+ $(tc-getCC) ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} \
+ -print-libgcc-file-name 2>/dev/null
+ )
+
+ case ${res} in
+ *libclang_rt*)
+ echo compiler-rt;;
+ *libgcc*)
+ echo libgcc;;
+ *)
+ return 1;;
+ esac
+
+ return 0
+}
+
fi
--
2.38.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [gentoo-dev] [PATCH 3/3] eclass/tests/toolchain-funcs.sh: Handle missing ld.gold gracefully
2022-10-08 9:43 [gentoo-dev] [PATCH 0/3] toolchain-funcs.eclass: support for querying C++ stdlib and compiler runtime Michał Górny
2022-10-08 9:43 ` [gentoo-dev] [PATCH 1/3] toolchain-funcs.eclass: Add tc-get-cxx-stdlib() to get C++ stdlib Michał Górny
2022-10-08 9:43 ` [gentoo-dev] [PATCH 2/3] toolchain-funcs.eclass: Add tc-get-c-rtlib() to get CC runtime Michał Górny
@ 2022-10-08 9:43 ` Michał Górny
2022-10-09 21:30 ` [gentoo-dev] [PATCH 0/3] toolchain-funcs.eclass: support for querying C++ stdlib and compiler runtime Sam James
3 siblings, 0 replies; 5+ messages in thread
From: Michał Górny @ 2022-10-08 9:43 UTC (permalink / raw
To: gentoo-dev; +Cc: Michał Górny
Signed-off-by: Michał Górny <mgorny@gentoo.org>
---
eclass/tests/toolchain-funcs.sh | 64 +++++++++++++++++----------------
1 file changed, 34 insertions(+), 30 deletions(-)
diff --git a/eclass/tests/toolchain-funcs.sh b/eclass/tests/toolchain-funcs.sh
index d8a357fb24fe..08cfd74611aa 100755
--- a/eclass/tests/toolchain-funcs.sh
+++ b/eclass/tests/toolchain-funcs.sh
@@ -60,20 +60,22 @@ tbegin "tc-ld-is-gold (ld=bfd cc=bfd)"
LD=ld.bfd LDFLAGS=-fuse-ld=bfd tc-ld-is-gold && ret=1 || ret=0
tend ${ret}
-tbegin "tc-ld-is-gold (ld=gold cc=default)"
-LD=ld.gold tc-ld-is-gold
-ret=$?
-tend ${ret}
-
-tbegin "tc-ld-is-gold (ld=gold cc=bfd)"
-LD=ld.gold LDFLAGS=-fuse-ld=bfd tc-ld-is-gold
-ret=$?
-tend ${ret}
-
-tbegin "tc-ld-is-gold (ld=bfd cc=gold)"
-LD=ld.bfd LDFLAGS=-fuse-ld=gold tc-ld-is-gold
-ret=$?
-tend ${ret}
+if type -P ld.gold &>/dev/null; then
+ tbegin "tc-ld-is-gold (ld=gold cc=default)"
+ LD=ld.gold tc-ld-is-gold
+ ret=$?
+ tend ${ret}
+
+ tbegin "tc-ld-is-gold (ld=gold cc=bfd)"
+ LD=ld.gold LDFLAGS=-fuse-ld=bfd tc-ld-is-gold
+ ret=$?
+ tend ${ret}
+
+ tbegin "tc-ld-is-gold (ld=bfd cc=gold)"
+ LD=ld.bfd LDFLAGS=-fuse-ld=gold tc-ld-is-gold
+ ret=$?
+ tend ${ret}
+fi
#
# TEST: tc-ld-disable-gold
@@ -87,23 +89,25 @@ tc-ld-disable-gold
)
tend $?
-tbegin "tc-ld-disable-gold (ld=gold)"
-(
-export LD=ld.gold LDFLAGS=
-ewarn() { :; }
-tc-ld-disable-gold
-[[ ${LD} == "ld.bfd" || ${LDFLAGS} == *"-fuse-ld=bfd"* ]]
-)
-tend $?
+if type -P ld.gold &>/dev/null; then
+ tbegin "tc-ld-disable-gold (ld=gold)"
+ (
+ export LD=ld.gold LDFLAGS=
+ ewarn() { :; }
+ tc-ld-disable-gold
+ [[ ${LD} == "ld.bfd" || ${LDFLAGS} == *"-fuse-ld=bfd"* ]]
+ )
+ tend $?
-tbegin "tc-ld-disable-gold (cc=gold)"
-(
-export LD= LDFLAGS="-fuse-ld=gold"
-ewarn() { :; }
-tc-ld-disable-gold
-[[ ${LD} == *"/ld.bfd" || ${LDFLAGS} == "-fuse-ld=gold -fuse-ld=bfd" ]]
-)
-tend $?
+ tbegin "tc-ld-disable-gold (cc=gold)"
+ (
+ export LD= LDFLAGS="-fuse-ld=gold"
+ ewarn() { :; }
+ tc-ld-disable-gold
+ [[ ${LD} == *"/ld.bfd" || ${LDFLAGS} == "-fuse-ld=gold -fuse-ld=bfd" ]]
+ )
+ tend $?
+fi
unset CPP
--
2.38.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [gentoo-dev] [PATCH 0/3] toolchain-funcs.eclass: support for querying C++ stdlib and compiler runtime
2022-10-08 9:43 [gentoo-dev] [PATCH 0/3] toolchain-funcs.eclass: support for querying C++ stdlib and compiler runtime Michał Górny
` (2 preceding siblings ...)
2022-10-08 9:43 ` [gentoo-dev] [PATCH 3/3] eclass/tests/toolchain-funcs.sh: Handle missing ld.gold gracefully Michał Górny
@ 2022-10-09 21:30 ` Sam James
3 siblings, 0 replies; 5+ messages in thread
From: Sam James @ 2022-10-09 21:30 UTC (permalink / raw
To: gentoo-dev; +Cc: Michał Górny, Gentoo Toolchain
[-- Attachment #1: Type: text/plain, Size: 719 bytes --]
> On 8 Oct 2022, at 10:43, Michał Górny <mgorny@gentoo.org> wrote:
>
> Hi,
>
> Here's a patchset adding two new functions along with tests:
>
> - tc-get-cxx-stdlib() that determines C++ stdlib used (libc++ vs
> libstdc++)
> - tc-get-c-rtlib() that determines C compiler runtime used (libgcc vs
> compiler-rt)
>
> I've also included a fix for tests failing if ld.gold is not installed.
>
All LGTM, although you forgot to CC toolchain@ ;)
>
> Michał Górny (3):
> toolchain-funcs.eclass: Add tc-get-cxx-stdlib() to get C++ stdlib
> toolchain-funcs.eclass: Add tc-get-c-rtlib() to get CC runtime
> eclass/tests/toolchain-funcs.sh: Handle missing ld.gold gracefully
Best,
sam
[-- Attachment #2: Message signed with OpenPGP --]
[-- Type: application/pgp-signature, Size: 358 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-10-09 21:30 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-08 9:43 [gentoo-dev] [PATCH 0/3] toolchain-funcs.eclass: support for querying C++ stdlib and compiler runtime Michał Górny
2022-10-08 9:43 ` [gentoo-dev] [PATCH 1/3] toolchain-funcs.eclass: Add tc-get-cxx-stdlib() to get C++ stdlib Michał Górny
2022-10-08 9:43 ` [gentoo-dev] [PATCH 2/3] toolchain-funcs.eclass: Add tc-get-c-rtlib() to get CC runtime Michał Górny
2022-10-08 9:43 ` [gentoo-dev] [PATCH 3/3] eclass/tests/toolchain-funcs.sh: Handle missing ld.gold gracefully Michał Górny
2022-10-09 21:30 ` [gentoo-dev] [PATCH 0/3] toolchain-funcs.eclass: support for querying C++ stdlib and compiler runtime Sam James
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox