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 == .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.10.1") catch unreachable;
  5. pub const zig_backend = std.builtin.CompilerBackend.stage2_x86_64;
  6. pub const output_mode = std.builtin.OutputMode.Obj;
  7. pub const link_mode = std.builtin.LinkMode.Static;
  8. pub const is_test = false;
  9. pub const single_threaded = false;
  10. pub const abi = std.Target.Abi.gnu;
  11. pub const cpu: std.Target.Cpu = .{
  12. .arch = .x86_64,
  13. .model = &std.Target.x86.cpu.znver2,
  14. .features = std.Target.x86.featureSet(&[_]std.Target.x86.Feature{
  15. .@"64bit",
  16. .adx,
  17. .aes,
  18. .avx,
  19. .avx2,
  20. .bmi,
  21. .bmi2,
  22. .branchfusion,
  23. .clflushopt,
  24. .clwb,
  25. .clzero,
  26. .cmov,
  27. .crc32,
  28. .cx16,
  29. .cx8,
  30. .f16c,
  31. .fast_15bytenop,
  32. .fast_bextr,
  33. .fast_lzcnt,
  34. .fast_movbe,
  35. .fast_scalar_fsqrt,
  36. .fast_scalar_shift_masks,
  37. .fast_variable_perlane_shuffle,
  38. .fast_vector_fsqrt,
  39. .fma,
  40. .fsgsbase,
  41. .fxsr,
  42. .lzcnt,
  43. .mmx,
  44. .movbe,
  45. .mwaitx,
  46. .nopl,
  47. .pclmul,
  48. .popcnt,
  49. .prfchw,
  50. .rdpid,
  51. .rdpru,
  52. .rdrnd,
  53. .rdseed,
  54. .sahf,
  55. .sbb_dep_breaking,
  56. .sha,
  57. .slow_shld,
  58. .sse,
  59. .sse2,
  60. .sse3,
  61. .sse4_1,
  62. .sse4_2,
  63. .sse4a,
  64. .ssse3,
  65. .vzeroupper,
  66. .wbnoinvd,
  67. .x87,
  68. .xsave,
  69. .xsavec,
  70. .xsaveopt,
  71. .xsaves,
  72. }),
  73. };
  74. pub const os = std.Target.Os{
  75. .tag = .linux,
  76. .version_range = .{ .linux = .{
  77. .range = .{
  78. .min = .{
  79. .major = 5,
  80. .minor = 10,
  81. .patch = 0,
  82. },
  83. .max = .{
  84. .major = 5,
  85. .minor = 10,
  86. .patch = 0,
  87. },
  88. },
  89. .glibc = .{
  90. .major = 2,
  91. .minor = 31,
  92. .patch = 0,
  93. },
  94. }},
  95. };
  96. pub const target = std.Target{
  97. .cpu = cpu,
  98. .os = os,
  99. .abi = abi,
  100. .ofmt = object_format,
  101. };
  102. pub const object_format = std.Target.ObjectFormat.elf;
  103. pub const mode = std.builtin.Mode.Debug;
  104. pub const link_libc = false;
  105. pub const link_libcpp = false;
  106. pub const have_error_return_tracing = true;
  107. pub const valgrind_support = true;
  108. pub const sanitize_thread = false;
  109. pub const position_independent_code = false;
  110. pub const position_independent_executable = false;
  111. pub const strip_debug_info = false;
  112. pub const code_model = std.builtin.CodeModel.default;

See also: