v: support `$if prod` (#9228)
parent
99abd46ac9
commit
791dec7b01
14
doc/docs.md
14
doc/docs.md
|
@ -3516,6 +3516,10 @@ $if test {
|
||||||
$if debug {
|
$if debug {
|
||||||
println('debugging')
|
println('debugging')
|
||||||
}
|
}
|
||||||
|
// v -prod ...
|
||||||
|
$if prod {
|
||||||
|
println('production build')
|
||||||
|
}
|
||||||
// v -d option ...
|
// v -d option ...
|
||||||
$if option ? {
|
$if option ? {
|
||||||
println('custom option')
|
println('custom option')
|
||||||
|
@ -3527,11 +3531,11 @@ Right now it can be used to detect an OS, compiler, platform or compilation opti
|
||||||
`$if debug` is a special option like `$if windows` or `$if x32`.
|
`$if debug` is a special option like `$if windows` or `$if x32`.
|
||||||
If you're using a custom ifdef, then you do need `$if option ? {}` and compile with`v -d option`.
|
If you're using a custom ifdef, then you do need `$if option ? {}` and compile with`v -d option`.
|
||||||
Full list of builtin options:
|
Full list of builtin options:
|
||||||
| OS | Compilers | Platforms | Other |
|
| OS | Compilers | Platforms | Other |
|
||||||
| --- | --- | --- | --- |
|
| --- | --- | --- | --- |
|
||||||
| `windows`, `linux`, `macos` | `gcc`, `tinyc` | `amd64`, `aarch64` | `debug`, `test`, `js` |
|
| `windows`, `linux`, `macos` | `gcc`, `tinyc` | `amd64`, `aarch64` | `debug`, `prod`, `test` |
|
||||||
| `mac`, `darwin`, `ios`, | `clang`, `mingw` | `x64`, `x32` | `glibc`, `prealloc` |
|
| `mac`, `darwin`, `ios`, | `clang`, `mingw` | `x64`, `x32` | `js`, `glibc`, `prealloc` |
|
||||||
| `android`,`mach`, `dragonfly` | `msvc` | `little_endian` | `no_bounds_checking` |
|
| `android`,`mach`, `dragonfly` | `msvc` | `little_endian` | `no_bounds_checking` |
|
||||||
| `gnu`, `hpux`, `haiku`, `qnx` | `cplusplus` | `big_endian` | |
|
| `gnu`, `hpux`, `haiku`, `qnx` | `cplusplus` | `big_endian` | |
|
||||||
| `solaris`, `linux_or_macos` | | | |
|
| `solaris`, `linux_or_macos` | | | |
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ const (
|
||||||
]
|
]
|
||||||
valid_comp_if_compilers = ['gcc', 'tinyc', 'clang', 'mingw', 'msvc', 'cplusplus']
|
valid_comp_if_compilers = ['gcc', 'tinyc', 'clang', 'mingw', 'msvc', 'cplusplus']
|
||||||
valid_comp_if_platforms = ['amd64', 'aarch64', 'x64', 'x32', 'little_endian', 'big_endian']
|
valid_comp_if_platforms = ['amd64', 'aarch64', 'x64', 'x32', 'little_endian', 'big_endian']
|
||||||
valid_comp_if_other = ['js', 'debug', 'test', 'glibc', 'prealloc', 'no_bounds_checking']
|
valid_comp_if_other = ['js', 'debug', 'prod', 'test', 'glibc', 'prealloc', 'no_bounds_checking']
|
||||||
array_builtin_methods = ['filter', 'clone', 'repeat', 'reverse', 'map', 'slice', 'sort',
|
array_builtin_methods = ['filter', 'clone', 'repeat', 'reverse', 'map', 'slice', 'sort',
|
||||||
'contains', 'index', 'wait']
|
'contains', 'index', 'wait']
|
||||||
)
|
)
|
||||||
|
@ -5150,6 +5150,7 @@ fn (mut c Checker) comp_if_branch(cond ast.Expr, pos token.Position) bool {
|
||||||
match cond.name {
|
match cond.name {
|
||||||
'js' { return c.pref.backend != .js }
|
'js' { return c.pref.backend != .js }
|
||||||
'debug' { return !c.pref.is_debug }
|
'debug' { return !c.pref.is_debug }
|
||||||
|
'prod' { return !c.pref.is_prod }
|
||||||
'test' { return !c.pref.is_test }
|
'test' { return !c.pref.is_test }
|
||||||
'glibc' { return false } // TODO
|
'glibc' { return false } // TODO
|
||||||
'prealloc' { return !c.pref.prealloc }
|
'prealloc' { return !c.pref.prealloc }
|
||||||
|
|
|
@ -423,6 +423,9 @@ pub fn (mut g Gen) init() {
|
||||||
if g.pref.is_debug || 'debug' in g.pref.compile_defines {
|
if g.pref.is_debug || 'debug' in g.pref.compile_defines {
|
||||||
g.comptime_defines.writeln('#define _VDEBUG (1)')
|
g.comptime_defines.writeln('#define _VDEBUG (1)')
|
||||||
}
|
}
|
||||||
|
if g.pref.is_prod || 'prod' in g.pref.compile_defines {
|
||||||
|
g.comptime_defines.writeln('#define _VPROD (1)')
|
||||||
|
}
|
||||||
if g.pref.is_test || 'test' in g.pref.compile_defines {
|
if g.pref.is_test || 'test' in g.pref.compile_defines {
|
||||||
g.comptime_defines.writeln('#define _VTEST (1)')
|
g.comptime_defines.writeln('#define _VTEST (1)')
|
||||||
}
|
}
|
||||||
|
|
|
@ -498,6 +498,9 @@ fn (mut g Gen) comp_if_to_ifdef(name string, is_comptime_optional bool) ?string
|
||||||
'debug' {
|
'debug' {
|
||||||
return '_VDEBUG'
|
return '_VDEBUG'
|
||||||
}
|
}
|
||||||
|
'prod' {
|
||||||
|
return '_VPROD'
|
||||||
|
}
|
||||||
'test' {
|
'test' {
|
||||||
return '_VTEST'
|
return '_VTEST'
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,4 +17,11 @@ fn get_st() MyStruct {
|
||||||
fn main() {
|
fn main() {
|
||||||
s := get_st()
|
s := get_st()
|
||||||
println(s)
|
println(s)
|
||||||
|
$if prod {
|
||||||
|
println('prod mode is on')
|
||||||
|
assert true
|
||||||
|
} $else {
|
||||||
|
println('prod mode is off')
|
||||||
|
assert false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
MyStruct{
|
MyStruct{
|
||||||
s: '6'
|
s: '6'
|
||||||
}
|
}
|
||||||
|
prod mode is on
|
||||||
|
|
Loading…
Reference in New Issue