Conditional compilation

  1. // Support for multiple conditions in one branch
  2. $if ios || android {
  3. println('Running on a mobile device!')
  4. }
  5. $if linux && x64 {
  6. println('64-bit Linux.')
  7. }
  8. // Usage as expression
  9. os := $if windows { 'Windows' } $else { 'UNIX' }
  10. println('Using $os')
  11. // $else-$if branches
  12. $if tinyc {
  13. println('tinyc')
  14. } $else $if clang {
  15. println('clang')
  16. } $else $if gcc {
  17. println('gcc')
  18. } $else {
  19. println('different compiler')
  20. }
  21. $if test {
  22. println('testing')
  23. }
  24. // v -cg ...
  25. $if debug {
  26. println('debugging')
  27. }
  28. // v -d option ...
  29. $if option ? {
  30. println('custom option')
  31. }

If you want an if to be evaluated at compile time it must be prefixed with a $ sign. Right now it can be used to detect an OS, compiler, platform or compilation options. $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 withv -d option. Full list of builtin options:

OSCompilersPlatformsOther
windows, linux, macosgcc, tinycamd64, aarch64debug, test, js
mac, darwin, ios,clang, mingwx64, x32glibc, prealloc
android,mach, dragonflymsvclittle_endianno_bounds_checking
gnu, hpux, haiku, qnxcplusplusbig_endian
solaris, linux_or_macos