Skip to content

v.pref #

Constants #

const (
	default_module_path = os.vmodules_dir()

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(cc_str 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 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 vexe_path #

fn vexe_path() string

enum Arch #

enum Arch {
	amd64 // aka x86_64
	arm64 // 64-bit arm
	arm32 // 32-bit arm
	rv64 // 64-bit risc-v
	rv32 // 32-bit risc-v

enum AssertFailureMode #

enum AssertFailureMode {

enum Backend #

enum Backend {
	c // The (default) C backend
	js_node // The JavaScript NodeJS backend
	js_browser // The JavaScript browser backend
	js_freestanding // The JavaScript freestanding backend
	native // The Native backend
	interpret // Interpret the ast

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)

enum ColorOutput #

enum ColorOutput {

enum CompilerType #

enum CompilerType {

enum GarbageCollectionMode #

enum GarbageCollectionMode {
	boehm_full // full garbage collection mode
	boehm_incr // incremental garbage colletion mode
	boehm_full_opt // full garbage collection mode
	boehm_incr_opt // incremental garbage colletion mode
	boehm_leak // leak detection mode (makes `gc_check_leaks()` work)

enum OS #

enum OS {
	_auto // Reserved so .macos cannot be misunderstood as auto

fn (OS) str #

fn (o OS) str() string

enum OutputMode #

enum OutputMode {

struct Preferences #

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
	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_run            bool
	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_test.v` will produce more detailed statistics for the tests that were run
	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_cstrict        bool     // turn on more C warnings; slightly slower
	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
	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
	obfuscate         bool     // `v -obf program.v`, renames functions to "f_XXX"
// 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
	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.
	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.
// TODO Convert this into a []string
	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'.
	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
	third_party_option string
	building_v         bool
	autofree           bool // `v -manualfree` => false, `v -autofree` => true; false by default for now.
// Disabling `free()` insertion results in better performance in some applications (e.g. compilers)
	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
	lookup_path      []string
	output_cross_c   bool // true, when the user passed `-os cross`
	output_es5       bool
	prealloc         bool
	vroot            string
	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
	run_only []string // VTEST_ONLY_FN and -run-only accept comma separated glob patterns.
// 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']
	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.
	skip_running     bool     // when true, do no try to run the produced file (set by, when -o x.c or -o x.js)
	skip_warnings    bool     // like C's "-w", forces warnings to be ignored.
	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
	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
	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
	show_timings      bool // show how much time each compiler stage took
	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 successfull 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 = .no_gc // .no_gc, .boehm, .boehm_leak, ...
	assert_failure_mode AssertFailureMode     // whether to call abort() or print_backtrace() after an assertion failure
	message_limit       int = 100 // 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
// 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.

fn (Preferences) default_c_compiler #

fn (mut p Preferences) default_c_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

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) vcross_compiler_name #

fn (p &Preferences) vcross_compiler_name() string

fn (Preferences) vrun_elog #

fn (pref &Preferences) vrun_elog(s string)