1const std = @import("std");
2
3pub fn build(b: *std.Build) void {
4 const test_step = b.step("test", "Test it");
5 b.default_step = test_step;
6
7 const target = b.resolveTargetQuery(.{
8 .cpu_arch = .x86_64,
9 .os_tag = .windows,
10 .abi = .gnu,
11 });
12
13 {
14 const exe = b.addExecutable(.{
15 .name = "main",
16 .root_module = b.createModule(.{
17 .root_source_file = null,
18 .target = target,
19 .optimize = .debug,
20 .link_libc = true,
21 }),
22 });
23 exe.root_module.addCSourceFile(.{ .file = b.path("main.c") });
24
25 _ = exe.getEmittedBin();
26 test_step.dependOn(&exe.step);
27 }
28
29 {
30 const exe = b.addExecutable(.{
31 .name = "wmain",
32 .root_module = b.createModule(.{
33 .root_source_file = null,
34 .target = target,
35 .optimize = .debug,
36 .link_libc = true,
37 }),
38 });
39 exe.mingw_unicode_entry_point = true;
40 exe.root_module.addCSourceFile(.{ .file = b.path("wmain.c") });
41
42 _ = exe.getEmittedBin();
43 test_step.dependOn(&exe.step);
44 }
45
46 {
47 const exe = b.addExecutable(.{
48 .name = "winmain",
49 .root_module = b.createModule(.{
50 .root_source_file = null,
51 .target = target,
52 .optimize = .debug,
53 .link_libc = true,
54 }),
55 });
56 // Note: `exe.subsystem = .windows;` is not necessary
57 exe.root_module.addCSourceFile(.{ .file = b.path("winmain.c") });
58
59 _ = exe.getEmittedBin();
60 test_step.dependOn(&exe.step);
61 }
62
63 {
64 const exe = b.addExecutable(.{
65 .name = "wwinmain",
66 .root_module = b.createModule(.{
67 .root_source_file = null,
68 .target = target,
69 .optimize = .debug,
70 .link_libc = true,
71 }),
72 });
73 exe.mingw_unicode_entry_point = true;
74 // Note: `exe.subsystem = .windows;` is not necessary
75 exe.root_module.addCSourceFile(.{ .file = b.path("wwinmain.c") });
76
77 _ = exe.getEmittedBin();
78 test_step.dependOn(&exe.step);
79 }
80
81 {
82 const exe = b.addExecutable(.{
83 .name = "zig_main",
84 .root_module = b.createModule(.{
85 .root_source_file = b.path("main.zig"),
86 .target = target,
87 .optimize = .debug,
88 }),
89 });
90
91 _ = exe.getEmittedBin();
92 test_step.dependOn(&exe.step);
93 }
94
95 {
96 const exe = b.addExecutable(.{
97 .name = "zig_main_link_libc",
98 .root_module = b.createModule(.{
99 .root_source_file = b.path("main.zig"),
100 .target = target,
101 .optimize = .debug,
102 .link_libc = true,
103 }),
104 });
105
106 _ = exe.getEmittedBin();
107 test_step.dependOn(&exe.step);
108 }
109
110 {
111 const exe = b.addExecutable(.{
112 .name = "zig_wwinmain",
113 .root_module = b.createModule(.{
114 .root_source_file = b.path("wwinmain.zig"),
115 .target = target,
116 .optimize = .debug,
117 }),
118 });
119 exe.mingw_unicode_entry_point = true;
120 // Note: `exe.subsystem = .windows;` is not necessary
121
122 _ = exe.getEmittedBin();
123 test_step.dependOn(&exe.step);
124 }
125
126 {
127 const exe = b.addExecutable(.{
128 .name = "zig_wwinmain_link_libc",
129 .root_module = b.createModule(.{
130 .root_source_file = b.path("wwinmain.zig"),
131 .target = target,
132 .optimize = .debug,
133 .link_libc = true,
134 }),
135 });
136 exe.mingw_unicode_entry_point = true;
137 // Note: `exe.subsystem = .windows;` is not necessary
138
139 _ = exe.getEmittedBin();
140 test_step.dependOn(&exe.step);
141 }
142
143 const load_dll_exe = b.addExecutable(.{ .name = "load_dll", .root_module = b.createModule(.{
144 .root_source_file = b.path("loaddll.zig"),
145 .target = target,
146 .optimize = .debug,
147 }) });
148
149 {
150 const dll = b.addLibrary(.{
151 .name = "zig_dllmain",
152 .linkage = .dynamic,
153 .root_module = b.createModule(.{
154 .root_source_file = b.path("dllmain.zig"),
155 .target = target,
156 .optimize = .debug,
157 }),
158 });
159
160 const run = b.addRunArtifact(load_dll_exe);
161 run.addArtifactArg(dll);
162 run.expectStdErrEqual("hello from DllMain");
163 run.expectStdOutEqual("");
164 run.expectExitCode(0);
165 run.skip_foreign_checks = true;
166
167 test_step.dependOn(&run.step);
168 }
169
170 {
171 const dll = b.addLibrary(.{
172 .name = "zig_dllmain_link_libc",
173 .linkage = .dynamic,
174 .root_module = b.createModule(.{
175 .root_source_file = b.path("dllmain.zig"),
176 .target = target,
177 .optimize = .debug,
178 .link_libc = true,
179 }),
180 });
181
182 const run = b.addRunArtifact(load_dll_exe);
183 run.addArtifactArg(dll);
184 run.expectStdErrEqual("hello from DllMain");
185 run.expectStdOutEqual("");
186 run.expectExitCode(0);
187 run.skip_foreign_checks = true;
188
189 test_step.dependOn(&run.step);
190 }
191
192 {
193 const dll = b.addLibrary(.{
194 .name = "c_dllmain",
195 .linkage = .dynamic,
196 .root_module = b.createModule(.{
197 .target = target,
198 .optimize = .debug,
199 .link_libc = true,
200 }),
201 });
202 dll.root_module.addCSourceFile(.{ .file = b.path("dllmain.c") });
203
204 const run = b.addRunArtifact(load_dll_exe);
205 run.addArtifactArg(dll);
206 run.expectStdErrEqual("hello from DllMain");
207 run.expectStdOutEqual("");
208 run.expectExitCode(0);
209 run.skip_foreign_checks = true;
210
211 test_step.dependOn(&run.step);
212 }
213}