I am reading through the build.zig
in tigerbeetle here
and I see this
// Build options passed with `-D` flags.
const build_options = .{
.target = b.option([]const u8, "target", "The CPU architecture and OS to build for"),
.config = b.option(config.ConfigBase, "config", "Base configuration.") orelse .default,
.config_aof_record = b.option(
bool,
"config-aof-record",
"Enable AOF Recording.",
) orelse false,
.config_aof_recovery = b.option(
bool,
"config-aof-recovery",
"Enable AOF Recovery mode.",
) orelse false,
.config_log_level = b.option(std.log.Level, "config-log-level", "Log level.") orelse .info,
.config_release = b.option([]const u8, "config-release", "Release triple."),
.config_release_client_min = b.option(
[]const u8,
"config-release-client-min",
"Minimum client release triple.",
),
// We run extra checks in "CI-mode" build.
.ci = b.graph.env_map.get("CI") != null,
.emit_llvm_ir = b.option(bool, "emit-llvm-ir", "Emit LLVM IR (.ll file)") orelse false,
// The "tigerbeetle version" command includes the build-time commit hash.
.git_commit = b.option(
[]const u8,
"git-commit",
"The git commit revision of the source code.",
) orelse std.mem.trimRight(u8, b.run(&.{ "git", "rev-parse", "--verify", "HEAD" }), "\n"),
.hash_log_mode = b.option(
config.HashLogMode,
"hash-log-mode",
"Log hashes (used for debugging non-deterministic executions).",
) orelse .none,
.vopr_state_machine = b.option(
VoprStateMachine,
"vopr-state-machine",
"State machine.",
) orelse .accounting,
.vopr_log = b.option(
VoprLog,
"vopr-log",
"Log only state transitions (short) or everything (full).",
) orelse .short,
.tracer_backend = b.option(
config.TracerBackend,
"tracer-backend",
"Which backend to use for tracing.",
) orelse .none,
};
And I am confused about the syntax. Specifically what are the .default
, .none
, .info
, .accounting
etc?
Also I understand one can use .{}
as a shortcut to not specifying the struct name. So for example
const person: Person = .{.name = "joe"}
instead of
const person: Person = Person{.name = "joe"}
But in the case of the code above, it is just:
const build_options = .{...}
There is no where it is stated what the type of build_options
should be. So how does this work?