From 0a8d2d5dc7582999e864404e2373976f05a3f64b Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Tue, 3 Dec 2019 12:58:24 +0200 Subject: [PATCH] compiler: guess cc kind for -prod builds, to know when to add -flto --- vlib/compiler/cc.v | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/vlib/compiler/cc.v b/vlib/compiler/cc.v index 8095a92428..3d352df9fa 100644 --- a/vlib/compiler/cc.v +++ b/vlib/compiler/cc.v @@ -146,13 +146,30 @@ fn (v mut V) cc() { debug_mode := v.pref.is_debug mut debug_options := '-g' mut optimization_options := '-O2' - if v.pref.ccompiler.contains('clang') { + + mut guessed_compiler := v.pref.ccompiler + if guessed_compiler == 'cc' && v.pref.is_prod { + // deliberately guessing only for -prod builds for performance reasons + if ccversion := os.exec('cc --version') { + if ccversion.exit_code == 0 { + if ccversion.output.contains('This is free software;') + && ccversion.output.contains('Free Software Foundation, Inc.') { + guessed_compiler = 'gcc' + } + if ccversion.output.contains('clang version '){ + guessed_compiler = 'clang' + } + } + } + } + + if v.pref.ccompiler.contains('clang') || guessed_compiler == 'clang' { if debug_mode { debug_options = '-g -O0 -no-pie' } optimization_options = '-O3 -flto' } - if v.pref.ccompiler.contains('gcc') { + if v.pref.ccompiler.contains('gcc') || guessed_compiler == 'gcc' { if debug_mode { debug_options = '-g3 -no-pie' }