Skip to content

Commit ed97874

Browse files
Christos-Gavrosmbriand
authored andcommitted
sanity: test for c toolchain
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] (From OE-Core rev: 8fd53741d340323b6eec493ecad2f192e33c0fc6) Signed-off-by: Christos Gavros <[email protected]> Reviewed-by: Yoann Congal <[email protected]> Signed-off-by: Mathieu Dubois-Briand <[email protected]>
1 parent c89063f commit ed97874

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

meta/classes-global/sanity.bbclass

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,43 @@ def drop_v14_cross_builds(d):
602602
bb.utils.remove(stamp + "*")
603603
bb.utils.remove(workdir, recurse = True)
604604

605+
def check_c_toolchain(d):
606+
"""
607+
it checks if the c compiling and linking to libstdc++ works properly in the native system
608+
"""
609+
import os
610+
import subprocess
611+
from tempfile import NamedTemporaryFile
612+
613+
try:
614+
with NamedTemporaryFile(delete=False, suffix=".c") as c_file:
615+
c_code = """
616+
#include <stdio.h>
617+
int main() {
618+
printf(\"Hello, World!\\n\");
619+
return 0;
620+
}
621+
"""
622+
c_file.write(c_code.encode('utf-8'))
623+
c_file_name = c_file.name
624+
625+
build_cc = d.getVar('BUILD_CC').strip()
626+
output_binary = c_file_name + ".out"
627+
compile_command = [build_cc, c_file_name, '-o', output_binary,'-lstdc++']
628+
result = subprocess.run(compile_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
629+
630+
if result.returncode == 0:
631+
return None
632+
else:
633+
return f"C toolchain check failed to link against libstdc++. Please ensure libstdc++ and headers are installed. Error:\n{result.stderr.decode()}"
634+
except Exception as e:
635+
return f"An unexpected issue occurred during the C toolchain check: {str(e)}"
636+
finally:
637+
if c_file_name and os.path.exists(c_file_name):
638+
os.remove(c_file_name)
639+
if output_binary and os.path.exists(output_binary):
640+
os.remove(output_binary)
641+
605642
def sanity_handle_abichanges(status, d):
606643
#
607644
# Check the 'ABI' of TMPDIR
@@ -770,6 +807,9 @@ def check_sanity_version_change(status, d):
770807
# macOS with default HFS+ file system)
771808
status.addresult(check_case_sensitive(tmpdir, "TMPDIR"))
772809

810+
# Check if linking with lstdc++ is failing
811+
status.addresult(check_c_toolchain(d))
812+
773813
def sanity_check_locale(d):
774814
"""
775815
Currently bitbake switches locale to en_US.UTF-8 so check that this locale actually exists.

0 commit comments

Comments
 (0)