Giter Site home page Giter Site logo

clear-code / meta-clang Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kraj/meta-clang

0.0 0.0 1.0 1.3 MB

Clang C/C++ cross compiler and runtime for OpenEmbedded/Yocto Project

License: MIT License

Shell 5.90% C++ 0.99% PHP 1.80% BlitzBasic 1.70% Makefile 0.10% BitBake 78.13% NASL 11.38%

meta-clang's Introduction

Yoe Distro CI

meta-clang (C/C++ frontend and LLVM compiler backend)

This layer provides clang/llvm as alternative to system C/C++ compiler for OpenEmbedded/Yocto Project based distributions. This can cohabit with GNU compiler and can be used for specific recipes or full system compiler.

Getting Started

git clone git://github.com/openembedded/openembedded-core.git
cd openembedded-core
git clone git://github.com/openembedded/bitbake.git
git clone git://github.com/kraj/meta-clang.git

$ . ./oe-init-build-env

If using poky ( Yocto project reference Distribution )

git clone https://git.yoctoproject.org/git/poky
cd poky
git clone git://github.com/kraj/meta-clang.git

$ . ./oe-init-build-env

Add meta-clang overlay

bitbake-layers add-layer ../meta-clang

Check conf/bblayers.conf to see that meta-clang is added to layer mix e.g.

Default Compiler

Note that by default gcc will remain the system compiler, however if you wish clang to be the default compiler then set

TOOLCHAIN ?= "clang"

in local.conf, this would now switch default cross-compiler to be clang you can select clang per recipe too by writing bbappends for them containing

TOOLCHAIN = "clang"

also look at conf/nonclangable.conf for list of recipes which do not yet fully build with clang.

Default Compiler Runtime

Default is to use GNU runtime 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

RUNTIME = "llvm"

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 best fit. e.g. below we select LLVM C++ as default C++ runtime.

LIBCPLUSPLUS = "-stdlib=libc++"

in local.conf. You can select libstdc++ per package too by writing bbappends for them containing

LIBCPLUSPLUS:toolchain-clang:pn-<recipe> = "-stdlibc=libc++"

Defaults are chosen to be GNU for maximum compatibility with existing GNU systems. It's always good to use single runtime on a system, mixing runtimes can cause complications during compilation as well as runtime. However, it's up to distribution policies to decide which runtime to use.

Adding clang in generated SDK toolchain

Clang based cross compiler is not included into the generated SDK using bitbake meta-toolchain or bitbake -cpopulate_sdk <image> if clang is expected to be part of SDK, add CLANGSDK = "1" in local.conf

CLANGSDK = "1"

Building

Below we build for qemuarm machine as an example

$ MACHINE=qemuarm bitbake core-image-full-cmdline

Running

$ runqemu nographic

Limitations

Few components do not build with clang, if you have a component to add to that list simply add it to conf/nonclangable.inc e.g.

TOOLCHAIN:pn-<recipe> = "gcc"

and OE will start using gcc to cross compile that recipe.

If a component does not build with libc++, you can add it to conf/nonclangable.inc e.g.

CXX:remove:pn-<recipe>:toolchain-clang = " -stdlib=libc++ "

compiler-rt failing in do_configure with custom TARGET_VENDOR

If your DISTRO sets own value of TARGET_VENDOR, then it's need to be added in CLANG_EXTRA_OE_VENDORS, it should be done automatically, but if compiler-rt fails like bellow, then check the end of work-shared/llvm-project-source-12.0.0-r0/temp/log.do_patch is should have line like: NOTE: Adding support following TARGET_VENDOR values: foo in /OE/build/oe-core/tmp-glibc/work-shared/llvm-project-source-12.0.0-r0/git/llvm/lib/Support/Triple.cpp and /OE/build/oe-core/tmp-glibc/work-shared/llvm-project-source-12.0.0-r0/git/clang/lib/Driver/ToolChains/Gnu.cpp and check these files if //CLANG_EXTRA_OE_VENDORS* strings were replaced correctly. Read add_more_target_vendors function in recipes-devtools/clang/llvm-project-source.inc for more details.

http://errors.yoctoproject.org/Errors/Details/574365/

-- 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
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- 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
-- 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
CMake 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):
  The 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"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: TOPDIR/tmp-glibc/work/core2-64-foo-linux/compiler-rt/12.0.0-r0/build/CMakeFiles/CMakeTmp

    Run Build Command(s):ninja cmTC_928f4 && [1/2] Building C object CMakeFiles/cmTC_928f4.dir/testCCompiler.c.o
    [2/2] Linking C executable cmTC_928f4

Dependencies

URI: git://github.com/openembedded/openembedded-core.git
branch: master
revision: HEAD

URI: git://github.com/openembedded/bitbake.git
branch: master
revision: HEAD

Contributing

You are encouraged to follow Github Pull request workflow to share changes and following commit message guidelines are recommended: OE patch guidelines.

Layer Maintainer: Khem Raj

meta-clang's People

Contributors

anujm1 avatar cosmo0920 avatar daniel-thompson avatar danieldittmann avatar dankm avatar davidlt avatar dl9pf avatar dsacre avatar esben avatar hongxu-jia avatar jpuhlman avatar jsbronder avatar kergoth avatar kkang-wr avatar kraj avatar leo-yan avatar lorac avatar mastag avatar mdavis777 avatar oocheret avatar otavio avatar ovpanait avatar ribalda avatar rossburton avatar saininav avatar sandy-lcq avatar shr-project avatar tworaz avatar walkthetalk avatar zboszor avatar

Forkers

isabella232

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.