diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2024-06-03 15:29:50 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2024-06-03 14:38:34 +0000 |
| commit | 49b158db460b8b8d4144d5869453a1936639aa2b (patch) | |
| tree | 374ba42b7279dc30d48389b48ea2f75de10b55a8 /sys/targets | |
| parent | 417ff0144628e87a12ef36590287c1ce070a2f99 (diff) | |
sys/targets: build C++ program with C++ compiler
Arm64 gcc on Debian rejects to build a program that includes <algorithm>.
Use C program for C compiler, and C++ program for C++ compiler.
Diffstat (limited to 'sys/targets')
| -rw-r--r-- | sys/targets/targets.go | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/sys/targets/targets.go b/sys/targets/targets.go index 8e07b9aad..35068af01 100644 --- a/sys/targets/targets.go +++ b/sys/targets/targets.go @@ -970,14 +970,14 @@ func (target *Target) lazyInit() { return // On CI all compilers are expected to work, so we don't do the following check. } for _, cxx := range []bool{false, true} { - lang, comp, flags := "c", target.CCompiler, target.CFlags + lang, prog, comp, flags := "c", simpleCProg, target.CCompiler, target.CFlags if cxx { - lang, comp, flags = "c++", target.CxxCompiler, target.CxxFlags + lang, prog, comp, flags = "c++", simpleCxxProg, 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) + cmd.Stdin = strings.NewReader(prog) if out, err := cmd.CombinedOutput(); err != nil { target.BrokenCompiler = string(out) return @@ -989,7 +989,7 @@ func checkFlagSupported(target *Target, targetCFlags []string, flag string) bool args := []string{"-x", "c++", "-", "-o", "/dev/null", "-Werror", flag} args = append(args, targetCFlags...) cmd := exec.Command(target.CCompiler, args...) - cmd.Stdin = strings.NewReader(simpleProg) + cmd.Stdin = strings.NewReader(simpleCProg) return cmd.Run() == nil } @@ -1082,10 +1082,14 @@ var ( const ( sourceDirVar = "${SOURCEDIR}" - simpleProg = ` + simpleCProg = ` #include <stdio.h> #include <dirent.h> // ensures that system headers are installed -#include <algorithm> // ensures that C++ headers are installed int main() { printf("Hello, World!\n"); } ` + simpleCxxProg = ` +#include <algorithm> // ensures that C++ headers are installed +#include <vector> +int main() { std::vector<int> v(10); } +` ) |
