|
| 1 | +const std = @import("std"); |
| 2 | + |
| 3 | +pub const Enum = enum { alfa, bravo, charlie }; |
| 4 | + |
| 5 | +pub fn build(b: *std.Build) !void { |
| 6 | + const test_step = b.step("test", "Test passing options to a dependency"); |
| 7 | + b.default_step = test_step; |
| 8 | + |
| 9 | + const none_specified = b.dependency("other", .{}); |
| 10 | + |
| 11 | + const none_specified_mod = none_specified.module("dummy"); |
| 12 | + if (!none_specified_mod.resolved_target.?.query.eql(b.graph.host.query)) return error.TestFailed; |
| 13 | + if (none_specified_mod.optimize.? != .Debug) return error.TestFailed; |
| 14 | + |
| 15 | + const all_specified = b.dependency("other", .{ |
| 16 | + .target = b.resolveTargetQuery(.{ .cpu_arch = .x86_64, .os_tag = .windows, .abi = .gnu }), |
| 17 | + .optimize = @as(std.builtin.OptimizeMode, .ReleaseSafe), |
| 18 | + .bool = @as(bool, true), |
| 19 | + .int = @as(i64, 123), |
| 20 | + .float = @as(f64, 0.5), |
| 21 | + .string = @as([]const u8, "abc"), |
| 22 | + .string_list = @as([]const []const u8, &.{ "a", "b", "c" }), |
| 23 | + .lazy_path = @as(std.Build.LazyPath, .{ .cwd_relative = "abc.txt" }), |
| 24 | + .lazy_path_list = @as([]const std.Build.LazyPath, &.{ |
| 25 | + .{ .cwd_relative = "a.txt" }, |
| 26 | + .{ .cwd_relative = "b.txt" }, |
| 27 | + .{ .cwd_relative = "c.txt" }, |
| 28 | + }), |
| 29 | + .@"enum" = @as(Enum, .alfa), |
| 30 | + //.enum_list = @as([]const Enum, &.{ .alfa, .bravo, .charlie }), |
| 31 | + //.build_id = @as(std.zig.BuildId, .uuid), |
| 32 | + }); |
| 33 | + |
| 34 | + const all_specified_mod = all_specified.module("dummy"); |
| 35 | + if (all_specified_mod.resolved_target.?.result.cpu.arch != .x86_64) return error.TestFailed; |
| 36 | + if (all_specified_mod.resolved_target.?.result.os.tag != .windows) return error.TestFailed; |
| 37 | + if (all_specified_mod.resolved_target.?.result.abi != .gnu) return error.TestFailed; |
| 38 | + if (all_specified_mod.optimize.? != .ReleaseSafe) return error.TestFailed; |
| 39 | + |
| 40 | + // Most supported option types are serialized to a string representation, |
| 41 | + // so alternative representations of the same option value should resolve |
| 42 | + // to the same cached dependency instance. |
| 43 | + const all_specified_alt = b.dependency("other", .{ |
| 44 | + .target = @as(std.Target.Query, .{ .cpu_arch = .x86_64, .os_tag = .windows, .abi = .gnu }), |
| 45 | + .optimize = @as([]const u8, "ReleaseSafe"), |
| 46 | + .bool = .true, |
| 47 | + .int = @as([]const u8, "123"), |
| 48 | + .float = @as(f16, 0.5), |
| 49 | + .string = .abc, |
| 50 | + .string_list = @as([]const []const u8, &.{ "a", "b", "c" }), |
| 51 | + .lazy_path = @as(std.Build.LazyPath, .{ .cwd_relative = "abc.txt" }), |
| 52 | + .lazy_path_list = @as([]const std.Build.LazyPath, &.{ |
| 53 | + .{ .cwd_relative = "a.txt" }, |
| 54 | + .{ .cwd_relative = "b.txt" }, |
| 55 | + .{ .cwd_relative = "c.txt" }, |
| 56 | + }), |
| 57 | + .@"enum" = @as([]const u8, "alfa"), |
| 58 | + //.enum_list = @as([]const Enum, &.{ .alfa, .bravo, .charlie }), |
| 59 | + //.build_id = @as(std.zig.BuildId, .uuid), |
| 60 | + }); |
| 61 | + |
| 62 | + if (all_specified != all_specified_alt) return error.TestFailed; |
| 63 | +} |
0 commit comments