mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
compiler: use thirdparty/tcc/tcc.exe by default, when no explicit -cc is given (#6598)
This commit is contained in:
@@ -217,6 +217,12 @@ fn (mut v Builder) cc() {
|
||||
return
|
||||
}
|
||||
}
|
||||
//
|
||||
mut tried_compilation_commands := []string{}
|
||||
original_pwd := os.getwd()
|
||||
// TODO remove the start: goto start construct;
|
||||
// use a labeled for break instead
|
||||
start:
|
||||
mut ccompiler := v.pref.ccompiler
|
||||
$if windows {
|
||||
if ccompiler == 'msvc' {
|
||||
@@ -248,35 +254,6 @@ fn (mut v Builder) cc() {
|
||||
args << '-fobjc-arc'
|
||||
}
|
||||
mut linker_flags := []string{}
|
||||
// TCC on Linux by default, unless -cc was provided
|
||||
// TODO if -cc = cc, TCC is still used, default compiler should be
|
||||
// used instead.
|
||||
if v.pref.fast {
|
||||
$if linux {
|
||||
$if !android {
|
||||
tcc_3rd := '$vdir/thirdparty/tcc/bin/tcc'
|
||||
// println('tcc third "$tcc_3rd"')
|
||||
tcc_path := '/var/tmp/tcc/bin/tcc'
|
||||
if os.exists(tcc_3rd) && !os.exists(tcc_path) {
|
||||
// println('moving tcc')
|
||||
// if there's tcc in thirdparty/, that means this is
|
||||
// a prebuilt V_linux.zip.
|
||||
// Until the libtcc1.a bug is fixed, we neeed to move
|
||||
// it to /var/tmp/
|
||||
os.system('mv $vdir/thirdparty/tcc /var/tmp/')
|
||||
}
|
||||
if v.pref.ccompiler == 'cc' && os.exists(tcc_path) {
|
||||
// TODO tcc bug, needs an empty libtcc1.a fila
|
||||
// os.mkdir('/var/tmp/tcc/lib/tcc/') or { panic(err) }
|
||||
// os.create('/var/tmp/tcc/lib/tcc/libtcc1.a')
|
||||
v.pref.ccompiler = tcc_path
|
||||
args << '-m64'
|
||||
}
|
||||
}
|
||||
} $else {
|
||||
verror('-fast is only supported on Linux right now')
|
||||
}
|
||||
}
|
||||
if !v.pref.is_shared && v.pref.build_mode != .build_module && os.user_os() == 'windows' &&
|
||||
!v.pref.out_name.ends_with('.exe') {
|
||||
v.pref.out_name += '.exe'
|
||||
@@ -353,9 +330,9 @@ fn (mut v Builder) cc() {
|
||||
}
|
||||
if debug_mode {
|
||||
args << debug_options
|
||||
$if macos {
|
||||
args << ' -ferror-limit=5000 '
|
||||
}
|
||||
// $if macos {
|
||||
// args << ' -ferror-limit=5000 '
|
||||
// }
|
||||
}
|
||||
if v.pref.is_prod {
|
||||
args << optimization_options
|
||||
@@ -448,7 +425,9 @@ fn (mut v Builder) cc() {
|
||||
}
|
||||
// macOS code can include objective C TODO remove once objective C is replaced with C
|
||||
if v.pref.os == .macos || v.pref.os == .ios {
|
||||
args << '-x objective-c'
|
||||
if !is_cc_tcc {
|
||||
args << '-x objective-c'
|
||||
}
|
||||
}
|
||||
// The C file we are compiling
|
||||
args << '"$v.out_name_c"'
|
||||
@@ -535,10 +514,11 @@ fn (mut v Builder) cc() {
|
||||
v.pref.cleanup_files << v.out_name_c
|
||||
v.pref.cleanup_files << response_file
|
||||
}
|
||||
start:
|
||||
//
|
||||
todo()
|
||||
// TODO remove
|
||||
os.chdir(vdir)
|
||||
cmd := '$ccompiler @$response_file'
|
||||
tried_compilation_commands << cmd
|
||||
v.show_cc(cmd, response_file, response_file_content)
|
||||
// Run
|
||||
ticks := time.ticks()
|
||||
@@ -546,6 +526,7 @@ fn (mut v Builder) cc() {
|
||||
// C compilation failed.
|
||||
// If we are on Windows, try msvc
|
||||
println('C compilation failed.')
|
||||
os.chdir(original_pwd)
|
||||
/*
|
||||
if os.user_os() == 'windows' && v.pref.ccompiler != 'msvc' {
|
||||
println('Trying to build with MSVC')
|
||||
@@ -561,19 +542,27 @@ fn (mut v Builder) cc() {
|
||||
if v.pref.show_c_output {
|
||||
v.show_c_compiler_output(res)
|
||||
}
|
||||
if res.exit_code == 127 {
|
||||
// the command could not be found by the system
|
||||
$if linux {
|
||||
// TCC problems on linux? Try GCC.
|
||||
if ccompiler.contains('tcc') {
|
||||
v.pref.ccompiler = 'cc'
|
||||
goto start
|
||||
os.chdir(original_pwd)
|
||||
if res.exit_code != 0 {
|
||||
if ccompiler.contains('tcc.exe') {
|
||||
// a TCC problem? Retry with the system cc:
|
||||
if tried_compilation_commands.len > 1 {
|
||||
eprintln('Recompilation loop detected (ccompiler: $ccompiler):')
|
||||
for recompile_command in tried_compilation_commands {
|
||||
eprintln(' $recompile_command')
|
||||
}
|
||||
exit(101)
|
||||
}
|
||||
eprintln('recompilation with tcc failed; retrying with cc ...')
|
||||
v.pref.ccompiler = pref.default_c_compiler()
|
||||
goto start
|
||||
}
|
||||
if res.exit_code == 127 {
|
||||
verror('C compiler error, while attempting to run: \n' +
|
||||
'-----------------------------------------------------------\n' + '$cmd\n' +
|
||||
'-----------------------------------------------------------\n' + 'Probably your C compiler is missing. \n' +
|
||||
'Please reinstall it, or make it available in your PATH.\n\n' + missing_compiler_info())
|
||||
}
|
||||
verror('C compiler error, while attempting to run: \n' +
|
||||
'-----------------------------------------------------------\n' + '$cmd\n' +
|
||||
'-----------------------------------------------------------\n' + 'Probably your C compiler is missing. \n' +
|
||||
'Please reinstall it, or make it available in your PATH.\n\n' + missing_compiler_info())
|
||||
}
|
||||
if !v.pref.show_c_output {
|
||||
v.post_process_c_compiler_output(res)
|
||||
|
||||
Reference in New Issue
Block a user