Skip to content

Commit

Permalink
v: add -cstrict for optionally turning on all ccoptions.wargs
Browse files Browse the repository at this point in the history
  • Loading branch information
spytheman committed Apr 15, 2021
1 parent 5ae3b81 commit d90be54
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
4 changes: 4 additions & 0 deletions cmd/v/help/build-c.txt
Expand Up @@ -16,6 +16,10 @@ see also `v help build`.
Pass the provided flag as is to the C compiler.
Can be specified multiple times to provide multiple flags.
Use quotes to wrap the flag argument if it contains spaces.

-cstrict
Turn on additional C warnings. This slows down compilation
slightly (~10-10% for gcc), but sometimes provides better diagnosis.

-showcc
Prints the C command that is used to build the program.
Expand Down
13 changes: 8 additions & 5 deletions vlib/v/builder/cc.v
Expand Up @@ -378,14 +378,17 @@ fn (mut v Builder) setup_ccompiler_options(ccompiler string) {
}
v.ccoptions = ccoptions
// setup the cache too, so that different compilers/options do not interfere:
v.pref.cache_manager.set_temporary_options(ccoptions.thirdparty_object_args([
v.pref.cache_manager.set_temporary_options(v.thirdparty_object_args(v.ccoptions, [
ccoptions.guessed_compiler,
]))
}

fn (ccoptions CcompilerOptions) all_args() []string {
fn (v &Builder) all_args(ccoptions CcompilerOptions) []string {
mut all := []string{}
all << ccoptions.env_cflags
if v.pref.is_cstrict {
all << ccoptions.wargs
}
all << ccoptions.args
all << ccoptions.o_args
all << ccoptions.pre_args
Expand All @@ -396,7 +399,7 @@ fn (ccoptions CcompilerOptions) all_args() []string {
return all
}

fn (ccoptions CcompilerOptions) thirdparty_object_args(middle []string) []string {
fn (v &Builder) thirdparty_object_args(ccoptions CcompilerOptions, middle []string) []string {
mut all := []string{}
all << ccoptions.env_cflags
all << ccoptions.args
Expand Down Expand Up @@ -611,7 +614,7 @@ fn (mut v Builder) cc() {
}
}
//
all_args := v.ccoptions.all_args()
all_args := v.all_args(v.ccoptions)
v.dump_c_options(all_args)
str_args := all_args.join(' ')
// write args to response file
Expand Down Expand Up @@ -953,7 +956,7 @@ fn (mut v Builder) build_thirdparty_obj_file(path string, moduleflags []cflag.CF
all_options << moduleflags.c_options_before_target()
all_options << '-o "$opath"'
all_options << '-c "$cfile"'
cc_options := v.ccoptions.thirdparty_object_args(all_options).join(' ')
cc_options := v.thirdparty_object_args(v.ccoptions, all_options).join(' ')
cmd := '$v.pref.ccompiler $cc_options'
$if trace_thirdparty_obj_files ? {
println('>>> build_thirdparty_obj_files cmd: $cmd')
Expand Down
4 changes: 4 additions & 0 deletions vlib/v/pref/pref.v
Expand Up @@ -166,6 +166,7 @@ pub mut:
cache_manager vcache.CacheManager
is_help bool // -h, -help or --help was passed
gc_mode GarbageCollectionMode = .no_gc // .no_gc, .boehm, .boehm_leak, ...
is_cstrict bool // turn on more C warnings; slightly slower
// checker settings:
checker_match_exhaustive_cutoff_limit int = 10
}
Expand Down Expand Up @@ -227,6 +228,9 @@ pub fn parse_args(known_external_commands []string, args []string) (&Preferences
'-silent' {
res.output_mode = .silent
}
'-cstrict' {
res.is_cstrict = true
}
'-gc' {
gc_mode := cmdline.option(current_args, '-gc', '')
match gc_mode {
Expand Down

0 comments on commit d90be54

Please sign in to comment.