Compile Variables

Compile variables are accessible by importing the "builtin" package, which the compiler makes available to every Zig source file. It contains compile-time constants such as the current target, endianness, and release mode.

  1. const builtin = @import("builtin");
  2. const separator = if (builtin.os == builtin.Os.windows) '\\' else '/';

Example of what is imported with @import("builtin"):

  1. usingnamespace @import("std").builtin;
  2. /// Deprecated
  3. pub const arch = Target.current.cpu.arch;
  4. /// Deprecated
  5. pub const endian = Target.current.cpu.arch.endian();
  6. pub const output_mode = OutputMode.Obj;
  7. pub const link_mode = LinkMode.Static;
  8. pub const is_test = false;
  9. pub const single_threaded = false;
  10. pub const abi = Abi.gnu;
  11. pub const cpu: Cpu = Cpu{
  12. .arch = .x86_64,
  13. .model = &Target.x86.cpu.skylake,
  14. .features = Target.x86.featureSet(&[_]Target.x86.Feature{
  15. .@"64bit",
  16. .@"adx",
  17. .@"aes",
  18. .@"avx",
  19. .@"avx2",
  20. .@"bmi",
  21. .@"bmi2",
  22. .@"clflushopt",
  23. .@"cmov",
  24. .@"cx16",
  25. .@"cx8",
  26. .@"ermsb",
  27. .@"f16c",
  28. .@"false_deps_popcnt",
  29. .@"fast_15bytenop",
  30. .@"fast_gather",
  31. .@"fast_scalar_fsqrt",
  32. .@"fast_shld_rotate",
  33. .@"fast_variable_shuffle",
  34. .@"fast_vector_fsqrt",
  35. .@"fma",
  36. .@"fsgsbase",
  37. .@"fxsr",
  38. .@"idivq_to_divl",
  39. .@"invpcid",
  40. .@"lzcnt",
  41. .@"macrofusion",
  42. .@"merge_to_threeway_branch",
  43. .@"mmx",
  44. .@"movbe",
  45. .@"nopl",
  46. .@"pclmul",
  47. .@"popcnt",
  48. .@"prfchw",
  49. .@"rdrnd",
  50. .@"rdseed",
  51. .@"sahf",
  52. .@"sgx",
  53. .@"slow_3ops_lea",
  54. .@"sse",
  55. .@"sse2",
  56. .@"sse3",
  57. .@"sse4_1",
  58. .@"sse4_2",
  59. .@"ssse3",
  60. .@"vzeroupper",
  61. .@"x87",
  62. .@"xsave",
  63. .@"xsavec",
  64. .@"xsaveopt",
  65. .@"xsaves",
  66. }),
  67. };
  68. pub const os = Os{
  69. .tag = .linux,
  70. .version_range = .{ .linux = .{
  71. .range = .{
  72. .min = .{
  73. .major = 5,
  74. .minor = 4,
  75. .patch = 77,
  76. },
  77. .max = .{
  78. .major = 5,
  79. .minor = 4,
  80. .patch = 77,
  81. },
  82. },
  83. .glibc = .{
  84. .major = 2,
  85. .minor = 31,
  86. .patch = 0,
  87. },
  88. }},
  89. };
  90. pub const object_format = ObjectFormat.elf;
  91. pub const mode = Mode.Debug;
  92. pub const link_libc = false;
  93. pub const link_libcpp = false;
  94. pub const have_error_return_tracing = true;
  95. pub const valgrind_support = true;
  96. pub const position_independent_code = false;
  97. pub const strip_debug_info = false;
  98. pub const code_model = CodeModel.default;

See also: