zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit b0846b6ecbb3e2557c5c95ddee04ecc055881d75 (tree)
parent a237283d90ea6799331a7268f474511f352a23d7
Author: Vincent Rischmann <vincent@rischmann.fr>
Date:   Wed, 19 Aug 2020 23:21:16 +0200

builder: implement integer options

Diffstat:
Mlib/std/build.zig | 28+++++++++++++++++++++++++++-
1 file changed, 27 insertions(+), 1 deletion(-)

diff --git a/lib/std/build.zig b/lib/std/build.zig @@ -449,7 +449,33 @@ pub const Builder = struct { return null; }, }, - .Int => panic("TODO integer options to build script", .{}), + .Int => switch (entry.value.value) { + .Flag => { + warn("Expected -D{} to be an integer, but received a boolean.\n", .{name}); + self.markInvalidUserInput(); + return null; + }, + .Scalar => |s| { + const n = std.fmt.parseInt(T, s, 10) catch |err| switch (err) { + error.Overflow => { + warn("-D{} value {} cannot fit into type {}.\n", .{ name, s, @typeName(T) }); + self.markInvalidUserInput(); + return null; + }, + else => { + warn("Expected -D{} to be an integer of type {}.\n", .{ name, @typeName(T) }); + self.markInvalidUserInput(); + return null; + }, + }; + return n; + }, + .List => { + warn("Expected -D{} to be an integer, but received a list.\n", .{name}); + self.markInvalidUserInput(); + return null; + }, + }, .Float => panic("TODO float options to build script", .{}), .Enum => switch (entry.value.value) { .Flag => {