@@ -9,28 +9,6 @@ pub fn build(b: *std.Build) !void {
99
1010 const optimize : std.builtin.OptimizeMode = .Debug ;
1111
12- const lib_msvc = b .addStaticLibrary (.{
13- .name = "toargv-msvc" ,
14- .root_source_file = .{ .path = "lib.zig" },
15- .target = b .resolveTargetQuery (.{
16- .abi = .msvc ,
17- }),
18- .optimize = optimize ,
19- });
20- const verify_msvc = b .addExecutable (.{
21- .name = "verify-msvc" ,
22- .target = b .resolveTargetQuery (.{
23- .abi = .msvc ,
24- }),
25- .optimize = optimize ,
26- });
27- verify_msvc .addCSourceFile (.{
28- .file = .{ .path = "verify.c" },
29- .flags = &.{ "-DUNICODE" , "-D_UNICODE" },
30- });
31- verify_msvc .linkLibrary (lib_msvc );
32- verify_msvc .linkLibC ();
33-
3412 const lib_gnu = b .addStaticLibrary (.{
3513 .name = "toargv-gnu" ,
3614 .root_source_file = .{ .path = "lib.zig" },
@@ -71,18 +49,52 @@ pub fn build(b: *std.Build) !void {
7149 };
7250 const fuzz_seed_arg = std .fmt .allocPrint (b .allocator , "{}" , .{fuzz_seed }) catch @panic ("oom" );
7351
74- const run_msvc = b .addRunArtifact (fuzz );
75- run_msvc .setName ("fuzz-msvc" );
76- run_msvc .addArtifactArg (verify_msvc );
77- run_msvc .addArgs (&.{ fuzz_iterations_arg , fuzz_seed_arg });
78- run_msvc .expectExitCode (0 );
79-
8052 const run_gnu = b .addRunArtifact (fuzz );
8153 run_gnu .setName ("fuzz-gnu" );
8254 run_gnu .addArtifactArg (verify_gnu );
8355 run_gnu .addArgs (&.{ fuzz_iterations_arg , fuzz_seed_arg });
8456 run_gnu .expectExitCode (0 );
8557
86- test_step .dependOn (& run_msvc .step );
8758 test_step .dependOn (& run_gnu .step );
59+
60+ // Only target the MSVC ABI if MSVC/Windows SDK is available
61+ const has_msvc = has_msvc : {
62+ const sdk = std .zig .WindowsSdk .find (b .allocator ) catch | err | switch (err ) {
63+ error .OutOfMemory = > @panic ("oom" ),
64+ else = > break :has_msvc false ,
65+ };
66+ defer sdk .free (b .allocator );
67+ break :has_msvc true ;
68+ };
69+ if (has_msvc ) {
70+ const lib_msvc = b .addStaticLibrary (.{
71+ .name = "toargv-msvc" ,
72+ .root_source_file = .{ .path = "lib.zig" },
73+ .target = b .resolveTargetQuery (.{
74+ .abi = .msvc ,
75+ }),
76+ .optimize = optimize ,
77+ });
78+ const verify_msvc = b .addExecutable (.{
79+ .name = "verify-msvc" ,
80+ .target = b .resolveTargetQuery (.{
81+ .abi = .msvc ,
82+ }),
83+ .optimize = optimize ,
84+ });
85+ verify_msvc .addCSourceFile (.{
86+ .file = .{ .path = "verify.c" },
87+ .flags = &.{ "-DUNICODE" , "-D_UNICODE" },
88+ });
89+ verify_msvc .linkLibrary (lib_msvc );
90+ verify_msvc .linkLibC ();
91+
92+ const run_msvc = b .addRunArtifact (fuzz );
93+ run_msvc .setName ("fuzz-msvc" );
94+ run_msvc .addArtifactArg (verify_msvc );
95+ run_msvc .addArgs (&.{ fuzz_iterations_arg , fuzz_seed_arg });
96+ run_msvc .expectExitCode (0 );
97+
98+ test_step .dependOn (& run_msvc .step );
99+ }
88100}
0 commit comments