v/vlib/v/pref/pref.v

105 lines
4.7 KiB
V
Raw Normal View History

// Copyright (c) 2019-2020 Alexander Medvednikov. All rights reserved.
// Use of this source code is governed by an MIT license
// that can be found in the LICENSE file.
module pref
pub enum BuildMode {
// `v program.v'
// Build user code only, and add pre-compiled vlib (`cc program.o builtin.o os.o...`)
default_mode
// `v -lib ~/v/os`
// build any module (generate os.o + os.vh)
build_module
}
2020-03-06 18:53:29 +01:00
pub enum Backend {
c // The (default) C backend
js // The JavaScript backend
x64 // The x64 backend
}
pub struct Preferences {
pub mut:
2020-02-09 10:08:04 +01:00
os OS // the OS to compile for
2020-03-06 18:53:29 +01:00
backend Backend
2020-02-09 10:08:04 +01:00
build_mode BuildMode
2020-04-07 00:44:19 +02:00
//verbosity VerboseLevel
is_verbose bool
2020-02-09 10:08:04 +01:00
// nofmt bool // disable vfmt
is_test bool // `v test string_test.v`
is_script bool // single file mode (`v program.v`), main function can be skipped
2020-05-01 19:34:27 +02:00
is_livemain bool // main program that contains live/hot code
is_liveshared bool // a shared library, that will be used in a -live main program
is_shared bool // an ordinary shared library, -shared, no matter if it is live or not
2020-02-09 10:08:04 +01:00
is_prof bool // benchmark every function
profile_file string // the profile results will be stored inside profile_file
profile_no_inline bool // when true, [inline] functions would not be profiled
2020-02-09 10:08:04 +01:00
translated bool // `v translate doom.v` are we running V code translated from C? allow globals, ++ expressions, etc
is_prod bool // use "-O2"
obfuscate bool // `v -obf program.v`, renames functions to "f_XXX"
is_repl bool
is_run bool
sanitize bool // use Clang's new "-fsanitize" option
is_debug bool // false by default, turned on by -g or -cg, it tells v to pass -g to the C backend compiler.
is_vlines bool // turned on by -g, false by default (it slows down .tmp.c generation slightly).
2020-04-27 13:27:55 +02:00
keep_c bool // -keepc , tell v to leave the generated .tmp.c alone (since by default v will delete them after c backend finishes)
show_cc bool // -showcc, print cc command
// NB: passing -cg instead of -g will set is_vlines to false and is_g to true, thus making v generate cleaner C files,
// which are sometimes easier to debug / inspect manually than the .tmp.c files by plain -g (when/if v line number generation breaks).
2020-04-27 14:46:25 +02:00
use_cache bool // turns on v usage of the module cache to speed up compilation.
2020-02-09 10:08:04 +01:00
is_stats bool // `v -stats file_test.v` will produce more detailed statistics for the tests that were run
no_auto_free bool // `v -nofree` disable automatic `free()` insertion for better performance in some applications (e.g. compilers)
2020-03-06 18:53:29 +01:00
// TODO Convert this into a []string
2020-02-09 10:08:04 +01:00
cflags string // Additional options which will be passed to the C compiler.
// For example, passing -cflags -Os will cause the C compiler to optimize the generated binaries for size.
// You could pass several -cflags XXX arguments. They will be merged with each other.
// You can also quote several options at the same time: -cflags '-Os -fno-inline-small-functions'.
2020-02-09 10:08:04 +01:00
ccompiler string // the name of the used C compiler
third_party_option string
building_v bool
autofree bool
compress bool
// skip_builtin bool // Skips re-compilation of the builtin module
// to increase compilation time.
// This is on by default, since a vast majority of users do not
// work on the builtin module itself.
2020-02-09 10:08:04 +01:00
// generating_vh bool
fast bool // use tcc/x64 codegen
enable_globals bool // allow __global for low level code
is_fmt bool
2020-02-09 10:08:04 +01:00
is_bare bool
2020-03-06 18:53:29 +01:00
lookup_path []string
2020-02-09 10:08:04 +01:00
output_cross_c bool
prealloc bool
vroot string
out_name string
path string // Path to file/folder to compile
// -d vfmt and -d another=0 for `$if vfmt { will execute }` and `$if another { will NOT get here }`
compile_defines []string // just ['vfmt']
compile_defines_all []string // contains both: ['vfmt','another']
mod string
run_args []string // `v run x.v 1 2 3` => `1 2 3`
printfn_list []string // a list of generated function names, whose source should be shown, for debugging
2020-05-01 19:34:27 +02:00
print_v_files bool // when true, just print the list of all parsed .v files then stop.
skip_running bool // when true, do no try to run the produced file (set by b.cc(), when -o x.c or -o x.js)
}
2020-03-06 18:53:29 +01:00
pub fn backend_from_string(s string) ?Backend {
match s {
'c' {
return .c
}
'js' {
return .js
}
'x64' {
return .x64
}
else {
return error('Unknown backend type $s')
}
}
}