v.pref #
Constants #
const supported_test_runners = ['normal', 'simple', 'tap', 'dump', 'teamcity']
const default_module_path = os.vmodules_dir()
fn add_line_info_expr_to_program_text #
fn add_line_info_expr_to_program_text(raw_text string, linfo LineInfo) string
fn arch_from_string #
fn arch_from_string(arch_str string) !Arch
fn backend_from_string #
fn backend_from_string(s string) !Backend
fn cc_from_string #
fn cc_from_string(s string) CompilerType
Helper function to convert string names to CC enum
fn default_tcc_compiler #
fn default_tcc_compiler() string
fn eprintln_cond #
fn eprintln_cond(condition bool, s string)
fn eprintln_exit #
fn eprintln_exit(s string)
fn get_host_arch #
fn get_host_arch() Arch
fn get_host_os #
fn get_host_os() OS
fn new_preferences #
fn new_preferences() &Preferences
fn os_from_string #
fn os_from_string(os_str string) !OS
Helper function to convert string names to OS enum
fn parse_args #
fn parse_args(known_external_commands []string, args []string) (&Preferences, string)
fn parse_args_and_show_errors #
fn parse_args_and_show_errors(known_external_commands []string, args []string, show_output bool) (&Preferences, string)
fn supported_test_runners_list #
fn supported_test_runners_list() string
fn vexe_path #
fn vexe_path() string
enum Arch #
enum Arch {
_auto
amd64 // aka x86_64
arm64 // 64-bit arm
arm32 // 32-bit arm
rv64 // 64-bit risc-v
rv32 // 32-bit risc-v
i386
js_node
js_browser
js_freestanding
wasm32
_max
}
enum AssertFailureMode #
enum AssertFailureMode {
default
aborts
backtraces
continues
}
enum Backend #
enum Backend {
c // The (default) C backend
golang // Go backend
interpret // Interpret the ast
js_node // The JavaScript NodeJS backend
js_browser // The JavaScript browser backend
js_freestanding // The JavaScript freestanding backend
native // The Native backend
wasm // The WebAssembly backend
}
fn (Backend) is_js #
fn (b Backend) is_js() bool
enum BuildMode #
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
}
enum ColorOutput #
enum ColorOutput {
auto
always
never
}
enum CompilerType #
enum CompilerType {
gcc
tinyc
clang
mingw
msvc
cplusplus
}
enum GarbageCollectionMode #
enum GarbageCollectionMode {
unknown
no_gc
boehm_full // full garbage collection mode
boehm_incr // incremental garbage collection mode
boehm_full_opt // full garbage collection mode
boehm_incr_opt // incremental garbage collection mode
boehm_leak // leak detection mode (makes `gc_check_leaks()` work)
}
enum OS #
enum OS {
_auto // Reserved so .macos cannot be misunderstood as auto
ios
macos
linux
windows
freebsd
openbsd
netbsd
dragonfly
js_node
js_browser
js_freestanding
android
termux // like android, but compiling/running natively on the devices
solaris
qnx
serenity
plan9
vinix
haiku
wasm32
wasm32_emscripten
wasm32_wasi
browser // -b wasm -os browser
wasi // -b wasm -os wasi
raw
all
}
fn (OS) is_target_of #
fn (this_os OS) is_target_of(target string) bool
is_target_of returns true if this_os is included in the target specified for example, 'nix' is true for Linux and FreeBSD but not Windows
fn (OS) str #
fn (o OS) str() string
enum OutputMode #
enum OutputMode {
stdout
silent
}
enum Subsystem #
enum Subsystem {
auto
console
windows
}
Subsystem is needed for modeling passing an explicit /subsystem:windows
or /subsystem:console
on Windows. By default it is auto
. It has no effect on platforms != windows.
struct LineInfo #
struct LineInfo {
pub mut:
line_nr int // a quick single file run when called with v -line-info (contains line nr to inspect)
path string // same, but stores the path being parsed
expr string // "foo" or "foo.bar" V code (expression) which needs autocomplete
is_running bool // so that line info is fetched only on the second checker run
vars_printed map[string]bool // to avoid dups
}
struct Preferences #
@[heap]
@[minify]
struct Preferences {
pub mut:
os OS // the OS to compile for
backend Backend
build_mode BuildMode
arch Arch
output_mode OutputMode = .stdout
// verbosity VerboseLevel
is_verbose bool
// nofmt bool // disable vfmt
is_glibc bool // if GLIBC will be linked
is_musl bool // if MUSL will be linked
is_test bool // `v test string_test.v`
is_script bool // single file mode (`v program.v`), main function can be skipped
is_vsh bool // v script (`file.vsh`) file, the `os` module should be made global
raw_vsh_tmp_prefix string // The prefix used for executables, when a script lacks the .vsh extension
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
is_o bool // building an .o file
is_prof bool // benchmark every function
is_prod bool // use "-O2"
is_repl bool
is_eval_argument bool // true for `v -e 'println(2+2)'`. `println(2+2)` will be in pref.eval_argument .
is_run bool // compile and run a v program, passing arguments to it, and deleting the executable afterwards
is_crun bool // similar to run, but does not recompile the executable, if there were no changes to the sources
is_debug bool // turned on by -g or -cg, it tells v to pass -g to the C backend compiler.
is_vlines bool // turned on by -g (it slows down .tmp.c generation slightly).
is_stats bool // `v -stats file.v` will produce more detailed statistics for the file that is compiled
show_asserts bool // `VTEST_SHOW_ASSERTS=1 v file_test.v` will show details about the asserts done by a test file. Also activated for `-stats` and `-show-asserts`.
show_timings bool // show how much time each compiler stage took
is_fmt bool
is_vet bool
is_vweb bool // skip _ var warning in templates
is_ios_simulator bool
is_apk bool // build as Android .apk format
is_help bool // -h, -help or --help was passed
is_quiet bool // do not show the repetitive explanatory messages like the one for `v -prod run file.v` .
is_cstrict bool // turn on more C warnings; slightly slower
is_callstack bool // turn on callstack registers on each call when v.debug is imported
is_trace bool // turn on possibility to trace fn call where v.debug is imported
is_coverage bool // turn on code coverage stats
eval_argument string // `println(2+2)` on `v -e "println(2+2)"`. Note that this source code, will be evaluated in vsh mode, so 'v -e 'println(ls(".")!)' is valid.
test_runner string // can be 'simple' (fastest, but much less detailed), 'tap', 'normal'
profile_file string // the profile results will be stored inside profile_file
coverage_dir string // the coverage files will be stored inside coverage_dir
profile_no_inline bool // when true, @[inline] functions would not be profiled
profile_fns []string // when set, profiling will be off by default, but inside these functions (and what they call) it will be on.
translated bool // `v translate doom.v` are we running V code translated from C? allow globals, ++ expressions, etc
translated_go bool = true // Are we running V code translated from Go? Allow err shadowing
obfuscate bool // `v -obf program.v`, renames functions to "f_XXX"
hide_auto_str bool // `v -hide-auto-str program.v`, doesn't generate str() with struct data
// Note: passing -cg instead of -g will set is_vlines to false and is_debug 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).
sanitize bool // use Clang's new "-fsanitize" option
sourcemap bool // JS Backend: -sourcemap will create a source map - default false
sourcemap_inline bool = true // JS Backend: -sourcemap-inline will embed the source map in the generated JaaScript file - currently default true only implemented
sourcemap_src_included bool // JS Backend: -sourcemap-src-included includes V source code in source map - default false
show_cc bool // -showcc, print cc command
show_c_output bool // -show-c-output, print all cc output even if the code was compiled correctly
show_callgraph bool // -show-callgraph, print the program callgraph, in a Graphviz DOT format to stdout
show_depgraph bool // -show-depgraph, print the program module dependency graph, in a Graphviz DOT format to stdout
show_unused_params bool // NOTE: temporary until making it a default.
dump_c_flags string // `-dump-c-flags file.txt` - let V store all C flags, passed to the backend C compiler in `file.txt`, one C flag/value per line.
dump_modules string // `-dump-modules modules.txt` - let V store all V modules, that were used by the compiled program in `modules.txt`, one module per line.
dump_files string // `-dump-files files.txt` - let V store all V or .template file paths, that were used by the compiled program in `files.txt`, one path per line.
dump_defines string // `-dump-defines defines.txt` - let V store all the defines that affect the current program and their values, one define per line + `,` + its value.
use_cache bool // when set, use cached modules to speed up subsequent compilations, at the cost of slower initial ones (while the modules are cached)
retry_compilation bool = true // retry the compilation with another C compiler, if tcc fails.
use_os_system_to_run bool // when set, use os.system() to run the produced executable, instead of os.new_process; works around segfaults on macos, that may happen when xcode is updated
macosx_version_min string = '0' // relevant only for macos and ios targets
// TODO: Convert this into a []string
cflags string // Additional options which will be passed to the C compiler *before* other options.
ldflags string // Additional options which will be passed to the C compiler *after* everything else.
// 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'.
m64 bool // true = generate 64-bit code, defaults to x64
ccompiler string // the name of the C compiler used
ccompiler_type CompilerType // the type of the C compiler used
cppcompiler string // the name of the CPP compiler used
third_party_option string
building_v bool
no_bounds_checking bool // `-no-bounds-checking` turns off *all* bounds checks for all functions at runtime, as if they all had been tagged with `[direct_array_access]`
autofree bool // `v -manualfree` => false, `v -autofree` => true; false by default for now.
print_autofree_vars bool // print vars that are not freed by autofree
print_autofree_vars_in_fn string // same as above, but only for a single fn
// Disabling `free()` insertion results in better performance in some applications (e.g. compilers)
trace_calls bool // -trace-calls true = the transformer stage will generate and inject print calls for tracing function calls
trace_fns []string // when set, tracing will be done only for functions, whose names match the listed patterns.
compress bool // when set, use `upx` to compress the generated executable
// generating_vh bool
no_builtin bool // Skip adding the `builtin` module implicitly. The generated C code may not compile.
enable_globals bool // allow __global for low level code
is_bare bool // set by -freestanding
bare_builtin_dir string // Set by -bare-builtin-dir xyz/ . The xyz/ module should contain implementations of malloc, memset, etc, that are used by the rest of V's `builtin` module. That option is only useful with -freestanding (i.e. when is_bare is true).
no_preludes bool // Prevents V from generating preludes in resulting .c files
custom_prelude string // Contents of custom V prelude that will be prepended before code in resulting .c files
cmain string // The name of the generated C main function. Useful with framework like code, that uses macros to re-define `main`, like SDL2 does. When set, V will always generate `int THE_NAME(int ___argc, char** ___argv){`, *no matter* the platform.
lookup_path []string
output_cross_c bool // true, when the user passed `-os cross` or `-cross`
output_es5 bool
prealloc bool
vroot string
vlib string // absolute path to the vlib/ folder
vmodules_paths []string // absolute paths to the vmodules folders, by default ['/home/user/.vmodules'], can be overridden by setting VMODULES
out_name_c string // full os.real_path to the generated .tmp.c file; set by builder.
out_name string
path string // Path to file/folder to compile
line_info string // `-line-info="file.v:28"`: for "mini VLS" (shows information about objects on provided line)
linfo LineInfo
run_only []string // VTEST_ONLY_FN and -run-only accept comma separated glob patterns.
exclude []string // glob patterns for excluding .v files from the list of .v files that otherwise would have been used for a compilation, example: `-exclude @vlib/math/*.c.v`
// Only test_ functions that match these patterns will be run. -run-only is valid only for _test.v files.
// -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']
compile_values map[string]string // the map will contain for `-d key=value`: compile_values['key'] = 'value', and for `-d ident`, it will be: compile_values['ident'] = 'true'
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
print_v_files bool // when true, just print the list of all parsed .v files then stop.
print_watched_files bool // when true, just print the list of all parsed .v files + all the compiled $tmpl files, then stop. Used by `v watch run webserver.v`
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)
skip_warnings bool // like C's "-w", forces warnings to be ignored.
skip_notes bool // force notices to be ignored/not shown.
warn_impure_v bool // -Wimpure-v, force a warning for JS.fn()/C.fn(), outside of .js.v/.c.v files. TODO: turn to an error by default
warns_are_errors bool // -W, like C's "-Werror", treat *every* warning is an error
notes_are_errors bool // -N, treat *every* notice as 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)
no_std bool // when true, do not pass -std=gnu99(linux)/-std=c99 to the C backend
no_parallel bool // do not use threads when compiling; slower, but more portable and sometimes less buggy
parallel_cc bool // whether to split the resulting .c file into many .c files + a common .h file, that are then compiled in parallel, then linked together.
only_check_syntax bool // when true, just parse the files, then stop, before running checker
check_only bool // same as only_check_syntax, but also runs the checker
experimental bool // enable experimental features
skip_unused bool // skip generating C code for functions, that are not used
use_color ColorOutput // whether the warnings/errors should use ANSI color escapes.
cleanup_files []string // list of temporary *.tmp.c and *.tmp.c.rsp files. Cleaned up on successful builds.
build_options []string // list of options, that should be passed down to `build-module`, if needed for -usecache
cache_manager vcache.CacheManager
gc_mode GarbageCollectionMode = .unknown // .no_gc, .boehm, .boehm_leak, ...
assert_failure_mode AssertFailureMode // whether to call abort() or print_backtrace() after an assertion failure
message_limit int = 150 // the maximum amount of warnings/errors/notices that will be accumulated
nofloat bool // for low level code, like kernels: replaces f32 with u32 and f64 with u64
use_coroutines bool // experimental coroutines
fast_math bool // -fast-math will pass either -ffast-math or /fp:fast (for msvc) to the C backend
// checker settings:
checker_match_exhaustive_cutoff_limit int = 12
thread_stack_size int = 8388608 // Change with `-thread-stack-size 4194304`. Note: on macos it was 524288, which is too small for more complex programs with many nested callexprs.
// wasm settings:
wasm_stack_top int = 1024 + (16 * 1024) // stack size for webassembly backend
wasm_validate bool // validate webassembly code, by calling `wasm-validate`
warn_about_allocs bool // -warn-about-allocs warngs about every single allocation, e.g. 'hi $name'. Mostly for low level development where manual memory management is used.
// temp
// use_64_int bool
// forwards compatibility settings:
relaxed_gcc14 bool = true // turn on the generated pragmas, that make gcc versions > 14 a lot less pedantic. The default is to have those pragmas in the generated C output, so that gcc-14 can be used on Arch etc.
//
subsystem Subsystem // the type of the window app, that is going to be generated; has no effect on !windows
}
fn (Preferences) default_c_compiler #
fn (mut p Preferences) default_c_compiler()
fn (Preferences) default_cpp_compiler #
fn (mut p Preferences) default_cpp_compiler()
fn (Preferences) fill_with_defaults #
fn (mut p Preferences) fill_with_defaults()
fn (Preferences) should_compile_asm #
fn (prefs &Preferences) should_compile_asm(path string) bool
fn (Preferences) should_compile_c #
fn (prefs &Preferences) should_compile_c(file string) bool
Todo: Rework this using is_target_of()
fn (Preferences) should_compile_filtered_files #
fn (prefs &Preferences) should_compile_filtered_files(dir string, files_ []string) []string
fn (Preferences) should_compile_js #
fn (prefs &Preferences) should_compile_js(file string) bool
fn (Preferences) should_compile_native #
fn (prefs &Preferences) should_compile_native(file string) bool
fn (Preferences) should_output_to_stdout #
fn (pref &Preferences) should_output_to_stdout() bool
fn (Preferences) should_trace_fn_name #
fn (pref &Preferences) should_trace_fn_name(fname string) bool
fn (Preferences) vcross_compiler_name #
fn (p &Preferences) vcross_compiler_name() string
fn (Preferences) vcross_linker_name #
fn (p &Preferences) vcross_linker_name() string
fn (Preferences) vrun_elog #
fn (pref &Preferences) vrun_elog(s string)
- Constants
- fn add_line_info_expr_to_program_text
- fn arch_from_string
- fn backend_from_string
- fn cc_from_string
- fn default_tcc_compiler
- fn eprintln_cond
- fn eprintln_exit
- fn get_host_arch
- fn get_host_os
- fn new_preferences
- fn os_from_string
- fn parse_args
- fn parse_args_and_show_errors
- fn supported_test_runners_list
- fn vexe_path
- enum Arch
- enum AssertFailureMode
- enum Backend
- enum BuildMode
- enum ColorOutput
- enum CompilerType
- enum GarbageCollectionMode
- enum OS
- enum OutputMode
- enum Subsystem
- struct LineInfo
- struct Preferences