Skip to contentSkip to conversation

toolchain/clang: prepend target host-sys to HOST_CC_ARCH

PATCH In review Peter Marko 2 participants 4 messages Aug 20 – Sep 28

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 toolchain/clang: prepend target host-sys to HOST_CC_ARCH

From: Peter Marko <[email protected]>

This assignment was present in scarthgap meta-clang.
* commit adding it: [1]
* commit removing it from native case: [2]
* it was removed completely when migrating clang to oe-core

After migration from scarthgap to wrynose (or current master), clang extra tools like clang-tidy do not work anymore.

This restores the state before migration from meta-clang to oe-core.

Test recipe used for fix validation:

test-recipe.bb:
SUMMARY = "clang-tidy demonstration program"
SECTION = "examples"
HOMEPAGE = "n/a"
LICENSE = "GPL-2.0-only"
LIC_FILES_CHKSUM = "file://${COREBASE}/meta/files/common-licenses/GPL-2.0-only;md5=801f80980d171dd6425610833a22dbe6" SRC_URI = "file://CMakeLists.txt file://hello-world.cpp"
S = "${UNPACKDIR}"
TOOLCHAIN = "clang"
inherit cmake

CMakeLists.txt
project(hello-world) cmake_minimum_required(VERSION 3.5) find_program(CLANG_TIDY NAMES clang-tidy) set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY}" "--checks=*") add_executable(${PROJECT_NAME} hello-world.cpp)

hello-world.cpp
#include <iostream>

  int main() {
    std::cout << "Hello World!";
    return 0;

}

[1] https://github.com/kraj/meta-clang/commit/503aa977b27be0506fb6ac21fbf9e8b049b82247
[2] https://github.com/kraj/meta-clang/commit/6da0abaa33b458a37b97f42e3755245e3220bf27

---
v2:
* removed native variant, which will make it equivalent to pre-move mota-clang
* remove unuseful AI explanation from commit message

 meta/classes/toolchain/clang.bbclass | 4 ++++
 1 file changed, 4 insertions(+)
meta/classes/toolchain/clang.bbclass +4 -0
index 9a3cd0e584..f6b554d210 100644
@@ -34,6 +34,10 @@ LDFLAGS:append:class-nativesdk:x86-64 = " -Wl,-dynamic-linker,${base_libdir}/ld-
 LDFLAGS:append:class-nativesdk:aarch64 = " -Wl,-dynamic-linker,${base_libdir}/ld-linux-aarch64.so.1"
 LDFLAGS:append:class-cross-canadian = " -Wl,-dynamic-linker,${base_libdir}/placeholder/to/be/rewritten/by/sdk/installer"
 
+# helps extra tools like clang-tidy to find arch-specific macros and headers in a cross compile environment
+HOST_CC_ARCH:prepend:class-target = "-target ${HOST_SYS} "
+HOST_CC_ARCH:prepend:class-nativesdk = "-target ${HOST_SYS} "
+
 # do_populate_sysroot needs STRIP, do_package_qa needs OBJDUMP
 POPULATESYSROOTDEPS:append:class-target = " llvm-native:do_populate_sysroot"
 
#1 lore raw

This patch is sitting in master-next for some time already and is probably spending a minute or two of everyone's time on each patch review call. Let's try to do a decision whether to merge it or drop it.
I (without asking or rewording via AI) think this:

I see following ways how to approach this clang-tidy problem:
- make clang-tidy architecture aware upstream
- add these flags to tell it the architecture (what this patch proposes and what was present in scarthgap)
- add it only to recipes which use clang-tidy (or other similar clang tools)

clang-tidy (and this also applies to some other clang support tools) is in principle architecture independent.
Linter should not care about build arch, correct?, it just needs to know the paths to sources.
So imho making it architecture dependent would go in a wrong direction, probably wasting time of whoever develops this and upstream clang maintainers.

Explicit set of architecture globally looks like a better choice.
Yocto currently does not set the triplet in build flags, because it's hardcoded in toolchain and thus "it works" (however as we see here, only in 99.9% of cases) For clang compiler it's a no-op (the value is the same as value that it has hardcoded during its compilation).
And it helps all "arch-independent" clang tools to find the right headers.

Having a special handling for clang-tidy in all recipes using it is certainly possible, but seems to be sub-par. Yocto should support clang-tidy workflows natively.

Best Regards,
Peter

Quoted 84 lines

-----Original Message-----
From: Marko, Peter (FT D EU SK BFS1) <[email protected]>
Sent: Thursday, August 20, 2026 10:11 PM
To: [email protected]
Cc: Khem Raj <[email protected]>; Marko, Peter (FT D EU SK BFS1) <[email protected]>
Subject: [PATCH v2] toolchain/clang: prepend target host-sys to HOST_CC_ARCH

From: Peter Marko <[email protected]>

This assignment was present in scarthgap meta-clang.
* commit adding it: [1]
* commit removing it from native case: [2]
* it was removed completely when migrating clang to oe-core

After migration from scarthgap to wrynose (or current master), clang extra tools like clang-tidy do not work anymore.

This restores the state before migration from meta-clang to oe-core.

Test recipe used for fix validation:

test-recipe.bb:
SUMMARY = "clang-tidy demonstration program"
SECTION = "examples"
HOMEPAGE = "n/a"
LICENSE = "GPL-2.0-only"
LIC_FILES_CHKSUM = "file://${COREBASE}/meta/files/common-licenses/GPL-
2.0-only;md5=801f80980d171dd6425610833a22dbe6"
SRC_URI = "file://CMakeLists.txt file://hello-world.cpp"
S = "${UNPACKDIR}"
TOOLCHAIN = "clang"
inherit cmake

CMakeLists.txt
project(hello-world) cmake_minimum_required(VERSION 3.5) find_program(CLANG_TIDY NAMES clang-tidy) set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY}" "--checks=*") add_executable(${PROJECT_NAME} hello-world.cpp)

hello-world.cpp
#include <iostream>

  int main() {
    std::cout << "Hello World!";
    return 0;

}

[1] https://github.com/kraj/meta-
clang/commit/503aa977b27be0506fb6ac21fbf9e8b049b82247
[2] https://github.com/kraj/meta-
clang/commit/6da0abaa33b458a37b97f42e3755245e3220bf27

---
v2:
* removed native variant, which will make it equivalent to pre-move mota-clang
* remove unuseful AI explanation from commit message

 meta/classes/toolchain/clang.bbclass | 4 ++++
 1 file changed, 4 insertions(+)
meta/classes/toolchain/clang.bbclass +0 -0
index 9a3cd0e584..f6b554d210 100644
@@ -34,6 +34,10 @@ LDFLAGS:append:class-nativesdk:x86-64 = " -Wl,-

dynamic-linker,${base_libdir}/ld-
LDFLAGS:append:class-nativesdk:aarch64 = " -Wl,-dynamic-
linker,${base_libdir}/ld-linux-aarch64.so.1"
LDFLAGS:append:class-cross-canadian = " -Wl,-dynamic-
linker,${base_libdir}/placeholder/to/be/rewritten/by/sdk/installer"

+# helps extra tools like clang-tidy to find arch-specific macros and headers in a cross compile environment

meta/classes/toolchain/clang.bbclass +3 -0
+HOST_CC_ARCH:prepend:class-target = "-target ${HOST_SYS} "
+HOST_CC_ARCH:prepend:class-nativesdk = "-target ${HOST_SYS} "
+
 # do_populate_sysroot needs STRIP, do_package_qa needs OBJDUMP
 POPULATESYSROOTDEPS:append:class-target = " llvm-

native:do_populate_sysroot"

#2 lore raw
Quoted 3 lines · Peter

This patch is sitting in master-next for some time already and is probably spending a minute or two of everyone's time on each patch review call.

That is true.

Quoted 27 lines

Let's try to do a decision whether to merge it or drop it. I (without asking or rewording via AI) think this:

I see following ways how to approach this clang-tidy problem:
- make clang-tidy architecture aware upstream
- add these flags to tell it the architecture (what this patch proposes and what was present in scarthgap)
- add it only to recipes which use clang-tidy (or other similar clang tools)

clang-tidy (and this also applies to some other clang support tools) is in principle architecture independent.
Linter should not care about build arch, correct?, it just needs to know the paths to sources.
So imho making it architecture dependent would go in a wrong direction, probably wasting time of whoever develops this and upstream clang maintainers.

Explicit set of architecture globally looks like a better choice. Yocto currently does not set the triplet in build flags, because it's hardcoded in toolchain and thus "it works" (however as we see here, only in 99.9% of cases)
For clang compiler it's a no-op (the value is the same as value that it has hardcoded during its compilation).
And it helps all "arch-independent" clang tools to find the right headers.

Quoted 3 lines

Having a special handling for clang-tidy in all recipes using it is certainly possible, but seems to be sub-par.
Yocto should support clang-tidy workflows natively.

I think several of us all have mixed feelings on it. On the one hand it fixes a problem. On the other, the rest of clang doesn't need this and these kinds of flags, once added, are very very hard to remove again.

I guess we lack enough data to make an informed choice and are worried about sending this in the wrong direction if we reject it, equally, we don't really want to make a change like this as it doesn't feel right. We are therefore struggling to reach a decision :/.

Even trying to articulate that in a way you can take some action on is hard, hence it is sitting there :/

Cheers,

Richard

#3 lore raw
Quoted 50 lines

-----Original Message-----
From: Richard Purdie <[email protected]>
Sent: Monday, September 28, 2026 3:04 PM
To: Marko, Peter (FT D EU SK BFS1) <[email protected]>; [email protected]
Cc: Khem Raj <[email protected]>; Ross Burton <[email protected]>; Freihofer, Adrian (SI B PRO TI EAC CCP) <[email protected]>
Subject: Re: [PATCH v2] toolchain/clang: prepend target host-sys to HOST_CC_ARCH

Quoted 3 lines · Peter

This patch is sitting in master-next for some time already and is probably spending a minute or two of everyone's time on each patch review call.

That is true.

Quoted 27 lines

Let's try to do a decision whether to merge it or drop it. I (without asking or rewording via AI) think this:

I see following ways how to approach this clang-tidy problem:
- make clang-tidy architecture aware upstream
- add these flags to tell it the architecture (what this patch proposes and what was present in scarthgap)
- add it only to recipes which use clang-tidy (or other similar clang tools)

clang-tidy (and this also applies to some other clang support tools) is in principle architecture independent.
Linter should not care about build arch, correct?, it just needs to know the paths to sources.
So imho making it architecture dependent would go in a wrong direction, probably wasting time of whoever develops this and upstream clang maintainers.

Explicit set of architecture globally looks like a better choice. Yocto currently does not set the triplet in build flags, because it's hardcoded in toolchain and thus "it works" (however as we see here, only in 99.9% of cases)
For clang compiler it's a no-op (the value is the same as value that it has hardcoded during its compilation).
And it helps all "arch-independent" clang tools to find the right headers.

Quoted 3 lines

Having a special handling for clang-tidy in all recipes using it is certainly possible, but seems to be sub-par.
Yocto should support clang-tidy workflows natively.

Quoted 8 lines

I think several of us all have mixed feelings on it. On the one hand it fixes a problem. On the other, the rest of clang doesn't need this and these kinds of flags, once added, are very very hard to remove again.

I guess we lack enough data to make an informed choice and are worried about sending this in the wrong direction if we reject it, equally, we don't really want to make a change like this as it doesn't feel right. We are therefore struggling to reach a decision :/.

I didn't want to cause too much effort with this patch.
So feel free to drop this one, it can wait for more demand than a single project. It's trivial to keep this in our product layer without fear of getting broken.

Peter

Quoted 7 lines

Even trying to articulate that in a way you can take some action on is hard, hence it is sitting there :/

Cheers,

Richard