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.

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

See also: