Skip to content

v.driver #

External linking for the native arm64 backend on macOS.

The built-in Mach-O linker (vlib/v/gen/arm64/linker.v) links one object against libSystem, libobjc and Metal only. That is enough, and fast, for programs that call libc. A program that needs C code (sokol, freetype, stb, Objective-C embedders, .c/.m sources), static archives, other dylibs, frameworks or the Boehm collector is linked the way Go links cgo programs with -linkmode=external:

  1. the generator writes a relocatable Mach-O object (Gen.write_object);
  2. the C side of the program (its #defines, #includes and #inserts) is compiled by the C compiler into one support object, in the same order and with the same #flags the C backend would use;
  3. cc links both objects with the program's libraries, archives and frameworks, and the system linker (ld-prime, or ld64.lld) does the rest: archive member selection, dylib binding, stubs, unwind info and signing.

Constants #

const project_backend_flag = '-v3-internal-project-backend'

project_backend_flag precedes the -b that the launcher adds for the backend of a project's v.mod. Such a backend is the project's default: unlike a -b on the command line, it does not ask for the generated C to be kept next to the output.

fn is_generated_source #

fn is_generated_source(path string) bool

is_generated_source reports whether path is the temporary source that the compiler writes for -e code or standard input. Such a source belongs to no project, so the launcher does not apply the backend of the v.mod in the folder that holds it. Recognizing the name, instead of marking the child command line, keeps the command that a .vvmrc forwards to another compiler version unchanged.

fn run #

fn run(args []string)

run executes the V3 compiler driver with args. run compiles the input selected by args using the requested backend and flags.

fn vtest_build_environment #

fn vtest_build_environment(vroot string, args []string) TestBuildEnvironment

vtest_build_environment resolves the facts and defines of the compilation that the compiler options args describe (-os, -arch, -cc, -prod, -race, -d, ...), the way run resolves them for v <args> file_test.v. A test runner started with those options exports the result through pref.set_build_flags_and_defines, so that its // vtest build: decisions match the compiler's own.

struct TestBuildEnvironment #

struct TestBuildEnvironment {
pub:
	facts   []string
	defines []string
}

TestBuildEnvironment is what a // vtest build: expression is evaluated against: the facts of a compilation (its OS, architecture, C compiler kind, prod, the CI job) and the defines it sets.