diff options
Diffstat (limited to 'README.md')
-rw-r--r-- | README.md | 113 |
1 files changed, 84 insertions, 29 deletions
@@ -1,9 +1,10 @@ | |||
1 | [](https://drone.yoedistro.org/kraj/meta-clang) | 1 | [](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 | ||
5 | This layer provides [clang/llvm](http://clang.llvm.org/) as alternative to your system | 5 | This layer provides [clang/llvm](http://clang.llvm.org/) as alternative to system |
6 | C/C++ compiler for OpenEmbedded based distributions along with gcc | 6 | C/C++ compiler for OpenEmbedded/Yocto Project based distributions. This can cohabit |
7 | with 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 | ``` |
19 | If using poky ( Yocto project reference Distribution ) | ||
20 | |||
21 | ```shell | ||
22 | git clone https://git.yoctoproject.org/git/poky | ||
23 | cd poky | ||
24 | git clone git://github.com/kraj/meta-clang.git | ||
25 | |||
26 | $ . ./oe-init-build-env | ||
27 | ``` | ||
18 | 28 | ||
19 | Add meta-clang overlay | 29 | Add meta-clang overlay |
20 | ``` | 30 | ``` |
@@ -23,7 +33,7 @@ bitbake-layers add-layer ../meta-clang | |||
23 | 33 | ||
24 | Check `conf/bblayers.conf` to see that meta-clang is added to layer mix e.g. | 34 | Check `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 | ||
28 | Note that by default gcc will remain the system compiler, however if you wish | 38 | Note that by default gcc will remain the system compiler, however if you wish |
29 | clang to be the default compiler then set | 39 | clang 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 |
39 | TOOLCHAIN = "clang" | 49 | TOOLCHAIN = "clang" |
40 | ``` | 50 | ``` |
51 | also look at `conf/nonclangable.conf` for list of recipes which do not yet fully | ||
52 | build with clang | ||
41 | 53 | ||
42 | # Default C++ Standard Library Switch | 54 | # Default Compiler Runtime |
43 | 55 | ||
44 | Note that by default clang libc++ is default C++ standard library, however if you wish | 56 | Default is to use GNU runtime `RUNTIME = "gnu"` which consists of libgcc, libstdc++ to provide C/C++ |
45 | to keep GNU libstdc++ to be the default then set | 57 | runtime support. However its possible to use LLVM runtime to replace it where |
58 | compile-rt, llvm libunwind, and libc++ are used to provide C/C++ runtime, while | ||
59 | GNU runtime works with both GCC and Clang, LLVM runtime is only tested with Clang | ||
60 | compiler, Switching to use LLVM runtime is done via a config metadata knob | ||
46 | 61 | ||
47 | ```shell | 62 | ```shell |
48 | LIBCPLUSPLUS = "" | 63 | RUNTIME = "llvm" |
49 | ``` | 64 | ``` |
50 | 65 | ||
51 | in `local.conf`. | 66 | RUNTIME variable influences individual runtime elements and can be set explcitly as well |
52 | You can select libstdc++ per package too by writing bbappends for them containing | 67 | e.g. `LIBCPLUSPLUS` `COMPILER_RT` and `UNWINDLIB` |
53 | 68 | ||
54 | ```shell | 69 | Please note that this will still use crt files from GNU compiler always, while llvm now |
55 | LIBCPLUSPLUS_toolchain-clang_pn-<recipe> = "" | 70 | do 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 | ||
60 | By default, clang build from meta-clang uses clang runtime ( compiler-rt + libc++ + libunwind ) out of box | 74 | Using RUNTIME bariable will select which C++ runtime is used, however it can be overridden |
61 | However, it is possible to switch to using gcc runtime as default, In order to do that | 75 | if needed to by modifying `LIBCPLUSPLUS` variable, usually defaults used by `RUNTIME` is |
62 | following settings are needed in site configurations e.g. in `local.conf` | 76 | best fit. e.g. below we select LLVM C++ as default C++ runtime. |
63 | 77 | ||
64 | ```shell | 78 | ```shell |
65 | TOOLCHAIN ?= "clang" | 79 | LIBCPLUSPLUS = "-stdlib=libc++" |
66 | LIBCPLUSPLUS = "" | 80 | ``` |
67 | COMPILER_RT = "" | ||
68 | UNWINDLIB = "" | ||
69 | 81 | ||
82 | in `local.conf`. | ||
83 | You can select libstdc++ per package too by writing bbappends for them containing | ||
84 | |||
85 | ```shell | ||
86 | LIBCPLUSPLUS_toolchain-clang_pn-<recipe> = "-stdlibc=libc++" | ||
70 | ``` | 87 | ``` |
88 | Defaults are chosen to be GNU for maximum compatibility with existing GNU systems. Its always | ||
89 | good to use single runtime on a system, mixing runtimes can cause complications during | ||
90 | compilation as well as runtime. However, its upto distribution policies to decide which runtime | ||
91 | to use. | ||
71 | 92 | ||
72 | # Removing clang from generated SDK toolchain | 93 | # Adding clang in generated SDK toolchain |
73 | 94 | ||
74 | clang based cross compiler is automatically included into the generated SDK using `bitbake meta-toolchain` or | 95 | clang 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"` |
76 | variable in `local.conf` | 97 | in `local.conf` |
77 | 98 | ||
78 | ```shell | 99 | ```shell |
79 | CLANGSDK = "" | 100 | CLANGSDK = "1" |
80 | ``` | 101 | ``` |
81 | 102 | ||
82 | # Building | 103 | # Building |
@@ -95,7 +116,7 @@ $ runqemu nographic | |||
95 | # Limitations | 116 | # Limitations |
96 | 117 | ||
97 | Few components do not build with clang, if you have a component to add to that list | 118 | Few components do not build with clang, if you have a component to add to that list |
98 | simply add it to conf/nonclangable.inc e.g. | 119 | simply add it to `conf/nonclangable.inc` e.g. |
99 | 120 | ||
100 | ```shell | 121 | ```shell |
101 | TOOLCHAIN_pn-<recipe> = "gcc" | 122 | TOOLCHAIN_pn-<recipe> = "gcc" |
@@ -103,12 +124,46 @@ TOOLCHAIN_pn-<recipe> = "gcc" | |||
103 | 124 | ||
104 | and OE will start using gcc to cross compile that recipe. | 125 | and OE will start using gcc to cross compile that recipe. |
105 | 126 | ||
106 | And if a component does not build with libc++, you can add it to `conf/nonclangable.inc` e.g. | 127 | if a component does not build with libc++, you can add it to `conf/nonclangable.inc` e.g. |
107 | 128 | ||
108 | ```shell | 129 | ```shell |
109 | CXX_remove_pn-<recipe>_toolchain-clang = " -stdlib=libc++ " | 130 | CXX_remove_pn-<recipe>_toolchain-clang = " -stdlib=libc++ " |
110 | ``` | 131 | ``` |
111 | 132 | ||
133 | # compiler-rt failing in do_configure with custom TARGET_VENDOR | ||
134 | |||
135 | If your DISTRO sets own value of TARGET_VENDOR, then it's need to be added in | ||
136 | CLANG_EXTRA_OE_VENDORS, it should be done automatically, but if compiler-rt fails | ||
137 | like bellow, then check the end of work-shared/llvm-project-source-12.0.0-r0/temp/log.do_patch | ||
138 | is should have line like: | ||
139 | NOTE: 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 | ||
142 | and check these files if //CLANG_EXTRA_OE_VENDORS* strings were replaced correctly. | ||
143 | Read add_more_target_vendors function in recipes-devtools/clang/llvm-project-source.inc for more details. | ||
144 | |||
145 | http://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 | ||
152 | 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): | ||
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 |