diff mbox series

insane: Check if the C++ toolchain supports --std=gnu++20

Message ID 20250319182029.675932-1-yoann.congal@smile.fr
State New
Headers show
Series insane: Check if the C++ toolchain supports --std=gnu++20 | expand

Commit Message

Yoann Congal March 19, 2025, 6:20 p.m. UTC
From: Yoann Congal <yoann.congal@smile.fr>

This is needed to build nodejs from meta-oe. Check this early to avoid
an error later in the build.

Fixes [YOCTO #15804]

Signed-off-by: Yoann Congal <yoann.congal@smile.fr>
---
WARNING: as discussed in previous threads [0][1], this will disqualify
builds on Ubuntu 20.04 (its g++ does not support the option)
[0]: https://lists.openembedded.org/g/openembedded-devel/topic/111740469
[1]: https://lists.yoctoproject.org/g/yocto-patches/topic/yocto_autobuilder2_patch/111757761
---
 meta/classes-global/sanity.bbclass | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

Comments

Richard Purdie March 19, 2025, 7:19 p.m. UTC | #1
On Wed, 2025-03-19 at 19:20 +0100, Yoann Congal via lists.openembedded.org wrote:
> From: Yoann Congal <yoann.congal@smile.fr>
> 
> This is needed to build nodejs from meta-oe. Check this early to avoid
> an error later in the build.
> 
> Fixes [YOCTO #15804]
> 
> Signed-off-by: Yoann Congal <yoann.congal@smile.fr>
> ---
> WARNING: as discussed in previous threads [0][1], this will disqualify
> builds on Ubuntu 20.04 (its g++ does not support the option)
> [0]: https://lists.openembedded.org/g/openembedded-devel/topic/111740469
> [1]: https://lists.yoctoproject.org/g/yocto-patches/topic/yocto_autobuilder2_patch/111757761
> ---
>  meta/classes-global/sanity.bbclass | 25 +++++++++++++++++++++++++
>  1 file changed, 25 insertions(+)
> 
> diff --git a/meta/classes-global/sanity.bbclass b/meta/classes-global/sanity.bbclass
> index 1bae998f74..5783b92b26 100644
> --- a/meta/classes-global/sanity.bbclass
> +++ b/meta/classes-global/sanity.bbclass
> @@ -629,6 +629,28 @@ def check_cpp_toolchain(d):
>      except subprocess.CalledProcessError as e:
>          return f"An unexpected issue occurred during the C++ toolchain check: {str(e)}"
>  
> +def check_cpp_stdgnupp20_toolchain(d):
> +    """
> +    Checks if the C++ toolchain support the '--std=gnu++20' option
> +    """
> +    import shlex
> +    import subprocess
> +
> +    cpp_code = """
> +    #include <iostream>
> +    int main() {
> +        std::cout << "Hello, World!" << std::endl;
> +        return 0;
> +    }
> +    """
> +
> +    cmd = shlex.split(d.getVar("BUILD_CXX")) + ["-x", "c++","-", "-o", "/dev/null", "--std=gnu++20"]
> +    try:
> +        subprocess.run(cmd, input=cpp_code, capture_output=True, text=True, check=True)
> +        return None
> +    except subprocess.CalledProcessError as e:
> +        return f"An unexpected issue occurred during the C++ 'std=gnu++20' toolchain check: {str(e)}"
> +
>  

I did test this:

https://autobuilder.yoctoproject.org/valkyrie/#/builders/68/builds/1281

I'm wondering if we should add:

". Please use a g++ compiler that supports C++20 (e.g. g++ version 10 onwards)."

In the meantime, since we're going to do this, I will take the
opportunity to bump the python version minimum to 3.9 and install
buildtools on the 20.04 ubuntu workers from now on.

Cheers,

Richard
diff mbox series

Patch

diff --git a/meta/classes-global/sanity.bbclass b/meta/classes-global/sanity.bbclass
index 1bae998f74..5783b92b26 100644
--- a/meta/classes-global/sanity.bbclass
+++ b/meta/classes-global/sanity.bbclass
@@ -629,6 +629,28 @@  def check_cpp_toolchain(d):
     except subprocess.CalledProcessError as e:
         return f"An unexpected issue occurred during the C++ toolchain check: {str(e)}"
 
+def check_cpp_stdgnupp20_toolchain(d):
+    """
+    Checks if the C++ toolchain support the '--std=gnu++20' option
+    """
+    import shlex
+    import subprocess
+
+    cpp_code = """
+    #include <iostream>
+    int main() {
+        std::cout << "Hello, World!" << std::endl;
+        return 0;
+    }
+    """
+
+    cmd = shlex.split(d.getVar("BUILD_CXX")) + ["-x", "c++","-", "-o", "/dev/null", "--std=gnu++20"]
+    try:
+        subprocess.run(cmd, input=cpp_code, capture_output=True, text=True, check=True)
+        return None
+    except subprocess.CalledProcessError as e:
+        return f"An unexpected issue occurred during the C++ 'std=gnu++20' toolchain check: {str(e)}"
+
 def sanity_handle_abichanges(status, d):
     #
     # Check the 'ABI' of TMPDIR
@@ -804,6 +826,9 @@  def check_sanity_version_change(status, d):
     # Check if linking with lstdc++ is failing
     status.addresult(check_cpp_toolchain(d))
 
+    # Check if the C++ toolchain supports --std=gnu++20
+    status.addresult(check_cpp_stdgnupp20_toolchain(d))
+
 def sanity_check_locale(d):
     """
     Currently bitbake switches locale to en_US.UTF-8 so check that this locale actually exists.