Skip to content

Commit

Permalink
std.Build: accept comptime string as option value
Browse files Browse the repository at this point in the history
  • Loading branch information
thiago-negri committed Dec 3, 2024
1 parent 6188cb8 commit 7c29c14
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion lib/std/Build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,30 @@ fn userInputOptionsFromArgs(allocator: Allocator, args: anytype) UserInputOption
var user_input_options = UserInputOptionsMap.init(allocator);
inline for (@typeInfo(@TypeOf(args)).@"struct".fields) |field| {
const v = @field(args, field.name);
const T = @TypeOf(v);

const type_info = @typeInfo(@TypeOf(v));
const is_comptime_str = is_comptime_str: switch (type_info) {
.pointer => |pointer| {
if (pointer.size == .One and pointer.is_const) {
const child_type_info = @typeInfo(pointer.child);
switch (child_type_info) {
.array => |array| {
if (array.child == u8) {
if (array.sentinel) |sentinel| {
break :is_comptime_str @as(*const u8, @ptrCast(sentinel)).* == 0;
}
}
},
else => break :is_comptime_str false,
}
}
break :is_comptime_str false;
},
else => break :is_comptime_str false,
};

const T = if (is_comptime_str) []const u8 else @TypeOf(v);

switch (T) {
Target.Query => {
user_input_options.put(field.name, .{
Expand Down

0 comments on commit 7c29c14

Please sign in to comment.