From 6f95be60a104b98c3cf9126e736f0adfe64e1f67 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Fri, 8 Nov 2019 21:15:14 +0300 Subject: [PATCH] cc.v: use msvc on Windows by default if gcc is not installed --- v.v | 2 +- vlib/compiler/cc.v | 28 ++++++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/v.v b/v.v index d608f723f4..a792aa599f 100755 --- a/v.v +++ b/v.v @@ -42,7 +42,7 @@ fn main() { compiler.launch_tool('vup') return } - else if ('search' in commands) || ('install' in commands) || ('update' in commands) || ('remove' in commands){ + else if 'search' in commands || 'install' in commands || 'update' in commands || 'remove' in commands { compiler.launch_tool('vpm') return } diff --git a/vlib/compiler/cc.v b/vlib/compiler/cc.v index fcefdb4b99..beb178752d 100644 --- a/vlib/compiler/cc.v +++ b/vlib/compiler/cc.v @@ -14,6 +14,17 @@ fn todo() { } +fn no_mingw_installed() bool { + $if !windows { + panic('no_mingw_installed() can only run on Windows') + } + os.exec('gcc -v') or { + println('mingw not found, trying to build with msvc...') + return true + } + return false +} + fn (v mut V) cc() { v.build_thirdparty_obj_files() vexe := vexe_path() @@ -57,7 +68,7 @@ fn (v mut V) cc() { } } $if windows { - if v.pref.ccompiler == 'msvc' { + if v.pref.ccompiler == 'msvc' || no_mingw_installed() { v.cc_msvc() return } @@ -257,7 +268,20 @@ start: println(cmd) } ticks := time.ticks() - res := os.exec(cmd) or { verror(err) return } + res := os.exec(cmd) or { + // C compilation failed. + // If we are on Windows, try msvc + println('C compilation failed.') + /* + if os.user_os() == 'windows' && v.pref.ccompiler != 'msvc' { + println('Trying to build with MSVC') + v.cc_msvc() + return + } + */ + verror(err) + return + } if res.exit_code != 0 { // the command could not be found by the system if res.exit_code == 127 {