Skip to content

Commit

Permalink
meta-clang: Replace RUNTIME with TC_CXX_RUNTIME
Browse files Browse the repository at this point in the history
TC_CXX_RUNTIME is now defined in OE-core

Signed-off-by: Khem Raj <[email protected]>
  • Loading branch information
kraj committed Oct 25, 2023
1 parent 4c65122 commit 41b7f52
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 23 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,26 +67,26 @@ PROVIDES:pn-nativesdk-clang = "nativesdk-llvm"
```
# Default Compiler Runtime

Default is to use GNU runtime `RUNTIME = "gnu"` which consists of libgcc, libstdc++ to provide C/C++
Default is to use GNU runtime `TC_CXX_RUNTIME = "gnu"` which consists of libgcc, libstdc++ to provide C/C++
runtime support. However it's possible to use LLVM runtime to replace it where
compile-rt, llvm libunwind, and libc++ are used to provide C/C++ runtime, while
GNU runtime works with both GCC and Clang, LLVM runtime is only tested with Clang
compiler, switching to use LLVM runtime is done via a config metadata knob

```shell
RUNTIME = "llvm"
TC_CXX_RUNTIME = "llvm"
```

RUNTIME variable influences individual runtime elements and can be set explicitly as well
TC_CXX_RUNTIME variable influences individual runtime elements and can be set explicitly as well
e.g. `LIBCPLUSPLUS` `COMPILER_RT` and `UNWINDLIB`.

Please note that this will still use crt files from GNU compiler always, while llvm now
do provide crt files, they have not been yet integrated into the toolchain.

# Default C++ Standard Library Switch

Using RUNTIME variable will select which C++ runtime is used, however it can be overridden
if needed to by modifying `LIBCPLUSPLUS` variable, usually defaults used by `RUNTIME` are
Using TC_CXX_RUNTIME variable will select which C++ runtime is used, however it can be overridden
if needed to by modifying `LIBCPLUSPLUS` variable, usually defaults used by `TC_CXX_RUNTIME` are
best fit. e.g. below we select LLVM C++ as default C++ runtime.

```shell
Expand Down
18 changes: 9 additions & 9 deletions classes/clang.bbclass
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ DEBUG_PREFIX_MAP:remove:toolchain-clang = "-fcanon-prefix-map"
# choose between 'gcc' 'clang' an empty '' can be used as well
TOOLCHAIN ??= "gcc"
# choose between 'gnu' 'llvm'
RUNTIME ??= "gnu"
TC_CXX_RUNTIME ??= "gnu"
# Using gcc or llvm runtime is only available when using clang for compiler
#RUNTIME:toolchain-gcc = "gnu"
RUNTIME:armeb = "gnu"
RUNTIME:armv5 = "gnu"
#TC_CXX_RUNTIME:toolchain-gcc = "gnu"
TC_CXX_RUNTIME:armeb = "gnu"
TC_CXX_RUNTIME:armv5 = "gnu"

TOOLCHAIN:class-native = "gcc"
TOOLCHAIN:class-nativesdk = "gcc"
Expand All @@ -88,8 +88,8 @@ TOOLCHAIN:class-crosssdk = "gcc"
TOOLCHAIN:class-cross = "gcc"

OVERRIDES =. "${@['', 'toolchain-${TOOLCHAIN}:']['${TOOLCHAIN}' != '']}"
OVERRIDES =. "${@['', 'runtime-${RUNTIME}:']['${RUNTIME}' != '']}"
OVERRIDES[vardepsexclude] += "TOOLCHAIN RUNTIME"
OVERRIDES =. "${@['', 'runtime-${TC_CXX_RUNTIME}:']['${TC_CXX_RUNTIME}' != '']}"
OVERRIDES[vardepsexclude] += "TOOLCHAIN TC_CXX_RUNTIME"

YOCTO_ALTERNATE_EXE_PATH:toolchain-clang:class-target = "${STAGING_BINDIR}/llvm-config"
YOCTO_ALTERNATE_LIBDIR:toolchain-clang:class-target = "/${BASELIB}"
Expand All @@ -104,16 +104,16 @@ def clang_base_deps(d):
if not d.getVar('INHIBIT_DEFAULT_DEPS', False):
if not oe.utils.inherits(d, 'allarch') :
ret = " ${MLPREFIX}clang-cross-${TARGET_ARCH} virtual/libc "
if (d.getVar('RUNTIME').find('android') != -1):
if (d.getVar('TC_CXX_RUNTIME').find('android') != -1):
ret += " libcxx"
return ret
if (d.getVar('RUNTIME').find('llvm') != -1):
if (d.getVar('TC_CXX_RUNTIME').find('llvm') != -1):
ret += " compiler-rt"
elif (d.getVar('COMPILER_RT').find('-rtlib=compiler-rt') != -1):
ret += " compiler-rt "
else:
ret += " libgcc "
if (d.getVar('RUNTIME').find('llvm') != -1):
if (d.getVar('TC_CXX_RUNTIME').find('llvm') != -1):
ret += " libcxx"
elif (d.getVar('COMPILER_RT').find('--unwindlib=libunwind') != -1):
ret += " libcxx "
Expand Down
2 changes: 1 addition & 1 deletion conf/layer.conf
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ BBFILES_DYNAMIC += " \

PREFERRED_PROVIDER_libgcc-initial = "libgcc-initial"
#PREFERRED_PROVIDER_virtual/${TARGET_PREFIX}compilerlibs_forcevariable = "libcxx"
PREFERRED_PROVIDER_libunwind = "${@bb.utils.contains_any("RUNTIME", "llvm android", "libcxx", "libunwind", d)}"
PREFERRED_PROVIDER_libunwind = "${@bb.utils.contains_any("TC_CXX_RUNTIME", "llvm android", "libcxx", "libunwind", d)}"
INHERIT += "clang"

# Do not include clang in SDK unless user wants to
Expand Down
6 changes: 3 additions & 3 deletions recipes-devtools/clang/clang_git.bb
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ def get_clang_experimental_target_arch(bb, d):

PACKAGECONFIG ??= "compiler-rt libcplusplus shared-libs lldb-wchar \
${@bb.utils.filter('DISTRO_FEATURES', 'thin-lto lto', d)} \
${@bb.utils.contains('RUNTIME', 'llvm', 'compiler-rt libcplusplus unwindlib libomp', '', d)} \
${@bb.utils.contains('TC_CXX_RUNTIME', 'llvm', 'compiler-rt libcplusplus unwindlib libomp', '', d)} \
rtti eh libedit terminfo \
"
PACKAGECONFIG:class-native = "rtti eh libedit shared-libs ${@bb.utils.contains('RUNTIME', 'llvm', 'compiler-rt libcplusplus unwindlib libomp', '', d)}"
PACKAGECONFIG:class-nativesdk = "rtti eh libedit shared-libs ${@bb.utils.filter('DISTRO_FEATURES', 'thin-lto lto', d)} ${@bb.utils.contains('RUNTIME', 'llvm', 'compiler-rt libcplusplus unwindlib libomp', '', d)}"
PACKAGECONFIG:class-native = "rtti eh libedit shared-libs ${@bb.utils.contains('TC_CXX_RUNTIME', 'llvm', 'compiler-rt libcplusplus unwindlib libomp', '', d)}"
PACKAGECONFIG:class-nativesdk = "rtti eh libedit shared-libs ${@bb.utils.filter('DISTRO_FEATURES', 'thin-lto lto', d)} ${@bb.utils.contains('TC_CXX_RUNTIME', 'llvm', 'compiler-rt libcplusplus unwindlib libomp', '', d)}"

PACKAGECONFIG[compiler-rt] = "-DCLANG_DEFAULT_RTLIB=compiler-rt,,"
PACKAGECONFIG[libcplusplus] = "-DCLANG_DEFAULT_CXX_STDLIB=libc++,,"
Expand Down
2 changes: 1 addition & 1 deletion recipes-devtools/clang/compiler-rt-sanitizers_git.bb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ EXTRA_OECMAKE += "-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DCMAKE_C_COMPILER_TARGET=${HOST_ARCH}${HOST_VENDOR}-${HOST_OS}${HF} \
-DCOMPILER_RT_BUILD_BUILTINS=OFF \
-DCOMPILER_RT_INCLUDE_TESTS=OFF \
-DSANITIZER_CXX_ABI_LIBNAME=${@bb.utils.contains("RUNTIME", "llvm", "libc++", "libstdc++", d)} \
-DSANITIZER_CXX_ABI_LIBNAME=${@bb.utils.contains("TC_CXX_RUNTIME", "llvm", "libc++", "libstdc++", d)} \
-DCOMPILER_RT_BUILD_XRAY=ON \
-DCOMPILER_RT_BUILD_SANITIZERS=ON \
-DCOMPILER_RT_BUILD_LIBFUZZER=ON \
Expand Down
6 changes: 3 additions & 3 deletions recipes-devtools/clang/libcxx_git.bb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require common-source.inc

inherit cmake cmake-native python3native

PACKAGECONFIG ??= "compiler-rt exceptions ${@bb.utils.contains("RUNTIME", "llvm", "unwind unwind-shared", "", d)}"
PACKAGECONFIG ??= "compiler-rt exceptions ${@bb.utils.contains("TC_CXX_RUNTIME", "llvm", "unwind unwind-shared", "", d)}"
PACKAGECONFIG:append:armv5 = " no-atomics"
PACKAGECONFIG:remove:class-native = "compiler-rt"
PACKAGECONFIG[unwind] = "-DLIBCXXABI_USE_LLVM_UNWINDER=ON -DLIBCXXABI_ENABLE_STATIC_UNWINDER=ON,-DLIBCXXABI_USE_LLVM_UNWINDER=OFF,,"
Expand Down Expand Up @@ -50,7 +50,7 @@ LIC_FILES_CHKSUM = "file://libcxx/LICENSE.TXT;md5=55d89dd7eec8d3b4204b680e27da39
"

OECMAKE_TARGET_COMPILE = "cxxabi cxx"
OECMAKE_TARGET_INSTALL = "install-cxx install-cxxabi ${@bb.utils.contains("RUNTIME", "llvm", "install-unwind", "", d)}"
OECMAKE_TARGET_INSTALL = "install-cxx install-cxxabi ${@bb.utils.contains("TC_CXX_RUNTIME", "llvm", "install-unwind", "", d)}"

OECMAKE_SOURCEPATH = "${S}/llvm"
EXTRA_OECMAKE += "\
Expand Down Expand Up @@ -97,7 +97,7 @@ ALLOW_EMPTY:${PN} = "1"
PROVIDES:append:runtime-llvm = " libunwind"

do_install:append() {
if ${@bb.utils.contains("RUNTIME", "llvm", "true", "false", d)}
if ${@bb.utils.contains("TC_CXX_RUNTIME", "llvm", "true", "false", d)}
then
for f in libunwind.h __libunwind_config.h unwind.h unwind_itanium.h unwind_arm_ehabi.h
do
Expand Down
2 changes: 1 addition & 1 deletion recipes-extended/ghostscript/ghostscript_%.bbappend
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"

do_configure:prepend:toolchain-clang () {
if ${@bb.utils.contains('RUNTIME', 'llvm', 'true', 'false', d)}; then
if ${@bb.utils.contains('TC_CXX_RUNTIME', 'llvm', 'true', 'false', d)}; then
sed -i -e "s|-stdlib=libstdc++|-stdlib=libc++|g" ${S}/configure.ac
fi
}

0 comments on commit 41b7f52

Please sign in to comment.