From 95ed0e9103abbe36ad4f7a91a6abd5d2472ecb1e Mon Sep 17 00:00:00 2001 From: Khem Raj Date: Tue, 21 Oct 2025 23:07:26 -0700 Subject: [PATCH] meta: Enable clang as default native compiler Fix few packages which do not yet build with clang There is one issue to tackle, when using clang for cross compiler it also installs native clang which is then picked by the build system if a package's build system has pieces to build for native build host There are only handful of such packages but there are few e.g. gmp, nettle which check for CC_FOR_BUILD during configure and it ends up using clang from own build and does not find right libraries in native sysroot, maybe we should add libcxx-native and compiler-rt-native to DEFAULT_DEPENDENCIES list when llvm runtime is used. gobject-introspection uses gcc for native builds Its fails when built with clang FileNotFoundError: [Errno 2] No such file or directory: 'ldd' ... | FAILED: [code=1] gir/GLib-2.0.gir Signed-off-by: Khem Raj --- meta/classes/toolchain/clang-native.bbclass | 5 ++--- meta/conf/bitbake.conf | 6 ++++-- meta/recipes-devtools/clang/common-clang.inc | 3 +++ .../gobject-introspection/gobject-introspection_1.84.0.bb | 2 ++ meta/recipes-support/gmp/gmp_6.3.0.bb | 2 ++ meta/recipes-support/nettle/nettle_3.10.2.bb | 2 ++ 6 files changed, 15 insertions(+), 5 deletions(-) diff --git a/meta/classes/toolchain/clang-native.bbclass b/meta/classes/toolchain/clang-native.bbclass index 006be9fadd..941a5fd6e4 100644 --- a/meta/classes/toolchain/clang-native.bbclass +++ b/meta/classes/toolchain/clang-native.bbclass @@ -13,6 +13,5 @@ BUILD_OBJDUMP = "${BUILD_PREFIX}llvm-objdump" BUILD_NM = "${BUILD_PREFIX}llvm-nm" BUILD_READELF = "${BUILD_PREFIX}llvm-readelf" -DEPENDS += "clang-native libcxx-native compiler-rt-native" - -BUILD_LDFLAGS += " --rtlib=libgcc --unwindlib=libgcc" +BUILD_LDFLAGS += "-rtlib=libgcc -unwindlib=libgcc -stdlib=libc++" +BUILD_CXXFLAGS += "-stdlib=libc++" diff --git a/meta/conf/bitbake.conf b/meta/conf/bitbake.conf index 5406e542db..6a77a4461f 100644 --- a/meta/conf/bitbake.conf +++ b/meta/conf/bitbake.conf @@ -516,10 +516,12 @@ HOSTTOOLS_DIR = "${TMPDIR}/hosttools" # Tools needed to run builds with OE-Core HOSTTOOLS += " \ - [ ar as awk basename bash bunzip2 bzip2 cat chgrp chmod chown chrpath cmp comm cp cpio \ + [ ar as awk basename bash bunzip2 bzip2 cat chgrp chmod chown chrpath clang clang++ cmp comm cp cpio \ cpp cut date dd diff diffstat dirname du echo egrep env expand expr false \ fgrep file find flock g++ gawk gcc getconf getopt git grep gunzip gzip \ - head hostname iconv id install ld ldd ln ls make md5sum mkdir mkfifo mknod \ + head hostname iconv id install ld ld.lld lld llvm-ar llvm-as llvm-config llvm-nm \ + llvm-objcopy llvm-objdump llvm-nm llvm-ranlib llvm-readelf llvm-strip llvm-config \ + ln ls make md5sum mkdir mkfifo mknod \ mktemp mv nm objcopy objdump od patch perl pr printf pwd \ python3 pzstd ranlib readelf readlink realpath rm rmdir rpcgen sed seq sh \ sha1sum sha224sum sha256sum sha384sum sha512sum \ diff --git a/meta/recipes-devtools/clang/common-clang.inc b/meta/recipes-devtools/clang/common-clang.inc index 416258c5d3..351e7afa3e 100644 --- a/meta/recipes-devtools/clang/common-clang.inc +++ b/meta/recipes-devtools/clang/common-clang.inc @@ -56,4 +56,7 @@ EXTRA_OECMAKE += "-DCMAKE_BUILD_WITH_INSTALL_RPATH=ON" # will include the git server URL. EXTRA_OECMAKE += "-DLLVM_APPEND_VC_REV=OFF" +# Enable linking with libc++ when its the distro default C++ runtime +EXTRA_OECMAKE += "${@bb.utils.contains('TC_CXX_RUNTIME', 'llvm', '-DLLVM_ENABLE_LIBCXX=ON', '', d)}" + require common.inc diff --git a/meta/recipes-gnome/gobject-introspection/gobject-introspection_1.84.0.bb b/meta/recipes-gnome/gobject-introspection/gobject-introspection_1.84.0.bb index f6797cd2e5..07fc284fb3 100644 --- a/meta/recipes-gnome/gobject-introspection/gobject-introspection_1.84.0.bb +++ b/meta/recipes-gnome/gobject-introspection/gobject-introspection_1.84.0.bb @@ -22,6 +22,8 @@ SRC_URI:append:class-native = " file://0001-Relocate-the-repository-directory-fo inherit meson pkgconfig gtk-doc python3targetconfig qemu gobject-introspection-data upstream-version-is-even multilib_script +TOOLCHAIN_NATIVE = "gcc" + GTKDOC_MESON_OPTION = "gtk_doc" MULTILIB_SCRIPTS = "${PN}-tools:${bindir}/g-ir-annotation-tool ${PN}-tools:${bindir}/g-ir-scanner" diff --git a/meta/recipes-support/gmp/gmp_6.3.0.bb b/meta/recipes-support/gmp/gmp_6.3.0.bb index 8f18bdca1b..d3bd36f4e0 100644 --- a/meta/recipes-support/gmp/gmp_6.3.0.bb +++ b/meta/recipes-support/gmp/gmp_6.3.0.bb @@ -22,6 +22,8 @@ SRC_URI[sha256sum] = "ac28211a7cfb609bae2e2c8d6058d66c8fe96434f740cf6fe2e47b000d EXTRA_OECONF += " --enable-cxx=detect" EXTRA_OECONF:append:mipsarchr6 = " --disable-assembly" +TOOLCHAIN_NATIVE:class-target = "gcc" + PACKAGES =+ "libgmpxx" FILES:libgmpxx = "${libdir}/libgmpxx${SOLIBS}" diff --git a/meta/recipes-support/nettle/nettle_3.10.2.bb b/meta/recipes-support/nettle/nettle_3.10.2.bb index e651f68cb9..e6c21f976b 100644 --- a/meta/recipes-support/nettle/nettle_3.10.2.bb +++ b/meta/recipes-support/nettle/nettle_3.10.2.bb @@ -14,6 +14,8 @@ LIC_FILES_CHKSUM = "file://COPYING.LESSERv3;md5=6a6a8e020838b23406c81b19c1d46df6 DEPENDS += "gmp" +TOOLCHAIN_NATIVE:class-target = "gcc" + SRC_URI = "${GNU_MIRROR}/${BPN}/${BP}.tar.gz \ file://Add-target-to-only-build-tests-not-run-them.patch \ file://run-ptest \ -- 2.47.3