Skip to content

std.Build: accept comptime string as option value #22135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion lib/std/Build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,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