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

doc: add description for environment-specific files like default.c.v, linux.c.v etc (#7543)

This commit is contained in:
zakuro 2020-12-26 05:41:22 +09:00 committed by GitHub
parent e7ca5dd17a
commit 60086a06ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2908,6 +2908,8 @@ use `v help`, `v help build` and `v help build-c`.
## Conditional compilation
### Compile time if
```v
// Support for multiple conditions in one branch
$if ios || android {
@ -2955,6 +2957,52 @@ Full list of builtin options:
| `gnu`, `hpux`, `haiku`, `qnx` | `cplusplus` | `big_endian` | |
| `solaris`, `linux_or_macos` | | | |
### Environment specific files
If a file has an environment-specific suffix, it will only be compiled for that environment.
- `.js.v` => will be used only by the JS backend. These files can contain JS. code.
- `.c.v` => will be used only by the C backend. These files can contain C. code.
- `.x64.v` => will be used only by V's x64 backend.
- `_nix.c.v` => will be used only on Unix systems (non Windows).
- `_${os}.c.v` => will be used only on the specific `os` system.
For example, `_windows.c.v` will be used only when compiling on Windows, or with `-os windows`.
- `_default.c.v` => will be used only if there is NOT a more specific platform file.
For example, if you have both `file_linux.c.v` and `file_default.c.v`,
and you are compiling for linux, then only `file_linux.c.v` will be used,
and `file_default.c.v` will be ignored.
Here is a more complete example:
main.v:
```v ignore
module main
fn main() { println(message) }
```
main_default.c.v:
```v ignore
module main
const ( message = 'Hello world' )
```
main_linux.c.v:
```v ignore
module main
const ( message = 'Hello linux' )
```
main_windows.c.v:
```v ignore
module main
const ( message = 'Hello windows' )
```
With the example above:
- when you compile for windows, you will get 'Hello windows'
- when you compile for linux, you will get 'Hello linux'
- when you compile for any other platform, you will get the
non specific 'Hello world' message.
## Compile time pseudo variables
V also gives your code access to a set of pseudo string variables,