1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00
v/cmd/v/help/build.txt

178 lines
8.2 KiB
Plaintext
Raw Normal View History

2021-01-13 13:50:35 +03:00
Usage: v [build flags] ['run'] <target.v|target_directory> [run options]
2020-03-13 22:52:49 +03:00
This command compiles the given target, along with their dependencies, into an executable.
2021-01-13 13:50:35 +03:00
Note that these build flags also work with `run` too, but you need to
pass them *before* `run` . The argument directly after `run` is assumed
to be a .v source file or folder containing .v source files.
Everything after that, is assumed to be flags, that V will ignore itself,
but will pass to the executable after it is compiled.
2020-03-13 22:52:49 +03:00
2021-01-13 13:50:35 +03:00
This enables you to do for example: `v -cc gcc -g myfile.v run -param1 abcde`
... which means for V: "compile using gcc, produce debugging information,
then run `./myfile -param1 abcde` and exit with its exit code".
When compiling packages, V ignores files that end in '_test.v'.
When compiling a single main package, V writes the resulting executable to an output file
2020-03-13 22:52:49 +03:00
named after the build target. ('v abc.v' and 'v abc/' both write either 'abc' or 'abc.exe')
2021-01-13 13:50:35 +03:00
The '.exe' suffix is added automatically, when writing a Windows executable.
2020-03-13 22:52:49 +03:00
By default, the executable is stored in the same directory as the compiled source code.
2021-01-13 13:50:35 +03:00
The -o flag forces V to write the resulting executable or object to the d output file or directory,
2020-03-13 22:52:49 +03:00
instead of the default behavior described in the last two paragraphs.
You can put common options inside an environment variable named VFLAGS, so that
you don't have to repeat them.
2021-01-13 13:50:35 +03:00
You can set it like this: `export VFLAGS="-cc clang -g"` on *nix,
2020-03-13 22:52:49 +03:00
`set VFLAGS=-cc msvc` on Windows.
V respects the TMPDIR environment variable, and will put .tmp.c files in TMPDIR/v/ .
If you have not set it, a suitable platform specific folder (like /tmp) will be used.
2021-01-13 13:50:35 +03:00
NB: the build flags are shared with the run command too:
2020-03-13 22:52:49 +03:00
-b <backend>, -backend <backend>
Specify the backend to use while building the executable.
Current list of supported backends:
* `c` (default) - V outputs C source code which is passed to a C compiler to be compiled.
* `js` - V outputs JS source code which can be passed to NodeJS to be ran.
* `js_browser` - V outputs JS source code ready for the browser.
* `js_node` - V outputs JS source code to run with nodejs.
* `js_freestanding` - V outputs JS source code with no hard runtime dependency.
* `native` - V outputs native executable (see -arch x64|arm64 and -os linux|macos) (EXPERIMENTAL).
2020-03-13 22:52:49 +03:00
-d <flag>[=<value>], -define <flag>[=<value>]
Define the provided flag.
2020-03-13 22:52:49 +03:00
If value is not provided, it is assumed to be set to `true`.
`value` should be `1` or `0` to indicate `true` and `false` respectively otherwise.
2021-01-13 13:50:35 +03:00
-g
Compile the executable in debug mode, allowing code to be debugged more easily.
2020-03-13 22:52:49 +03:00
-o <output>, -output <output>
Force V to output the executable in a specific location
(relative to the current working directory if not absolute).
2020-03-13 22:52:49 +03:00
-obf, -obfuscate
Turn on obfuscation for the code being built. Currently only renames symbols.
2020-03-13 22:52:49 +03:00
-path
Specify the order of path V looks up in while searching for imported dependencies,
2020-03-13 22:52:49 +03:00
separated by pipes (`|`). In addition to absolute paths, you can
also use these special strings too:
@vmodules - replaced with the location of the global ~/.vmodules/ folder
2021-01-13 13:50:35 +03:00
(modules installed with `v install` are there). You can change
its location by setting the environment variable VMODULES.
2020-03-13 22:52:49 +03:00
@vlib - replaced with the location of the v's vlib folder.
Using these, you can arrange for very flexible search orders for you project, for example:
-path "/v/my_project_private_modules|@vlib|@vmodules"
By default, -path is just "@vlib|@vmodules" .
-prod
2021-01-13 13:50:35 +03:00
Compile the executable in production mode, where most optimizations are enabled.
Note that most V warnings turn to errors, if you pass -prod, so you will have
to fix them first.
2020-03-13 22:52:49 +03:00
-prof, -profile <file.txt>
Compile the executable with all functions profiled.
The profile results will be stored in `file.txt`.
The format is 4 fields, separated by a space, for each v function:
a) how many times it was called
b) how much *nanoseconds in total* it took
c) an average for each function (i.e. (b) / (a) )
d) the function name
NB: if you want to output the profile info to stdout, use `-profile -`.
2020-06-01 21:15:44 +03:00
-message-limit <limit>
The maximum amount of warnings / errors / notices, that will be accumulated (defaults to 100).
The checker will abort prematurely once this limit has been reached.
Setting this to 0 or a negative value, will disable the limit.
2021-09-28 10:28:04 +03:00
-no-parallel
Do not run the compiler in parallel (currently only the cgen stage has parallelization).
2020-06-01 21:15:44 +03:00
-profile-no-inline
Skip [inline] functions when profiling.
2020-06-01 21:15:44 +03:00
-skip-unused
Skip generating C/JS code for functions, that are provably not used by your project.
This speeds up compilation, and reduces the generated output size.
It is still experimental, due to historical reasons, but please do try it,
and report issues, if compilation breaks with that option for your program.
2020-03-13 22:52:49 +03:00
-stats
Enable more detailed statistics reporting, while compiling test files.
You can use that with `v test` too, for example:
v -stats test vlib/
... will run test_ functions inside all _test.v files inside vlib/ ,
and will report detailed statistics about how much time each test_ function took, how many
2020-03-13 22:52:49 +03:00
assertions were made, how many tests passed/failed and so on.
-translated
Enable features that are discouraged in regular V code but required for translated V code.
2020-03-13 22:52:49 +03:00
2020-06-01 21:15:44 +03:00
-v
Enable verbosity in the V compiler while compiling
2020-03-13 22:52:49 +03:00
-print-v-files
Just print the list of all parsed .v files, then stop processing further.
This is useful for running external processing tools:
./v -print-v-files cmd/v | etags -L -
... will generate a TAGS file, that emacs can then use to jump
to the definition of functions used by v itself. For vim:
./v -print-v-files cmd/v | ctags -L -
... will generate a simillar tags file, that vi compatible editors can use.
NB: an useful, although not entirely accurate regexp based Universal Ctags options file
for V is located in `.ctags.d/v.ctags` . If you use https://ctags.io/ , it will be used
up automatically, or you can specify it explicitly with --options=.ctags.d/v.ctags .
2020-06-01 21:15:44 +03:00
-color, -nocolor
2021-01-13 13:50:35 +03:00
Force the use of ANSI colors for the V error/warning messages, or disable them completely.
By default, the V compiler tries to show its errors/warnings in ANSI color. The heuristic
that it uses to detect whether or not to use ANSI colors may not work in all cases.
These options allow you to override the default detection.
-check
Scans, parses, and checks the files without compiling the program.
2020-07-14 18:45:44 +03:00
-check-syntax
Only scan and parse the files, but then stop. Useful for very quick syntax checks.
2020-07-14 18:45:44 +03:00
-show-timings
Print a summary about how long each compiler stage took, for example:
PARSE: 152ms
CHECK: 62ms
C GEN: 103ms
C tcc: 95ms
2021-01-13 13:50:35 +03:00
Related to -show-timings, is the ability to compile a special instrumented
v compiler with this command:
`v -d time_parsing -d time_checking -d time_cgening -d time_v self`
The instrumented version will print detailed timing stats while processing
each .v file.
2020-11-29 16:11:12 +03:00
-w
Hide all warnings.
2020-10-24 20:29:24 +03:00
-W
2021-01-13 13:50:35 +03:00
Treat *all V warnings* as errors, even in development builds.
-Wfatal-errors
2021-01-13 13:50:35 +03:00
Unconditionally exit with exit(1) after the first error.
Useful for scripts/tooling that calls V.
-Wimpure-v
2021-01-13 13:50:35 +03:00
Warn about using C. or JS. symbols in plain .v files.
These should be moved in .c.v and .js.v .
2021-01-13 13:50:35 +03:00
NB: in the future, this will be turned ON by default,
and will become an error, after vlib modules are cleaned up.
2020-03-13 22:52:49 +03:00
For C-specific build flags, use `v help build-c`.
For JS-specific build flags, use `v help build-js`.
For Native-specific build flags, use `v help build-native`.
2020-03-13 22:52:49 +03:00
See also:
`v help run` for documentation regarding `v run`.