1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

Support for passing different options to the C compiler backend.

Example: 'v -c_options=-Os' will pass -Os to the C compiler.
In effect the C compiler will optimize the generated binary for size.
This commit is contained in:
Delyan Angelov 2019-07-16 19:15:14 +03:00 committed by Alexander Medvednikov
parent 47b0221b82
commit 17580f3013

View File

@ -88,6 +88,9 @@ mut:
sanitize bool // use Clang's new "-fsanitize" option sanitize bool // use Clang's new "-fsanitize" option
is_debug bool // keep compiled C files is_debug bool // keep compiled C files
no_auto_free bool // `v -nofree` disable automatic `free()` insertion for better performance in some applications (e.g. compilers) no_auto_free bool // `v -nofree` disable automatic `free()` insertion for better performance in some applications (e.g. compilers)
c_options string // Additional options which will be passed to the C compiler.
// For example, passing -c_options=-Os will cause the C compiler to optimize the generated binaries for size.
// You could pass several -c_options=XXX arguments. They will be merged with each other.
} }
@ -529,7 +532,7 @@ fn (v mut V) cc() {
} }
linux_host := os.user_os() == 'linux' linux_host := os.user_os() == 'linux'
v.log('cc() isprod=$v.pref.is_prod outname=$v.out_name') v.log('cc() isprod=$v.pref.is_prod outname=$v.out_name')
mut a := ['-w'] // arguments for the C compiler mut a := [v.pref.c_options, '-w'] // arguments for the C compiler
flags := v.table.flags.join(' ') flags := v.table.flags.join(' ')
//mut shared := '' //mut shared := ''
if v.pref.is_so { if v.pref.is_so {
@ -960,6 +963,14 @@ fn new_v(args[]string) *V {
files << f files << f
} }
} }
mut c_options := ''
for ci, cv in args {
if cv.starts_with('-c_options=') {
c_options += cv.replace('-c_options=','') + ' '
}
}
obfuscate := args.contains('-obf') obfuscate := args.contains('-obf')
pref := &Preferences { pref := &Preferences {
is_test: is_test is_test: is_test
@ -979,6 +990,7 @@ fn new_v(args[]string) *V {
is_run: args.contains('run') is_run: args.contains('run')
is_repl: args.contains('-repl') is_repl: args.contains('-repl')
build_mode: build_mode build_mode: build_mode
c_options: c_options
} }
if pref.is_so { if pref.is_so {