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.

test.zig

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

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

@import(“builtin”)

  1. const std = @import("std");
  2. /// Zig version. When writing code that supports multiple versions of Zig, prefer
  3. /// feature detection (i.e. with `@hasDecl` or `@hasField`) over version checks.
  4. pub const zig_version = std.SemanticVersion.parse("0.9.0-dev.1966+20328e976") catch unreachable;
  5. /// Temporary until self-hosted is feature complete.
  6. pub const zig_is_stage2 = false;
  7. /// Temporary until self-hosted supports the `cpu.arch` value.
  8. pub const stage2_arch: std.Target.Cpu.Arch = .x86_64;
  9. /// Temporary until self-hosted can call `std.Target.x86.featureSetHas` at comptime.
  10. pub const stage2_x86_cx16 = true;
  11. pub const output_mode = std.builtin.OutputMode.Obj;
  12. pub const link_mode = std.builtin.LinkMode.Static;
  13. pub const is_test = false;
  14. pub const single_threaded = false;
  15. pub const abi = std.Target.Abi.gnu;
  16. pub const cpu: std.Target.Cpu = .{
  17. .arch = .x86_64,
  18. .model = &std.Target.x86.cpu.skylake,
  19. .features = std.Target.x86.featureSet(&[_]std.Target.x86.Feature{
  20. .@"64bit",
  21. .adx,
  22. .aes,
  23. .avx,
  24. .avx2,
  25. .bmi,
  26. .bmi2,
  27. .clflushopt,
  28. .cmov,
  29. .cx16,
  30. .cx8,
  31. .ermsb,
  32. .f16c,
  33. .false_deps_popcnt,
  34. .fast_15bytenop,
  35. .fast_gather,
  36. .fast_scalar_fsqrt,
  37. .fast_shld_rotate,
  38. .fast_variable_crosslane_shuffle,
  39. .fast_variable_perlane_shuffle,
  40. .fast_vector_fsqrt,
  41. .fma,
  42. .fsgsbase,
  43. .fxsr,
  44. .idivq_to_divl,
  45. .invpcid,
  46. .lzcnt,
  47. .macrofusion,
  48. .mmx,
  49. .movbe,
  50. .nopl,
  51. .pclmul,
  52. .popcnt,
  53. .prfchw,
  54. .rdrnd,
  55. .rdseed,
  56. .sahf,
  57. .sgx,
  58. .slow_3ops_lea,
  59. .sse,
  60. .sse2,
  61. .sse3,
  62. .sse4_1,
  63. .sse4_2,
  64. .ssse3,
  65. .vzeroupper,
  66. .x87,
  67. .xsave,
  68. .xsavec,
  69. .xsaveopt,
  70. .xsaves,
  71. }),
  72. };
  73. pub const os = std.Target.Os{
  74. .tag = .linux,
  75. .version_range = .{ .linux = .{
  76. .range = .{
  77. .min = .{
  78. .major = 5,
  79. .minor = 10,
  80. .patch = 81,
  81. },
  82. .max = .{
  83. .major = 5,
  84. .minor = 10,
  85. .patch = 81,
  86. },
  87. },
  88. .glibc = .{
  89. .major = 2,
  90. .minor = 33,
  91. .patch = 0,
  92. },
  93. }},
  94. };
  95. pub const target = std.Target{
  96. .cpu = cpu,
  97. .os = os,
  98. .abi = abi,
  99. };
  100. pub const object_format = std.Target.ObjectFormat.elf;
  101. pub const mode = std.builtin.Mode.Debug;
  102. pub const link_libc = false;
  103. pub const link_libcpp = false;
  104. pub const have_error_return_tracing = true;
  105. pub const valgrind_support = true;
  106. pub const position_independent_code = false;
  107. pub const position_independent_executable = false;
  108. pub const strip_debug_info = false;
  109. pub const code_model = std.builtin.CodeModel.default;

See also: