public inbox for openembedded-core@lists.openembedded.org
 help / color / mirror / Atom feed
* [PATCH v3] sanity: test for c toolchain
       [not found] <20250118120105.11681-1-gavrosc.ref@yahoo.com>
@ 2025-01-18 12:01 ` Christos Gavros
  2025-01-20 13:42   ` [OE-core] " Richard Purdie
  0 siblings, 1 reply; 3+ messages in thread
From: Christos Gavros @ 2025-01-18 12:01 UTC (permalink / raw)
  To: openembedded-core; +Cc: Christos Gavros, Yoann Congal

Users reported issues caused by missing the right libstdc++-version-dev.
A new function 'check_c_toolchain' added in sanity.bbclass to test linking libstdc++
Fixes [YOCTO #15712]

Signed-off-by: Christos Gavros <gavrosc@yahoo.com>
Reviewed-by: Yoann Congal <yoann.congal@smile.fr>
---
v2->v3
* whitespaces are removed
* the format for reference to the bug is fixed
* 'Reviewed-by' tag is added
---
 meta/classes-global/sanity.bbclass | 40 ++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/meta/classes-global/sanity.bbclass b/meta/classes-global/sanity.bbclass
index 7b8a497d5a..13f7109eac 100644
--- a/meta/classes-global/sanity.bbclass
+++ b/meta/classes-global/sanity.bbclass
@@ -780,6 +780,43 @@ def sanity_check_locale(d):
     except locale.Error:
         raise_sanity_error("Your system needs to support the en_US.UTF-8 locale.", d)
 
+def check_c_toolchain(d):
+    """
+    it checks if the c compiling and linking to libstdc++ works properly in the native system
+    """
+    import os
+    import subprocess
+    from tempfile import NamedTemporaryFile
+
+    try:
+        with NamedTemporaryFile(delete=False, suffix=".c") as c_file:
+            c_code = """
+            #include <stdio.h>
+            int main() {
+                printf(\"Hello, World!\\n\");
+                return 0;
+            }
+            """
+            c_file.write(c_code.encode('utf-8'))
+            c_file_name = c_file.name
+
+        build_cc = d.getVar('BUILD_CC').strip()
+        output_binary = c_file_name + ".out"
+        compile_command = [build_cc, c_file_name, '-o', output_binary,'-lstdc++']
+        result = subprocess.run(compile_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+
+        if result.returncode == 0:
+            return None
+        else:
+            return f"C toolchain check failed to link against libstdc++. Please ensure libstdc++ and headers are installed. Error:\n{result.stderr.decode()}"
+    except Exception as e:
+        return f"An unexpected issue occurred during the C toolchain check: {str(e)}"
+    finally:
+        if c_file_name and os.path.exists(c_file_name):
+            os.remove(c_file_name)
+        if output_binary and os.path.exists(output_binary):
+            os.remove(output_binary)
+
 def check_sanity_everybuild(status, d):
     import os, stat
     # Sanity tests which test the users environment so need to run at each build (or are so cheap
@@ -976,6 +1013,9 @@ def check_sanity_everybuild(status, d):
         if '/dash' not in real_sh and '/bash' not in real_sh:
             status.addresult("Error, /bin/sh links to %s, must be dash or bash\n" % real_sh)
 
+    # Check if linking with lstdc++ is failing
+    status.addresult(check_c_toolchain(d))
+
 def check_sanity(sanity_data):
     class SanityStatus(object):
         def __init__(self):
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [OE-core] [PATCH v3] sanity: test for c toolchain
  2025-01-18 12:01 ` [PATCH v3] sanity: test for c toolchain Christos Gavros
@ 2025-01-20 13:42   ` Richard Purdie
  2025-01-20 20:35     ` Christos Gavros
  0 siblings, 1 reply; 3+ messages in thread
From: Richard Purdie @ 2025-01-20 13:42 UTC (permalink / raw)
  To: gavrosc, openembedded-core; +Cc: Yoann Congal

On Sat, 2025-01-18 at 13:01 +0100, Christos Gavros via lists.openembedded.org wrote:
> Users reported issues caused by missing the right libstdc++-version-dev.
> A new function 'check_c_toolchain' added in sanity.bbclass to test linking libstdc++
> Fixes [YOCTO #15712]
> 
> Signed-off-by: Christos Gavros <gavrosc@yahoo.com>
> Reviewed-by: Yoann Congal <yoann.congal@smile.fr>
> ---
> v2->v3
> * whitespaces are removed
> * the format for reference to the bug is fixed
> * 'Reviewed-by' tag is added
> ---
>  meta/classes-global/sanity.bbclass | 40 ++++++++++++++++++++++++++++++
>  1 file changed, 40 insertions(+)

This is looking really good thanks!

The one thing left which probably needs tweaking is testing this on
every build. I think that is a bit too much overhead and we should do
this in check_sanity_version_change().

The reason being that once builds are working on a given system we
probably don't need to check again. If people do run into issues, they
will probably test a clean builddir and at that point the error would
also show up.

If you could send a v4 with that small tweak, I think it looks good to
merge, thanks.

Cheers,

Richard



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v3] sanity: test for c toolchain
  2025-01-20 13:42   ` [OE-core] " Richard Purdie
@ 2025-01-20 20:35     ` Christos Gavros
  0 siblings, 0 replies; 3+ messages in thread
From: Christos Gavros @ 2025-01-20 20:35 UTC (permalink / raw)
  To: openembedded-core

[-- Attachment #1: Type: text/plain, Size: 100 bytes --]

I sent a v4! Please feel free to make any comments when I am submitting patches :)

Br
Christos

[-- Attachment #2: Type: text/html, Size: 150 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-01-20 20:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20250118120105.11681-1-gavrosc.ref@yahoo.com>
2025-01-18 12:01 ` [PATCH v3] sanity: test for c toolchain Christos Gavros
2025-01-20 13:42   ` [OE-core] " Richard Purdie
2025-01-20 20:35     ` Christos Gavros

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox