v.pref, v.builder: support `-no-rsp` (pass C options directly to the C compiler backend, without writing response files)

pull/11187/head
Delyan Angelov 2021-08-15 10:38:39 +03:00
parent 7494d7f6c7
commit f7cbcc241a
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
3 changed files with 28 additions and 12 deletions

View File

@ -228,6 +228,15 @@ see also `v help build`.
Write all C flags into `file.txt`, one flag per line.
If `file.txt` is `-`, then write the flags to stdout, one flag per line.
-no-rsp
By default, V passes all C compiler options to the backend C compiler
in so called "response files" (https://gcc.gnu.org/wiki/Response_Files).
This works in most cases, since it works around command line length
limitations on older systems (and windows), but some C compilers
(older versions of tcc for example) do not support them at all. When
you use -no-rsp, V will pass the C compiler options directly to the C
compiler, on the command line, without writing an .rsp file first.
-assert aborts
Call abort() after an assertion failure. Debuggers usually
install signal handlers for SIGABRT, so your program will stop and you

View File

@ -148,14 +148,11 @@ fn (mut v Builder) rebuild_cached_module(vexe string, imp_path string) string {
fn (mut v Builder) show_cc(cmd string, response_file string, response_file_content string) {
if v.pref.is_verbose || v.pref.show_cc {
println('')
println('=====================')
println('> C compiler cmd: $cmd')
if v.pref.show_cc {
println('> C compiler response file $response_file:')
if v.pref.show_cc && !v.pref.no_rsp {
println('> C compiler response file "$response_file":')
println(response_file_content)
}
println('=====================')
}
}
@ -610,16 +607,23 @@ fn (mut v Builder) cc() {
all_args := v.all_args(v.ccoptions)
v.dump_c_options(all_args)
str_args := all_args.join(' ')
// write args to response file
response_file := '${v.out_name_c}.rsp'
response_file_content := str_args.replace('\\', '\\\\')
mut cmd := '$ccompiler $str_args'
mut response_file := ''
mut response_file_content := str_args
if !v.pref.no_rsp {
response_file = '${v.out_name_c}.rsp'
response_file_content = str_args.replace('\\', '\\\\')
cmd = '$ccompiler "@$response_file"'
os.write_file(response_file, response_file_content) or {
verror('Unable to write response file "$response_file"')
verror('Unable to write to C response file "$response_file"')
}
}
if !v.ccoptions.debug_mode {
v.pref.cleanup_files << v.out_name_c
if !v.pref.no_rsp {
v.pref.cleanup_files << response_file
}
}
$if windows {
if v.ccoptions.is_cc_tcc {
def_name := v.pref.out_name[0..v.pref.out_name.len - 4]
@ -628,7 +632,6 @@ fn (mut v Builder) cc() {
}
//
os.chdir(vdir)
cmd := '$ccompiler "@$response_file"'
tried_compilation_commands << cmd
v.show_cc(cmd, response_file, response_file_content)
// Run

View File

@ -172,6 +172,7 @@ pub mut:
warns_are_errors bool // -W, like C's "-Werror", treat *every* warning is an error
fatal_errors bool // unconditionally exit after the first error with exit(1)
reuse_tmpc bool // do not use random names for .tmp.c and .tmp.c.rsp files, and do not remove them
no_rsp bool // when true, pass C backend options directly on the CLI (do not use `.rsp` files for them, some older C compilers do not support them)
use_color ColorOutput // whether the warnings/errors should use ANSI color escapes.
is_parallel bool
error_limit int
@ -474,6 +475,9 @@ pub fn parse_args(known_external_commands []string, args []string) (&Preferences
'-W' {
res.warns_are_errors = true
}
'-no-rsp' {
res.no_rsp = true
}
'-keepc' {
res.reuse_tmpc = true
}