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.
const builtin = @import("builtin");
const separator = if (builtin.os == builtin.Os.windows) '\\' else '/';
Example of what is imported with @import("builtin")
:
usingnamespace @import("std").builtin;
pub const endian = Endian.Little;
pub const output_mode = OutputMode.Obj;
pub const link_mode = LinkMode.Static;
pub const is_test = false;
pub const single_threaded = false;
/// Deprecated: use `std.Target.cpu.arch`
pub const arch = Arch.x86_64;
pub const abi = Abi.musl;
pub const cpu: Cpu = Cpu{
.arch = .x86_64,
.model = &Target.x86.cpu.haswell,
.features = Target.x86.featureSet(&[_]Target.x86.Feature{
.@"64bit",
.@"aes",
.@"avx",
.@"avx2",
.@"bmi",
.@"bmi2",
.@"cmov",
.@"cx16",
.@"cx8",
.@"ermsb",
.@"f16c",
.@"false_deps_lzcnt_tzcnt",
.@"false_deps_popcnt",
.@"fast_scalar_fsqrt",
.@"fast_shld_rotate",
.@"fast_variable_shuffle",
.@"fma",
.@"fsgsbase",
.@"fxsr",
.@"idivq_to_divl",
.@"invpcid",
.@"lzcnt",
.@"macrofusion",
.@"merge_to_threeway_branch",
.@"mmx",
.@"movbe",
.@"nopl",
.@"pclmul",
.@"popcnt",
.@"rdrnd",
.@"sahf",
.@"slow_3ops_lea",
.@"sse",
.@"sse2",
.@"sse3",
.@"sse4_1",
.@"sse4_2",
.@"ssse3",
.@"vzeroupper",
.@"x87",
.@"xsave",
.@"xsaveopt",
}),
};
pub const os = Os{
.tag = .linux,
.version_range = .{ .linux = .{
.range = .{
.min = .{
.major = 5,
.minor = 0,
.patch = 0,
},
.max = .{
.major = 5,
.minor = 0,
.patch = 0,
},
},
.glibc = .{
.major = 2,
.minor = 17,
.patch = 0,
},
}},
};
pub const object_format = ObjectFormat.elf;
pub const mode = Mode.Debug;
pub const link_libc = false;
pub const link_libcpp = false;
pub const have_error_return_tracing = true;
pub const valgrind_support = true;
pub const position_independent_code = false;
pub const strip_debug_info = false;
pub const code_model = CodeModel.default;
See also: