summaryrefslogtreecommitdiffstats
path: root/README.md
diff options
context:
space:
mode:
Diffstat (limited to 'README.md')
-rw-r--r--README.md113
1 files changed, 84 insertions, 29 deletions
diff --git a/README.md b/README.md
index 5541396..3aa42da 100644
--- a/README.md
+++ b/README.md
@@ -1,9 +1,10 @@
1[![Build Status](https://drone.yoedistro.org/api/badges/kraj/meta-clang/status.svg)](https://drone.yoedistro.org/kraj/meta-clang) 1[![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)
2 2
3# meta-clang (a C language family frontend and LLVM compiler backend) 3# meta-clang (C/C++ frontend and LLVM compiler backend)
4 4
5This layer provides [clang/llvm](http://clang.llvm.org/) as alternative to your system 5This layer provides [clang/llvm](http://clang.llvm.org/) as alternative to system
6C/C++ compiler for OpenEmbedded based distributions along with gcc 6C/C++ compiler for OpenEmbedded/Yocto Project based distributions. This can cohabit
7with GNU Compiler and can be used for specific recipes or full system Compiler
7 8
8# Getting Started 9# Getting Started
9 10
@@ -15,6 +16,15 @@ git clone git://github.com/kraj/meta-clang.git
15 16
16$ . ./oe-init-build-env 17$ . ./oe-init-build-env
17``` 18```
19If using poky ( Yocto project reference Distribution )
20
21```shell
22git clone https://git.yoctoproject.org/git/poky
23cd poky
24git clone git://github.com/kraj/meta-clang.git
25
26$ . ./oe-init-build-env
27```
18 28
19Add meta-clang overlay 29Add meta-clang overlay
20``` 30```
@@ -23,7 +33,7 @@ bitbake-layers add-layer ../meta-clang
23 33
24Check `conf/bblayers.conf` to see that meta-clang is added to layer mix e.g. 34Check `conf/bblayers.conf` to see that meta-clang is added to layer mix e.g.
25 35
26# Default Compiler Switch 36# Default Compiler
27 37
28Note that by default gcc will remain the system compiler, however if you wish 38Note that by default gcc will remain the system compiler, however if you wish
29clang to be the default compiler then set 39clang to be the default compiler then set
@@ -38,45 +48,56 @@ you can select clang per recipe too by writing bbappends for them containing
38```shell 48```shell
39TOOLCHAIN = "clang" 49TOOLCHAIN = "clang"
40``` 50```
51also look at `conf/nonclangable.conf` for list of recipes which do not yet fully
52build with clang
41 53
42# Default C++ Standard Library Switch 54# Default Compiler Runtime
43 55
44Note that by default clang libc++ is default C++ standard library, however if you wish 56Default is to use GNU runtime `RUNTIME = "gnu"` which consists of libgcc, libstdc++ to provide C/C++
45to keep GNU libstdc++ to be the default then set 57runtime support. However its possible to use LLVM runtime to replace it where
58compile-rt, llvm libunwind, and libc++ are used to provide C/C++ runtime, while
59GNU runtime works with both GCC and Clang, LLVM runtime is only tested with Clang
60compiler, Switching to use LLVM runtime is done via a config metadata knob
46 61
47```shell 62```shell
48LIBCPLUSPLUS = "" 63RUNTIME = "llvm"
49``` 64```
50 65
51in `local.conf`. 66RUNTIME variable influences individual runtime elements and can be set explcitly as well
52You can select libstdc++ per package too by writing bbappends for them containing 67e.g. `LIBCPLUSPLUS` `COMPILER_RT` and `UNWINDLIB`
53 68
54```shell 69Please note that this will still use crt files from GNU compiler always, while llvm now
55LIBCPLUSPLUS_toolchain-clang_pn-<recipe> = "" 70do provide crt files, they have not been yet intergrated into toolchain
56```
57 71
58# Default Compiler Runtime ( Compiler-rt + libc++ ) 72# Default C++ Standard Library Switch
59 73
60By default, clang build from meta-clang uses clang runtime ( compiler-rt + libc++ + libunwind ) out of box 74Using RUNTIME bariable will select which C++ runtime is used, however it can be overridden
61However, it is possible to switch to using gcc runtime as default, In order to do that 75if needed to by modifying `LIBCPLUSPLUS` variable, usually defaults used by `RUNTIME` is
62following settings are needed in site configurations e.g. in `local.conf` 76best fit. e.g. below we select LLVM C++ as default C++ runtime.
63 77
64```shell 78```shell
65TOOLCHAIN ?= "clang" 79LIBCPLUSPLUS = "-stdlib=libc++"
66LIBCPLUSPLUS = "" 80```
67COMPILER_RT = ""
68UNWINDLIB = ""
69 81
82in `local.conf`.
83You can select libstdc++ per package too by writing bbappends for them containing
84
85```shell
86LIBCPLUSPLUS_toolchain-clang_pn-<recipe> = "-stdlibc=libc++"
70``` 87```
88Defaults are chosen to be GNU for maximum compatibility with existing GNU systems. Its always
89good to use single runtime on a system, mixing runtimes can cause complications during
90compilation as well as runtime. However, its upto distribution policies to decide which runtime
91to use.
71 92
72# Removing clang from generated SDK toolchain 93# Adding clang in generated SDK toolchain
73 94
74clang based cross compiler is automatically included into the generated SDK using `bitbake meta-toolchain` or 95clang based cross compiler is not included into the generated SDK using `bitbake meta-toolchain` or
75`bitbake -cpopulate_sdk <image>` in circumstanced where clang is not expected to be part of SDK, then reset `CLANGSDK` 96`bitbake -cpopulate_sdk <image>` if clang is expected to be part of SDK, add `CLANGSDK = "1"`
76variable in `local.conf` 97in `local.conf`
77 98
78```shell 99```shell
79CLANGSDK = "" 100CLANGSDK = "1"
80``` 101```
81 102
82# Building 103# Building
@@ -95,7 +116,7 @@ $ runqemu nographic
95# Limitations 116# Limitations
96 117
97Few components do not build with clang, if you have a component to add to that list 118Few components do not build with clang, if you have a component to add to that list
98simply add it to conf/nonclangable.inc e.g. 119simply add it to `conf/nonclangable.inc` e.g.
99 120
100```shell 121```shell
101TOOLCHAIN_pn-<recipe> = "gcc" 122TOOLCHAIN_pn-<recipe> = "gcc"
@@ -103,12 +124,46 @@ TOOLCHAIN_pn-<recipe> = "gcc"
103 124
104and OE will start using gcc to cross compile that recipe. 125and OE will start using gcc to cross compile that recipe.
105 126
106And if a component does not build with libc++, you can add it to `conf/nonclangable.inc` e.g. 127if a component does not build with libc++, you can add it to `conf/nonclangable.inc` e.g.
107 128
108```shell 129```shell
109CXX_remove_pn-<recipe>_toolchain-clang = " -stdlib=libc++ " 130CXX_remove_pn-<recipe>_toolchain-clang = " -stdlib=libc++ "
110``` 131```
111 132
133# compiler-rt failing in do_configure with custom TARGET_VENDOR
134
135If your DISTRO sets own value of TARGET_VENDOR, then it's need to be added in
136CLANG_EXTRA_OE_VENDORS, it should be done automatically, but if compiler-rt fails
137like bellow, then check the end of work-shared/llvm-project-source-12.0.0-r0/temp/log.do_patch
138is should have line like:
139NOTE: Adding support following TARGET_VENDOR values: foo in
140 /OE/build/oe-core/tmp-glibc/work-shared/llvm-project-source-12.0.0-r0/git/llvm/lib/Support/Triple.cpp and
141 /OE/build/oe-core/tmp-glibc/work-shared/llvm-project-source-12.0.0-r0/git/clang/lib/Driver/ToolChains/Gnu.cpp
142and check these files if //CLANG_EXTRA_OE_VENDORS* strings were replaced correctly.
143Read add_more_target_vendors function in recipes-devtools/clang/llvm-project-source.inc for more details.
144
145http://errors.yoctoproject.org/Errors/Details/574365/
146```shell
147-- 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
148-- Detecting C compiler ABI info
149-- Detecting C compiler ABI info - failed
150-- 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
151-- 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
152CMake 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):
153 The C compiler
154
155 "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"
156
157 is not able to compile a simple test program.
158
159 It fails with the following output:
160
161 Change Dir: TOPDIR/tmp-glibc/work/core2-64-foo-linux/compiler-rt/12.0.0-r0/build/CMakeFiles/CMakeTmp
162
163 Run Build Command(s):ninja cmTC_928f4 && [1/2] Building C object CMakeFiles/cmTC_928f4.dir/testCCompiler.c.o
164 [2/2] Linking C executable cmTC_928f4
165```
166
112# Dependencies 167# Dependencies
113 168
114```shell 169```shell