cc.v: use msvc on Windows by default if gcc is not installed

pull/2705/head
Alexander Medvednikov 2019-11-08 21:15:14 +03:00
parent c4ff0d565b
commit 6f95be60a1
2 changed files with 27 additions and 3 deletions

2
v.v
View File

@ -42,7 +42,7 @@ fn main() {
compiler.launch_tool('vup') compiler.launch_tool('vup')
return 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') compiler.launch_tool('vpm')
return return
} }

View File

@ -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() { fn (v mut V) cc() {
v.build_thirdparty_obj_files() v.build_thirdparty_obj_files()
vexe := vexe_path() vexe := vexe_path()
@ -57,7 +68,7 @@ fn (v mut V) cc() {
} }
} }
$if windows { $if windows {
if v.pref.ccompiler == 'msvc' { if v.pref.ccompiler == 'msvc' || no_mingw_installed() {
v.cc_msvc() v.cc_msvc()
return return
} }
@ -257,7 +268,20 @@ start:
println(cmd) println(cmd)
} }
ticks := time.ticks() 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 { if res.exit_code != 0 {
// the command could not be found by the system // the command could not be found by the system
if res.exit_code == 127 { if res.exit_code == 127 {