Skip to contentSkip to conversation

thin-provisioning-tools: fix bindgen build error with clang on octeontx2

PATCH In review Bo Sun 2 participants 4 messages Jul 24, 2025 – Jul 25, 2025

lore
Share & tools
lore

Bo Sun

author
#0 lore raw

PATCH 1/1 thin-provisioning-tools: fix bindgen build error with clang on octeontx2

Remove unsupported '-mcpu=octeontx2+crypto' from BINDGEN_EXTRA_CLANG_ARGS as clang does not recognize 'octeontx2' as a valid target CPU, causing bindgen to fail when generating Rust bindings.

Since bindgen only parses headers using Clang, CPU-specific options like -mcpu are generally unnecessary.

Fixes build failure:

|   error: unsupported argument 'octeontx2+crypto' to option '-mcpu='
|   error: unknown target CPU 'octeontx2'
---
 .../thin-provisioning-tools/thin-provisioning-tools_1.1.0.bb | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
meta-oe/dynamic-layers/clang-layer/recipes-support/thin-provisioning-tools/thin-provisioning-tools_1.1.0.bb +4 -1
index a60ca11244..4ed885f8b3 100644
@@ -23,7 +23,10 @@ inherit pkgconfig
 DEPENDS += "udev libdevmapper libdevmapper-native clang-native"
 
 export LIBCLANG_PATH = "${STAGING_LIBDIR_NATIVE}"
-export BINDGEN_EXTRA_CLANG_ARGS = "${HOST_CC_ARCH}${TOOLCHAIN_OPTIONS} --target=${TARGET_SYS}"
+# Remove octeontx2 specific CPU flags that may cause issues with bindgen
+BINDGEN_EXTRA_CLANG_ARGS = "${HOST_CC_ARCH}${TOOLCHAIN_OPTIONS} --target=${TARGET_SYS}"
+BINDGEN_EXTRA_CLANG_ARGS:remove = "-mcpu=octeontx2+crypto"
+export BINDGEN_EXTRA_CLANG_ARGS
 
 require ${BPN}-crates.inc
 require ${BPN}-git-crates.inc
Signature · 1 line
2.50.1
#1 lore raw

while this fixes it for one recipe, we have to fix it as tune level in oe-core so remove it globally if we are using clang compiler. so perhaps adding it to clang.bbclass might be a good idea

Quoted 45 lines · Bo Sun via lists.openembedded.org

Remove unsupported '-mcpu=octeontx2+crypto' from BINDGEN_EXTRA_CLANG_ARGS as clang does not recognize 'octeontx2' as a valid target CPU, causing bindgen to fail when generating Rust bindings.

Since bindgen only parses headers using Clang, CPU-specific options like -mcpu are generally unnecessary.

Fixes build failure:

|   error: unsupported argument 'octeontx2+crypto' to option '-mcpu='
|   error: unknown target CPU 'octeontx2'
---
 .../thin-provisioning-tools/thin-provisioning-tools_1.1.0.bb | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
meta-oe/dynamic-layers/clang-layer/recipes-support/thin-provisioning-tools/thin-provisioning-tools_1.1.0.bb +4 -2
index a60ca11244..4ed885f8b3 100644
@@ -23,7 +23,10 @@ inherit pkgconfig
 DEPENDS += "udev libdevmapper libdevmapper-native clang-native"
 
 export LIBCLANG_PATH = "${STAGING_LIBDIR_NATIVE}"
-export BINDGEN_EXTRA_CLANG_ARGS = "${HOST_CC_ARCH}${TOOLCHAIN_OPTIONS} --target=${TARGET_SYS}"
+# Remove octeontx2 specific CPU flags that may cause issues with bindgen
+BINDGEN_EXTRA_CLANG_ARGS = "${HOST_CC_ARCH}${TOOLCHAIN_OPTIONS} --target=${TARGET_SYS}"
+BINDGEN_EXTRA_CLANG_ARGS:remove = "-mcpu=octeontx2+crypto"
+export BINDGEN_EXTRA_CLANG_ARGS
 
 require ${BPN}-crates.inc
 require ${BPN}-git-crates.inc
--

2.50.1

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#118723): https://lists.openembedded.org/g/openembedded-devel/message/118723
Mute This Topic: https://lists.openembedded.org/mt/114317423/1997914
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-devel/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

author
#2 lore raw
Quoted 6 lines · Khem Raj

CAUTION: This email comes from a non Wind River email account!
Do not click links or open attachments unless you recognize the sender and know the content is safe.

while this fixes it for one recipe, we have to fix it as tune level in oe-core so remove it globally if we are using clang compiler. so perhaps adding it to clang.bbclass might be a good idea

Yes, this fix does resolve the issue for this specific recipe. However, I think fixing it at the recipe level is still a reasonable solution.

Looking at the bindgen code, BINDGEN_EXTRA_CLANG_ARGS is parsed and used directly by bindgen at runtime, not by BitBake:

https://github.com/rust-lang/rust-bindgen/blob/de9627ffa4860c6ed56cd40470fc7a96afc09d44/bindgen/lib.rs#L300

fn get_extra_clang_args(
parse_callbacks: &[Rc<dyn callbacks::ParseCallbacks>],

) -> Vec<String> {
    // Add any extra arguments from the environment to the clang 
command line.
    let Some(extra_clang_args) = get_target_dependent_env_var(
        parse_callbacks,
        "BINDGEN_EXTRA_CLANG_ARGS",
    ) else {
        return vec![];
    };

https://github.com/rust-lang/rust-bindgen/blob/de9627ffa4860c6ed56cd40470fc7a96afc09d44/bindgen/lib.rs#L337

        // Add any extra arguments from the environment to the clang 
command line.
        self.options.clang_args.extend(
            get_extra_clang_args(&self.options.parse_callbacks)
                .into_iter()
                .map(String::into_boxed_str),
        );

Additionally, base on the build.rs for devicemapper-sys, I believe we can safely remove ${HOST_CC_ARCH} from this recipe.

https://github.com/stratis-storage/devicemapper-rs/blob/master/devicemapper-rs-sys/build.rs

$ git diff
meta-oe/dynamic-layers/clang-layer/recipes-support/thin-provisioning-tools/thin-provisioning-tools_1.1.0.bb +1 -1
index a60ca11244..e8173c9b14 100644
@@ -23,7 +23,7 @@ inherit pkgconfig
 DEPENDS += "udev libdevmapper libdevmapper-native clang-native"
 
 export LIBCLANG_PATH = "${STAGING_LIBDIR_NATIVE}"
-export BINDGEN_EXTRA_CLANG_ARGS = "${HOST_CC_ARCH}${TOOLCHAIN_OPTIONS} --target=${TARGET_SYS}"
+export BINDGEN_EXTRA_CLANG_ARGS = "${TOOLCHAIN_OPTIONS} --target=${TARGET_SYS}"
 
 require ${BPN}-crates.inc
 require ${BPN}-git-crates.inc

I propose submitting this patch to master in v2, from where it will be backported. Let me know if you agree or have an alternative suggestion.

Thanks,
Bo

Quoted 48 lines
Quoted 45 lines · Bo Sun via lists.openembedded.org

Remove unsupported '-mcpu=octeontx2+crypto' from BINDGEN_EXTRA_CLANG_ARGS as clang does not recognize 'octeontx2' as a valid target CPU, causing bindgen to fail when generating Rust bindings.

Since bindgen only parses headers using Clang, CPU-specific options like -mcpu are generally unnecessary.

Fixes build failure:

|   error: unsupported argument 'octeontx2+crypto' to option '-mcpu='
|   error: unknown target CPU 'octeontx2'
---
  .../thin-provisioning-tools/thin-provisioning-tools_1.1.0.bb | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
meta-oe/dynamic-layers/clang-layer/recipes-support/thin-provisioning-tools/thin-provisioning-tools_1.1.0.bb +4 -2
index a60ca11244..4ed885f8b3 100644
@@ -23,7 +23,10 @@ inherit pkgconfig
  DEPENDS += "udev libdevmapper libdevmapper-native clang-native"
 
  export LIBCLANG_PATH = "${STAGING_LIBDIR_NATIVE}"
-export BINDGEN_EXTRA_CLANG_ARGS = "${HOST_CC_ARCH}${TOOLCHAIN_OPTIONS} --target=${TARGET_SYS}"
+# Remove octeontx2 specific CPU flags that may cause issues with bindgen
+BINDGEN_EXTRA_CLANG_ARGS = "${HOST_CC_ARCH}${TOOLCHAIN_OPTIONS} --target=${TARGET_SYS}"
+BINDGEN_EXTRA_CLANG_ARGS:remove = "-mcpu=octeontx2+crypto"
+export BINDGEN_EXTRA_CLANG_ARGS
 
  require ${BPN}-crates.inc
  require ${BPN}-git-crates.inc
--

2.50.1

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#118723): https://lists.openembedded.org/g/openembedded-devel/message/118723
Mute This Topic: https://lists.openembedded.org/mt/114317423/1997914
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-devel/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

#3 lore raw

sounds good.

Quoted 121 lines · Bo Sun
Quoted 6 lines · Khem Raj

CAUTION: This email comes from a non Wind River email account!
Do not click links or open attachments unless you recognize the sender and know the content is safe.

while this fixes it for one recipe, we have to fix it as tune level in oe-core so remove it globally if we are using clang compiler. so perhaps adding it to clang.bbclass might be a good idea

Yes, this fix does resolve the issue for this specific recipe. However, I think fixing it at the recipe level is still a reasonable solution.

Looking at the bindgen code, BINDGEN_EXTRA_CLANG_ARGS is parsed and used directly by bindgen at runtime, not by BitBake:

https://github.com/rust-lang/rust-bindgen/blob/de9627ffa4860c6ed56cd40470fc7a96afc09d44/bindgen/lib.rs#L300

fn get_extra_clang_args(
parse_callbacks: &[Rc<dyn callbacks::ParseCallbacks>],

) -> Vec<String> {
     // Add any extra arguments from the environment to the clang
command line.
     let Some(extra_clang_args) = get_target_dependent_env_var(
         parse_callbacks,
         "BINDGEN_EXTRA_CLANG_ARGS",
     ) else {
         return vec![];
     };

https://github.com/rust-lang/rust-bindgen/blob/de9627ffa4860c6ed56cd40470fc7a96afc09d44/bindgen/lib.rs#L337

         // Add any extra arguments from the environment to the clang
command line.
         self.options.clang_args.extend(
             get_extra_clang_args(&self.options.parse_callbacks)
                 .into_iter()
                 .map(String::into_boxed_str),
         );

Additionally, base on the build.rs for devicemapper-sys, I believe we can safely remove ${HOST_CC_ARCH} from this recipe.

https://github.com/stratis-storage/devicemapper-rs/blob/master/devicemapper-rs-sys/build.rs

$ git diff
diff --git
a/meta-oe/dynamic-layers/clang-layer/recipes-support/thin-provisioning-tools/thin-provisioning-tools_1.1.0.bb
b/meta-oe/dynamic-layers/clang-layer/recipes-support/thin-provisioning-tools/thin-provisioning-tools_1.1.0.bb
index a60ca11244..e8173c9b14 100644
---
a/meta-oe/dynamic-layers/clang-layer/recipes-support/thin-provisioning-tools/thin-provisioning-tools_1.1.0.bb
+++
b/meta-oe/dynamic-layers/clang-layer/recipes-support/thin-provisioning-tools/thin-provisioning-tools_1.1.0.bb
meta-oe/dynamic-layers/clang-layer/recipes-support/thin-provisioning-tools/thin-provisioning-tools_1.1.0.bb +1 -3
@@ -23,7 +23,7 @@ inherit pkgconfig
  DEPENDS += "udev libdevmapper libdevmapper-native clang-native"
 
  export LIBCLANG_PATH = "${STAGING_LIBDIR_NATIVE}"
-export BINDGEN_EXTRA_CLANG_ARGS = "${HOST_CC_ARCH}${TOOLCHAIN_OPTIONS}
--target=${TARGET_SYS}"
+export BINDGEN_EXTRA_CLANG_ARGS = "${TOOLCHAIN_OPTIONS}
--target=${TARGET_SYS}"
 
  require ${BPN}-crates.inc
  require ${BPN}-git-crates.inc

I propose submitting this patch to master in v2, from where it will be backported. Let me know if you agree or have an alternative suggestion.

Thanks,
Bo

Quoted 48 lines
Quoted 45 lines · Bo Sun via lists.openembedded.org

Remove unsupported '-mcpu=octeontx2+crypto' from BINDGEN_EXTRA_CLANG_ARGS as clang does not recognize 'octeontx2' as a valid target CPU, causing bindgen to fail when generating Rust bindings.

Since bindgen only parses headers using Clang, CPU-specific options like -mcpu are generally unnecessary.

Fixes build failure:

|   error: unsupported argument 'octeontx2+crypto' to option '-mcpu='
|   error: unknown target CPU 'octeontx2'
---
  .../thin-provisioning-tools/thin-provisioning-tools_1.1.0.bb | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
meta-oe/dynamic-layers/clang-layer/recipes-support/thin-provisioning-tools/thin-provisioning-tools_1.1.0.bb +4 -2
index a60ca11244..4ed885f8b3 100644
@@ -23,7 +23,10 @@ inherit pkgconfig
  DEPENDS += "udev libdevmapper libdevmapper-native clang-native"
 
  export LIBCLANG_PATH = "${STAGING_LIBDIR_NATIVE}"
-export BINDGEN_EXTRA_CLANG_ARGS = "${HOST_CC_ARCH}${TOOLCHAIN_OPTIONS} --target=${TARGET_SYS}"
+# Remove octeontx2 specific CPU flags that may cause issues with bindgen
+BINDGEN_EXTRA_CLANG_ARGS = "${HOST_CC_ARCH}${TOOLCHAIN_OPTIONS} --target=${TARGET_SYS}"
+BINDGEN_EXTRA_CLANG_ARGS:remove = "-mcpu=octeontx2+crypto"
+export BINDGEN_EXTRA_CLANG_ARGS
 
  require ${BPN}-crates.inc
  require ${BPN}-git-crates.inc
--

2.50.1

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#118723): https://lists.openembedded.org/g/openembedded-devel/message/118723
Mute This Topic: https://lists.openembedded.org/mt/114317423/1997914
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-devel/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-