v.pref, v.builder: support `-no-std` (skips passing `-std=c99` to the C backend)

pull/11187/head
Delyan Angelov 2021-08-15 11:05:06 +03:00
parent b1186cca3f
commit eef7eea7bc
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
3 changed files with 25 additions and 11 deletions

View File

@ -35,7 +35,7 @@ see also `v help build`.
Supported only on `linux` targets currently.
-bare-builtin-dir <bare-builtin-dir>
Use with `-freestanding`. This specifies the directory to the
Use with `-freestanding`. This specifies the directory to the
implementation of some basic builtin functions. The list is as follows:
bare_print(buf &byte, len u64)
Print len charecters from the buffer pointed to by buf to stdout.
@ -50,7 +50,7 @@ see also `v help build`.
__free(ptr &C.void)
Free the block of memory ptr allocated by malloc.
realloc(old_area &C.void, new_size size_t) &C.void
Allocates a new area of size new_size, copies old_area
Allocates a new area of size new_size, copies old_area
to the new area, and returns a pointer to the new area.
[export: 'calloc']
__calloc(nmemb size_t, size size_t) &C.void
@ -75,20 +75,20 @@ see also `v help build`.
vsnprintf(str &char, size size_t, format &char, ap va_list) int
See `man vsnprintf`.
bare_backtrace() string
Return a backtrace that can be printed. If backtraces are not
Return a backtrace that can be printed. If backtraces are not
supported, return a message stating that backtraces do not work.
[export: 'exit']
__exit(code int)
Exit with code code. code is allowed to be ignored.
The module decleration should be `builtin`. The default Linux
The module decleration should be `builtin`. The default Linux
implementation can be found in `vlib/builtin/linux_bare`.
-os <os>, -target-os <os>
Change the target OS that V tries to compile for.
By default, the target OS is the host system.
When OS is `cross`, V will attempt to output cross-platform C code.
Here is a list of the operating systems, supported by V:
(CI tests runs on every commit/PR for each of these):
`windows`, `linux`, `macos`
@ -137,7 +137,7 @@ see also `v help build`.
and unsafe{free(x)} calls manually in this mode).
Some short lived applications, like compilers and other CLI tools are
more performant without autofree.
-gc <mode>
Use and link an optional garbage collector. Only the BoehmDemersWeiser
garbage collector is supported currently with the following sub-options:
@ -152,12 +152,12 @@ see also `v help build`.
You need to install a `libgc-dev` package first, or install it manually from:
https://github.com/ivmai/bdwgc
Note, `-gc boehm` is complementary to -autofree. The Boehm garbage
collector is conservative, and it may make your program significantly
slower if it does many small allocations in a loop. This option
is intended *mainly* for reducing the memory usage of programs, that
process large amounts of text in *batch mode* on low/limited memory
process large amounts of text in *batch mode* on low/limited memory
environments like small VPSes, and for which a few ms of garbage
collection pauses from time to time *do not matter much*.
@ -237,12 +237,19 @@ see also `v help build`.
you use -no-rsp, V will pass the C compiler options directly to the C
compiler, on the command line, without writing an .rsp file first.
-assert aborts
-no-std
By default, V passes -std=c99 to the C backend, but some compilers do
not support that, even though they may be able to compile the produced
code, or have other options that can be tuned to allow it.
Passing -no-std will remove that flag, and you can then use -cflags ''
to pass the other options for your specific C compiler.
-assert aborts
Call abort() after an assertion failure. Debuggers usually
install signal handlers for SIGABRT, so your program will stop and you
will get a backtrace. If you are running your program outside of a
debugger, you will most likely get a core dump file.
-assert backtraces
Call print_backtrace() after an assertion failure. Note that
backtraces are not implemented yet on all combinations of

View File

@ -186,7 +186,10 @@ fn (mut v Builder) setup_ccompiler_options(ccompiler string) {
mut debug_options := ['-g']
mut optimization_options := ['-O2']
// arguments for the C compiler
ccoptions.args = [v.pref.cflags, '-std=gnu99']
ccoptions.args = [v.pref.cflags]
if !v.pref.no_std {
ccoptions.args << '-std=c99'
}
ccoptions.wargs = [
'-Wall',
'-Wextra',

View File

@ -173,6 +173,7 @@ pub mut:
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=c99 to the C backend
use_color ColorOutput // whether the warnings/errors should use ANSI color escapes.
is_parallel bool
error_limit int
@ -478,6 +479,9 @@ pub fn parse_args(known_external_commands []string, args []string) (&Preferences
'-no-rsp' {
res.no_rsp = true
}
'-no-std' {
res.no_std = true
}
'-keepc' {
res.reuse_tmpc = true
}