Compare commits

...

1 Commits

2 changed files with 41 additions and 19 deletions

View File

@@ -784,23 +784,37 @@ pub fn openDirAbsolute(path_: []const u8) !std.fs.Dir {
}
}
pub const MimallocArena = @import("./mimalloc_arena.zig").Arena;
pub fn getRuntimeFeatureFlag(comptime flag: [:0]const u8) bool {
return struct {
pub const TriState = enum(u8) { no, yes, unset };
pub fn getRuntimeFeatureFlagState(comptime flag: [:0]const u8) TriState {
const Flag = struct {
pub var is_enabled = std.atomic.Value(TriState).init(.unset);
const flag_ = flag;
const state = enum(u8) { idk, disabled, enabled };
var is_enabled: std.atomic.Value(state) = std.atomic.Value(state).init(.idk);
pub fn get() bool {
return switch (is_enabled.load(.SeqCst)) {
.enabled => true,
.disabled => false,
.idk => {
const enabled = if (getenvZ(flag_)) |val| strings.eqlComptime(val, "1") or strings.eqlComptime(val, "true") else false;
is_enabled.store(if (enabled) .enabled else .disabled, .SeqCst);
return enabled;
},
pub var once = std.once(get);
pub fn get() void {
const val = getenvZ(flag_) orelse {
is_enabled.store(.unset, .SeqCst);
return;
};
if (strings.eqlComptime(val, "1") or strings.eqlComptime(val, "true")) {
is_enabled.store(.yes, .SeqCst);
} else {
is_enabled.store(.no, .SeqCst);
}
}
}.get();
};
Flag.once.call();
return Flag.is_enabled.load(.SeqCst);
}
/// Returns true if the feature flag is enabled
///
/// If false or unset, returns false
///
/// To check if a feature flag is unset, use `getRuntimeFeatureFlagState` instead.
pub fn getRuntimeFeatureFlag(comptime flag: [:0]const u8) bool {
return getRuntimeFeatureFlagState(flag) == .yes;
}
/// This wrapper exists to avoid the call to sliceTo(0)

View File

@@ -80,12 +80,20 @@ pub const Loader = struct {
return null;
}
pub const CI_ENVS = .{
"CI",
"TDDIUM",
"GITHUB_ACTIONS",
"JENKINS_URL",
"bamboo.buildKey",
};
pub fn isCI(this: *const Loader) bool {
return (this.get("CI") orelse
this.get("TDDIUM") orelse
this.get("GITHUB_ACTIONS") orelse
this.get("JENKINS_URL") orelse
this.get("bamboo.buildKey")) != null;
inline for (CI_ENVS) |env| {
if (this.has(env)) return true;
}
return false;
}
pub fn loadTracy(this: *const Loader) void {