Skip to content

v.builder

fn bounded_v3_fallback_source #

fn bounded_v3_fallback_source(kind string, c_output string, c_file string, allowed_v_sources map[string]string) (string, string, int)

bounded_v3_fallback_source extracts the bounded V source snippet to upload for a V3->V1 fallback, reading ONLY files the caller already trusts — it must be invoked by the process that staged the report, never by one that merely inherited a report path from the environment. c_file is the staged generated C for a generated-C compilation error. Internal compiler errors deliberately return no source here: their input must be snapshotted before V3 starts and passed to bounded_v3_internal_fallback_source, so a later editor/build-watcher rewrite cannot be uploaded as if V3 had parsed it. allowed_v_sources maps every source file V3 actually parsed to the SHA-256 digest captured from those exact parser bytes. Generated-C mappings outside that set, or files whose current contents no longer match the captured digest, contribute no source. The returned source is the full mapped file plus the 1-based failing line to focus on; the byte bound is applied once, at the handoff, centered on that line, so it is never dropped by a second truncation. ('', '', 0) means no source is available, so the report stays metadata-only.

fn bounded_v3_internal_fallback_source #

fn bounded_v3_internal_fallback_source(source_name string, source string) (string, string, int)

bounded_v3_internal_fallback_source returns the source CONTENT captured before V3 starts, with focus 0. It never opens source_name; the dispatcher separately verifies that the input still has the captured digest before forwarding this content to the stable retry. The snapshot is bounded here so a successful V3 compile does not retain an unbounded source copy until exit; export may tighten the bound further to fit the process environment.

fn compile #

fn compile(command string, pref_ &pref.Preferences, backend_cb FnBackend)

fn compile_with_external_c_error_report #

fn compile_with_external_c_error_report(command string, pref_ &pref.Preferences, backend_cb FnBackend, report ExternalCErrorBugReport)

compile_with_external_c_error_report compiles with the established compiler and submits report only after that build succeeds.

fn export_external_v3_report_to_env #

fn export_external_v3_report_to_env(report ExternalCErrorBugReport)

fn module_path #

fn module_path(mod string) string

fn new_builder #

fn new_builder(pref_ &pref.Preferences) Builder

fn should_find_windows_host_c_compiler #

fn should_find_windows_host_c_compiler(pref_ &pref.Preferences) bool

should_find_windows_host_c_compiler reports whether Windows host compiler probing is needed.

fn submit_external_c_error_bug_report #

fn submit_external_c_error_bug_report(prefs &pref.Preferences, ccompiler string, c_output string, c_file string, tag string)

submit_external_c_error_bug_report submits C diagnostics and generated source produced by another compiler implementation after the established compiler has confirmed the build.

fn submit_external_v3_compiler_error_bug_report #

fn submit_external_v3_compiler_error_bug_report(prefs &pref.Preferences, v3_stage string, v3_output string, v_file string, tag string)

submit_external_v3_compiler_error_bug_report reports metadata for a V3 internal compiler error after the stable compiler has confirmed the program is buildable. Source may only be supplied through the pre-V3 snapshot/content path, so this legacy path form deliberately does not reopen v_file after the failure.

fn take_external_v3_report_from_env #

fn take_external_v3_report_from_env() ?ExternalCErrorBugReport

take_external_v3_report_from_env returns the content-only fallback report exported by export_external_v3_report_to_env, or none when none is present. It clears the variables unconditionally so neither a nested build nor a stale/poisoned environment can leak them into later work. The returned report carries source_inline = true and no c_file or cleanup_dir, so consume_external_c_error_bug_report reads no source path and deletes no directory. Tagged dependency paths are separately constrained and hashed after a successful build. Pass the result to compile_with_external_c_error_report so the notice and submission happen relative to the tool's own build outcome (only on success).

fn verror #

fn verror(s string)

fn CC.from #

fn CC.from[W](input W) !CC

fn SourceKind.from #

fn SourceKind.from[W](input W) !SourceKind

fn TccMacosLibgcArgList.from #

fn TccMacosLibgcArgList.from[W](input W) !TccMacosLibgcArgList

fn V3FallbackInputStatus.from #

fn V3FallbackInputStatus.from[W](input W) !V3FallbackInputStatus

type FnBackend #

type FnBackend = fn (mut b Builder)

enum CC #

enum CC {
	tcc
	gcc
	icc
	msvc
	clang
	emcc
	unknown
}

struct Builder #

struct Builder {
pub:
	compiled_dir string // contains os.real_path() of the dir of the final file being compiled, or the dir itself when doing `v .`
	module_path  string
pub mut:
	checker             &checker.Checker         = unsafe { nil }
	transformer         &transformer.Transformer = unsafe { nil }
	comptime            &comptime.Comptime       = unsafe { nil }
	generics            &generics.Generics       = unsafe { nil }
	out_name_c          string
	out_name_js         string
	stats_lines         int // size of backend generated source code in lines
	stats_bytes         int // size of backend generated source code in bytes
	nr_errors           int // accumulated error count of scanner, parser, checker, and builder
	nr_warnings         int // accumulated warning count of scanner, parser, checker, and builder
	nr_notices          int // accumulated notice count of scanner, parser, checker, and builder
	pref                &pref.Preferences = unsafe { nil }
	module_search_paths []string
	parsed_files        []&ast.File
	//$if windows {
	cached_msvc MsvcResult
	//}
	table     &ast.Table = unsafe { nil }
	ccoptions CcompilerOptions
	// Note: changes in mod `builtin` force invalidation of every other .v file
	mod_invalidates_paths    map[string][]string // changes in mod `os`, invalidate only .v files, that do `import os`
	mod_invalidates_mods     map[string][]string // changes in mod `os`, force invalidation of mods, that do `import os`
	path_invalidates_mods    map[string][]string // changes in a .v file from `os`, invalidates `os`
	crun_cache_keys          []string            // target executable + top level source files; filled in by Builder.should_rebuild
	executable_exists        bool                // if the executable already exists, don't remove new executable after `v run`
	str_args                 string              // for parallel_cc mode only, to know which cc args to use (like -I etc)
	last_cc_cmd              string              // the most recently executed C compiler command; reused to regenerate a #line annotated report
	disable_flto             bool
	thirdparty_header_mtimes map[string]i64
}

fn (Builder) cc #

fn (mut v Builder) cc()

fn (Builder) dump_c_options #

fn (b &Builder) dump_c_options(all_args []string)

fn (Builder) dump_defines #

fn (b &Builder) dump_defines()

fn (Builder) dump_files #

fn (b &Builder) dump_files(files []string)

fn (Builder) dump_modules #

fn (b &Builder) dump_modules(mods []string)

fn (Builder) error_with_pos #

fn (b &Builder) error_with_pos(s string, fpath string, pos token.Pos) errors.Error

fn (Builder) find_invalidated_modules_by_files #

fn (mut b Builder) find_invalidated_modules_by_files(all_files []string) []string

fn (Builder) find_module_path #

fn (b &Builder) find_module_path(mod string, fpath string) !string

Todo: try to merge this & util.module functions to create areliable multi use function. see comments in util/module.v

fn (Builder) front_and_middle_stages #

fn (mut b Builder) front_and_middle_stages(v_files []string) !

fn (Builder) front_stages #

fn (mut b Builder) front_stages(v_files []string) !

fn (Builder) get_builtin_files #

fn (v Builder) get_builtin_files() []string

fn (Builder) get_compile_args #

fn (v &Builder) get_compile_args() []string

fn (Builder) get_linker_args #

fn (v &Builder) get_linker_args() []string

fn (Builder) get_user_files #

fn (v &Builder) get_user_files() []string

fn (Builder) get_vtmp_filename #

fn (mut b Builder) get_vtmp_filename(base_file_name string, postfix string) string

fn (Builder) has_pkgconfig_pthread #

fn (v &Builder) has_pkgconfig_pthread() bool

fn (Builder) import_graph #

fn (b &Builder) import_graph() &depgraph.DepGraph

graph of all imported modules

fn (Builder) info #

fn (b &Builder) info(s string)

fn (Builder) interpret_text #

fn (mut b Builder) interpret_text(code string, v_files []string) !

fn (Builder) log #

fn (b &Builder) log(s string)

fn (Builder) middle_stages #

fn (mut b Builder) middle_stages() !

fn (Builder) parse_imports #

fn (mut b Builder) parse_imports()

parse all deps from already parsed files

fn (Builder) print_warnings_and_errors #

fn (mut b Builder) print_warnings_and_errors()

fn (Builder) quote_compiler_name #

fn (mut v Builder) quote_compiler_name(name string) string

fn (Builder) rebuild #

fn (mut b Builder) rebuild(backend_cb FnBackend)

fn (Builder) rebuild_modules #

fn (mut b Builder) rebuild_modules()

fn (Builder) resolve_deps #

fn (mut b Builder) resolve_deps()

fn (Builder) set_module_lookup_paths #

fn (mut v Builder) set_module_lookup_paths()

'strings' => 'VROOT/vlib/strings' 'installed_mod' => '~/.vmodules/installed_mod' 'local_mod' => '/path/to/current/dir/local_mod'

fn (Builder) should_rebuild #

fn (mut b Builder) should_rebuild() bool

fn (Builder) show_parsed_files #

fn (mut b Builder) show_parsed_files()

fn (Builder) show_total_warns_and_errors_stats #

fn (b &Builder) show_total_warns_and_errors_stats()

fn (Builder) tcc_quoted_path #

fn (mut v Builder) tcc_quoted_path(p string) string

fn (Builder) v_files_from_dir #

fn (b &Builder) v_files_from_dir(dir string) []string

struct CcompilerOptions #

struct CcompilerOptions {
mut:
	pkgconfig_pthread bool // exact `-pthread` supplied by an ordered pkg-config linker segment
pub mut:
	guessed_compiler string
	shared_postfix   string // .so, .dll

	debug_mode bool
	cc         CC

	env_cflags  string // prepended *before* everything else
	env_ldflags string // appended *after* everything else

	args         []string // ordinary C options like `-O2`
	wargs        []string // for `-Wxyz` *exclusively*
	pre_args     []string // options that should go before .o_args
	o_args       []string // for `-o target`
	source_args  []string // for `x.tmp.c`
	post_args    []string // options that should go after .o_args
	linker_flags []string // `-lm`
	ldflags      []string // `-labcd' from `v -ldflags "-labcd"`
}

struct ExternalCErrorBugReport #

struct ExternalCErrorBugReport {
pub:
	kind        string
	ccompiler   string
	c_output    string
	c_file      string
	tag         string
	cleanup_dir string
	// The fields below carry a report to an external builder as self-contained CONTENT
	// (see export_external_v3_report_to_env), instead of as a filesystem path to read or
	// a directory to delete — both of which would be forgeable by an inherited or hostile
	// environment. When source_inline is set, v_file/v_source are used verbatim and no
	// path from the report is ever read or removed.
	v_file   string // informational base filename of the failing source (no directory)
	v_source string // the full failing file, or an already bounded internal-error snapshot
	// v_source_focus is the 1-based failing line within v_source (0 for none). export applies or
	// tightens the byte bound centered on it, so a generated-C failure keeps the exact failing code.
	v_source_focus int
	// v_source_truncated records, explicitly, whether v_source is already a bounded excerpt.
	// Export preserves it and also sets it when tightening the byte bound; it rides through the
	// environment so the retry states truncation accurately without sniffing source content.
	v_source_truncated bool
	source_inline      bool // true: use v_file/v_source as-is and touch no filesystem path
	// Untagged path/digest pairs below describe source bytes V3 actually parsed. The
	// stable parser compares them only with its own parsed-file paths and scanner
	// digests. Tagged native inputs describe resolved #include/#insert dependencies;
	// after a successful build the stable compiler reopens those regular files only to
	// verify their SHA-256 digests before it can submit the fallback report.
	input_digests          map[string]string
	input_digests_complete bool
}

ExternalCErrorBugReport describes a failure produced by another compiler implementation and confirmed by a successful build with the established compiler. kind is empty for a generated-C compilation error (the default), identifies an internal V3 failure, or marks a notice-only fallback; for internal failures c_file is the input V source and c_output is a short description.