Skip to contentSkip to conversation

meson: correct bindgen_clang_argments

PATCH In review Khem Raj 2 participants 4 messages May 6, 2025 Arm/Amlogic Meson SoC support

lore
Share & tools
lore

Khem Raj

author
#0 lore raw

PATCH 1/2 meson: correct bindgen_clang_argments

From: Dmitry Baryshkov <[email protected]>

Follow the changes in Clang search paths and specify sysroot via the TOOLCHAIN_OPTIONS, otherwise clang will fail to find system headers when executed by bindgen.

For SDK packages TOOLCHAIN_OPTIONS don't contain full sysroot path, so specify the correct directory explicitly.

---
 meta/classes-recipe/meson.bbclass | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
meta/classes-recipe/meson.bbclass +9 -1
index ef45a034a76..c8b3e1ec29a 100644
@@ -62,6 +62,14 @@ def rust_tool(d, target_var):
     cmd = [rustc, "--target", d.getVar(target_var)] + d.getVar("RUSTFLAGS").split()
     return "rust = %s" % repr(cmd)
 
+def bindgen_args(d):
+    args = '${HOST_CC_ARCH}${TOOLCHAIN_OPTIONS} --target=${TARGET_SYS}'
+    # For SDK packages TOOLCHAIN_OPTIONS don't contain full sysroot path
+    if bb.data.inherits_class("nativesdk", d):
+        args += ' --sysroot=${STAGING_DIR_HOST}${SDKPATHNATIVE}${prefix_nativesdk}'
+    items = d.expand(args).split()
+    return repr(items[0] if len(items) == 1 else items)
+
 addtask write_config before do_configure
 do_write_config[vardeps] += "CC CXX AR NM STRIP READELF OBJCOPY CFLAGS CXXFLAGS LDFLAGS RUSTC RUSTFLAGS EXEWRAPPER_ENABLED"
 do_write_config() {
@@ -93,7 +101,7 @@ cpp_link_args = ${@meson_array('LDFLAGS', d)}
 [properties]
 needs_exe_wrapper = true
 sys_root = '${STAGING_DIR_HOST}'
-bindgen_clang_arguments = ['-target', '${@d.getVar('RUST_HOST_SYS')}', '-I${STAGING_INCDIR}']
+bindgen_clang_arguments = ${@bindgen_args(d)}
 
 [host_machine]
 system = '${@meson_operating_system('HOST_OS', d)}'
author
#1 lore raw

PATCH 2/2 mesa: Do not use envvar BINDGEN_EXTRA_CLANG_ARGS

Its now set in meson bbclass for native, nativesdk and target recipes correctly.

---
 meta/recipes-graphics/mesa/mesa.inc | 4 ----
 1 file changed, 4 deletions(-)
meta/recipes-graphics/mesa/mesa.inc +0 -4
index 66fb896676a..288027bbb99 100644
@@ -267,10 +267,6 @@ PACKAGES =+ "libegl-mesa libegl-mesa-dev \
              mesa-vdpau-drivers mesa-tools \
             "
 
-do_compile:prepend:class-target() {
-    export BINDGEN_EXTRA_CLANG_ARGS="${HOST_CC_ARCH}${TOOLCHAIN_OPTIONS} --target=${TARGET_SYS}"
-}
-
 do_install:append () {
     # libwayland-egl has been moved to wayland 1.15+
     rm -f ${D}${libdir}/libwayland-egl*
Acked-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] mesa: Do not use envvar BINDGEN_EXTRA_CLANG_ARGS

Quoted 8 lines · Khem Raj

Its now set in meson bbclass for native, nativesdk and target recipes correctly.

---
 meta/recipes-graphics/mesa/mesa.inc | 4 ----
 1 file changed, 4 deletions(-)

But I wonder, what made you change your mind?

Signature · 2 lines
With best wishes
Dmitry
author
#3 lore raw

Re: [PATCH 2/2] mesa: Do not use envvar BINDGEN_EXTRA_CLANG_ARGS

Quoted 11 lines · Dmitry Baryshkov
Quoted 8 lines · Khem Raj

Its now set in meson bbclass for native, nativesdk and target recipes correctly.

---
 meta/recipes-graphics/mesa/mesa.inc | 4 ----
 1 file changed, 4 deletions(-)
Quoted 3 lines

But I wonder, what made you change your mind?

I read through meson documentation and they do have bindgen support variables added so
informed myself :)

Quoted 4 lines

--
With best wishes
Dmitry