{"id":16521612,"url":"https://github.com/kraj/meta-clang","last_synced_at":"2025-05-15T20:04:00.110Z","repository":{"id":20658427,"uuid":"23940688","full_name":"kraj/meta-clang","owner":"kraj","description":"Clang C/C++ cross compiler and runtime for OpenEmbedded/Yocto Project","archived":false,"fork":false,"pushed_at":"2025-05-06T13:14:52.000Z","size":2581,"stargazers_count":178,"open_issues_count":55,"forks_count":226,"subscribers_count":17,"default_branch":"master","last_synced_at":"2025-05-06T14:37:15.977Z","etag":null,"topics":["bitbake","c","clang","compilers","cross-compiler","llvm","sdk","yocto"],"latest_commit_sha":null,"homepage":"","language":"BitBake","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kraj.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"COPYING.MIT","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":"SECURITY","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2014-09-12T00:20:53.000Z","updated_at":"2025-05-06T13:14:57.000Z","dependencies_parsed_at":"2023-11-22T16:28:01.649Z","dependency_job_id":"a514abba-022e-4e4d-9bf1-a9c6984b6e1f","html_url":"https://github.com/kraj/meta-clang","commit_stats":{"total_commits":1585,"total_committers":109,"mean_commits":"14.541284403669724","dds":"0.19369085173501577","last_synced_commit":"275d0a5ed688886e907deb71e4ec6fd94fd24f91"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kraj%2Fmeta-clang","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kraj%2Fmeta-clang/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kraj%2Fmeta-clang/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kraj%2Fmeta-clang/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kraj","download_url":"https://codeload.github.com/kraj/meta-clang/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254414497,"owners_count":22067272,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bitbake","c","clang","compilers","cross-compiler","llvm","sdk","yocto"],"created_at":"2024-10-11T16:57:08.120Z","updated_at":"2025-05-15T20:03:59.314Z","avatar_url":"https://github.com/kraj.png","language":"BitBake","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Yoe Distro CI](https://github.com/kraj/meta-clang/workflows/Yoe%20Distro%20CI/badge.svg?branch=master)](https://github.com/kraj/meta-clang/actions/workflows/yoe.yml?query=workflow%3AYoe+branch%3Amaster)\n\u003ctable border=\"0\" rules=\"none\"\u003e\n\u003ctr border=\"0\"\u003e\n\u003ctd width=\"250\" height=\"150\"\u003e\u003cimg alt=\"Yocto Project Layer Compatible\"\nsrc=\"images/Yocto_Project™_Badge_Compatible_Web_RGB.png\"\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/table\u003e\n\n# meta-clang (C/C++ frontend and LLVM compiler backend)\n\nThis layer provides [clang/llvm](http://clang.llvm.org/) as alternative to system\nC/C++ compiler for OpenEmbedded/Yocto Project based distributions. This can cohabit\nwith GNU compiler and can be used for specific recipes or full system compiler.\n\n# Getting Started\n\n```shell\ngit clone https://github.com/openembedded/openembedded-core.git\ncd openembedded-core\ngit clone https://github.com/openembedded/bitbake.git\ngit clone https://github.com/kraj/meta-clang.git\n\n$ . ./oe-init-build-env\n```\nIf using poky ( Yocto project reference Distribution )\n\n```shell\ngit clone https://git.yoctoproject.org/git/poky\ncd poky\ngit clone https://github.com/kraj/meta-clang.git\n\n$ . ./oe-init-build-env\n```\n\nAdd meta-clang overlay\n```\nbitbake-layers add-layer ../meta-clang\n```\n\nCheck `conf/bblayers.conf` to see that meta-clang is added to layer mix e.g.\n\n# Default Compiler\n\nNote that by default gcc will remain the system compiler, however if you wish\nclang to be the default compiler then set\n\n```shell\nTOOLCHAIN ?= \"clang\"\n```\n\nin `local.conf`, this would now switch default cross-compiler to be clang\nyou can select clang per recipe too by writing bbappends for them containing\n\n```shell\nTOOLCHAIN = \"clang\"\n```\nalso look at `conf/nonclangable.conf` for list of recipes which do not yet fully\nbuild with clang.\n\n# Providing LLVM\n\nclang recipes can provide llvm and related packages too, it might be worth using single\nprovider for llvm and clang to save some compile time and space, select the knobs\nto point to clang, default is to use the version provided by core layer.\n\n```shell\nPREFERRED_PROVIDER_llvm = \"clang\"\nPREFERRED_PROVIDER_llvm-native = \"clang-native\"\nPREFERRED_PROVIDER_nativesdk-llvm = \"nativesdk-clang\"\nPROVIDES:pn-clang = \"llvm\"\nPROVIDES:pn-clang-native = \"llvm-native\"\nPROVIDES:pn-nativesdk-clang = \"nativesdk-llvm\"\n```\n# Default Compiler Runtime\n\nDefault is to use GNU runtime `TC_CXX_RUNTIME = \"gnu\"` which consists of libgcc, libstdc++ to provide C/C++\nruntime support. However it's possible to use LLVM runtime to replace it where\ncompile-rt, llvm libunwind, and libc++ are used to provide C/C++ runtime, while\nGNU runtime works with both GCC and Clang, LLVM runtime is only tested with Clang\ncompiler, switching to use LLVM runtime is done via a config metadata knob\n\n```shell\nTC_CXX_RUNTIME = \"llvm\"\n```\n\nTC_CXX_RUNTIME variable influences individual runtime elements and can be set explicitly as well\ne.g. `LIBCPLUSPLUS` `COMPILER_RT` and `UNWINDLIB`.\n\nPlease note that this will still use crt files from GNU compiler always, while llvm now\ndo provide crt files, they have not been yet integrated into the toolchain.\n\n# Default C++ Standard Library Switch\n\nUsing TC_CXX_RUNTIME variable will select which C++ runtime is used, however it can be overridden\nif needed to by modifying `LIBCPLUSPLUS` variable, usually defaults used by `TC_CXX_RUNTIME` are\nbest fit. e.g. below we select LLVM C++ as default C++ runtime.\n\n```shell\nLIBCPLUSPLUS = \"-stdlib=libc++\"\n```\n\nin `local.conf`.\nYou can select libstdc++ per package too by writing bbappends for them containing\n\n```shell\nLIBCPLUSPLUS:toolchain-clang:pn-\u003crecipe\u003e = \"-stdlib=libc++\"\n```\nDefaults are chosen to be GNU for maximum compatibility with existing GNU systems. It's always\ngood to use single runtime on a system, mixing runtimes can cause complications during\ncompilation as well as runtime. However, it's up to distribution policies to decide which runtime\nto use.\n\n# Adding clang in generated SDK toolchain\n\nClang based cross compiler is not included into the generated SDK using `bitbake meta-toolchain` or\n`bitbake -cpopulate_sdk \u003cimage\u003e` if clang is expected to be part of SDK, add `CLANGSDK = \"1\"`\nin `local.conf`\n\n```shell\nCLANGSDK = \"1\"\n```\n\n# Kernel build with clang\nNewer kernels and Android kernels support clang compilation, and even support LTO, The following takes [rockchip](https://github.com/JeffyCN/meta-rockchip)'s kernel as an example to configure clang compilation. x86, arm and arm64 kernel supported full LLVM toolchain, other arch only support clang. more info https://docs.kernel.org/kbuild/llvm.html\n\n- linux-rockchip_%bbappend\n```shell\nTOOLCHAIN:forcevariable = \"clang\"\n\nDEPENDS:append:toolchain-clang = \" clang-cross-${TARGET_ARCH}\"\nKERNEL_CC:toolchain-clang = \"${CCACHE}clang ${HOST_CC_KERNEL_ARCH} -fuse-ld=lld ${DEBUG_PREFIX_MAP} -fdebug-prefix-map=${STAGING_KERNEL_DIR}=${KERNEL_SRC_PATH}\"\nKERNEL_LD:toolchain-clang = \"${CCACHE}ld.lld\"\nKERNEL_AR:toolchain-clang = \"${CCACHE}llvm-ar\"\n```\nif you want use LLVM integrated assembler for some older kernel, newer vesion is enabled default.\n```shell\ndo_compile:prepend:toolchain-clang() {\n\texport LLVM_IAS=1\n}\n\ndo_compile_kernelmodules:prepend:toolchain-clang() {\n\texport LLVM_IAS=1\n}\n```\nif you want enable LTO, append follow content.\n```\nFILESEXTRAPATHS:prepend := \"${THISDIR}/${PN}:\"\nSRC_URI:append:toolchain-clang = \"\\\n\tfile://lto.cfg \\\n\"\n```\n\n`CONFIG_LTO_CLANG`is need for some android based kernel, mainline kernel will do auto detect.\n\n- lto.cfg\n```\nCONFIG_LTO_CLANG=y\nCONFIG_LTO=y\nCONFIG_LTO_CLANG_THIN=y\n```\n\n\n# Building\n\nBelow we build for qemuarm machine as an example\n\n```shell\n$ MACHINE=qemuarm bitbake core-image-full-cmdline\n```\n# Running\n\n```shell\n$ runqemu nographic\n```\n\n# Limitations\n\nFew components do not build with clang, if you have a component to add to that list\nsimply add it to `conf/nonclangable.inc` e.g.\n\n```shell\nTOOLCHAIN:pn-\u003crecipe\u003e = \"gcc\"\n```\n\nand OE will start using gcc to cross compile that recipe.\n\nIf a component does not build with libc++, you can add it to `conf/nonclangable.inc` e.g.\n\n```shell\nCXX:remove:pn-\u003crecipe\u003e:toolchain-clang = \" -stdlib=libc++ \"\n```\n\n# compiler-rt failing in do_configure with custom TARGET_VENDOR\n\nIf your DISTRO sets its own value of TARGET_VENDOR, then it needs to be added in\nCLANG_EXTRA_OE_VENDORS, it should be done automatically, but if compiler-rt fails\nlike bellow, then check the end of work-shared/llvm-project-source-12.0.0-r0/temp/log.do_patch\nit should have a line like:\nNOTE: Adding support following TARGET_VENDOR values: foo in\n  /OE/build/oe-core/tmp-glibc/work-shared/llvm-project-source-12.0.0-r0/git/llvm/lib/Support/Triple.cpp and\n  /OE/build/oe-core/tmp-glibc/work-shared/llvm-project-source-12.0.0-r0/git/clang/lib/Driver/ToolChains/Gnu.cpp\nand check these files if //CLANG_EXTRA_OE_VENDORS* strings were replaced correctly.\nRead add_distro_vendor function in recipes-devtools/clang/llvm-project-source.inc for more details.\n\nhttp://errors.yoctoproject.org/Errors/Details/574365/\n```shell\n-- Found assembler: TOPDIR/tmp-glibc/work/core2-64-foo-linux/compiler-rt/12.0.0-r0/recipe-sysroot-native/usr/bin/x86_64-foo-linux/x86_64-foo-linux-clang\n-- Detecting C compiler ABI info\n-- Detecting C compiler ABI info - failed\n-- Check for working C compiler: TOPDIR/tmp-glibc/work/core2-64-foo-linux/compiler-rt/12.0.0-r0/recipe-sysroot-native/usr/bin/x86_64-foo-linux/x86_64-foo-linux-clang\n-- Check for working C compiler: TOPDIR/tmp-glibc/work/core2-64-foo-linux/compiler-rt/12.0.0-r0/recipe-sysroot-native/usr/bin/x86_64-foo-linux/x86_64-foo-linux-clang - broken\nCMake Error at TOPDIR/tmp-glibc/work/core2-64-foo-linux/compiler-rt/12.0.0-r0/recipe-sysroot-native/usr/share/cmake-3.19/Modules/CMakeTestCCompiler.cmake:66 (message):\n  The C compiler\n\n    \"TOPDIR/tmp-glibc/work/core2-64-foo-linux/compiler-rt/12.0.0-r0/recipe-sysroot-native/usr/bin/x86_64-foo-linux/x86_64-foo-linux-clang\"\n\n  is not able to compile a simple test program.\n\n  It fails with the following output:\n\n    Change Dir: TOPDIR/tmp-glibc/work/core2-64-foo-linux/compiler-rt/12.0.0-r0/build/CMakeFiles/CMakeTmp\n\n    Run Build Command(s):ninja cmTC_928f4 \u0026\u0026 [1/2] Building C object CMakeFiles/cmTC_928f4.dir/testCCompiler.c.o\n    [2/2] Linking C executable cmTC_928f4\n```\n\n# Dependencies\n\n```shell\nURI: https://github.com/openembedded/openembedded-core.git\nbranch: master\nrevision: HEAD\n\nURI: ghttps://github.com/openembedded/bitbake.git\nbranch: master\nrevision: HEAD\n```\n# Using Devtool and Upstream Development\n\nAll LLVM based recipes use single llvm source directory, As a LLVM\ndeveloper, you might want to work on your own repository to build\nrelated recipes, devtool can we useful in establishing such a workflow\nthere is a script provided `scripts/devtool-clang.sh` which can assist\nin setting up all the recipes to use custom LLVM repository, in order\nto setup repository make sure that it has all the needed patches applied\nor else it will fail to build. Such a tree is already prepared and kept\nin sync at\n\nhttps://github.com/kraj/llvm-project\n\nThere are branches under `oe` namespace which carry the needed OE patches\n\n```\ncd $TOPDIR/workspace/sources\ngit clone https://github.com/kraj/llvm-project -b oe/main llvm-project\n```\n\nOnce project is setup and meta-clang is added, run `devtool-clang.sh`\nscript which will do the needed for setting up external sources for the\nyocto recipes, now yocto will use custom LLVM tree for its needs.\n\n# Contributing\n\nYou are encouraged to follow Github Pull request workflow\nto share changes and following commit message guidelines are recommended: [OE patch guidelines](https://www.openembedded.org/wiki/Commit_Patch_Message_Guidelines).\n\nLayer Maintainer: [Khem Raj](\u003cmailto:raj.khem@gmail.com\u003e)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkraj%2Fmeta-clang","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkraj%2Fmeta-clang","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkraj%2Fmeta-clang/lists"}