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

See also: