From c25b84828149a4957a795b08eb70caf5e89f8d9b Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Mon, 3 Jun 2024 10:42:15 +0200 Subject: sys/targets: test that C++ compiler works as well debian:bookworm has broken C++ arm64->amd64 cross-compiler: x86_64-linux-gnu-g++ -static-pie fails with: cannot find /usr/lib/x86_64-linux-gnu/libm-2.36.a: No such file or directory cannot find /usr/lib/x86_64-linux-gnu/libmvec.a: No such file or directory collect2: error: ld returned 1 exit status These are installed in a different dif in the image. Test that C++ compiler works as well. --- sys/targets/targets.go | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'sys/targets') diff --git a/sys/targets/targets.go b/sys/targets/targets.go index afc21d545..8e07b9aad 100644 --- a/sys/targets/targets.go +++ b/sys/targets/targets.go @@ -906,9 +906,11 @@ func (target *Target) lazyInit() { // On CI we want to fail loudly if cross-compilation breaks. // Also fail if SOURCEDIR_GOOS is set b/c in that case user probably assumes it will work. if (target.OS != runtime.GOOS || !runningOnCI) && getSourceDir(target) == "" { - if _, err := exec.LookPath(target.CCompiler); err != nil { - target.BrokenCompiler = fmt.Sprintf("%v is missing (%v)", target.CCompiler, err) - return + for _, comp := range []string{target.CCompiler, target.CxxCompiler} { + if _, err := exec.LookPath(comp); err != nil { + target.BrokenCompiler = fmt.Sprintf("%v is missing (%v)", comp, err) + return + } } } @@ -967,13 +969,19 @@ func (target *Target) lazyInit() { if runningOnCI || getSourceDir(target) != "" { return // On CI all compilers are expected to work, so we don't do the following check. } - args := []string{"-x", "c++", "-", "-o", "/dev/null"} - args = append(args, target.CFlags...) - cmd := exec.Command(target.CCompiler, args...) - cmd.Stdin = strings.NewReader(simpleProg) - if out, err := cmd.CombinedOutput(); err != nil { - target.BrokenCompiler = string(out) - return + for _, cxx := range []bool{false, true} { + lang, comp, flags := "c", target.CCompiler, target.CFlags + if cxx { + lang, comp, flags = "c++", target.CxxCompiler, target.CxxFlags + } + args := []string{"-x", lang, "-", "-o", "/dev/null"} + args = append(args, flags...) + cmd := exec.Command(comp, args...) + cmd.Stdin = strings.NewReader(simpleProg) + if out, err := cmd.CombinedOutput(); err != nil { + target.BrokenCompiler = string(out) + return + } } } -- cgit mrf-deployment