forked from CoderRC/libmingw32_extended
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.zig
132 lines (118 loc) · 3.59 KB
/
build.zig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
const std = @import("std");
pub fn build(b: *std.Build) void {
if (comptime !checkVersion())
@compileError("Please! Update zig toolchain >= 0.11!");
const tests = b.option(bool, "Tests", "Build Tests [default: false]") orelse false;
const target = b.standardTargetOptions(.{
.default_target = .{
.cpu_arch = .x86_64,
.os_tag = .windows,
.abi = .gnu,
},
});
const optimize = b.standardOptimizeOption(.{});
const libposixGW = b.addStaticLibrary(.{
.name = "mingw32_extended",
.target = target,
.optimize = optimize,
});
switch (optimize) {
.Debug, .ReleaseSafe => libposixGW.bundle_compiler_rt = true,
else => libposixGW.strip = true,
}
libposixGW.want_lto = false;
libposixGW.addIncludePath(.{ .path = "include" });
libposixGW.defineCMacro("__USE_MINGW_ANSI_STDIO", "1");
libposixGW.addCSourceFiles(&.{
"source/writev.c",
"source/dlsym.c",
"source/posix_madvise.c",
"source/msync.c",
"source/wait.c",
"source/munlock.c",
"source/munmap.c",
"source/dladdr.c",
"source/dlclose.c",
"source/mlock.c",
"source/mmap.c",
"source/process_vm_readv.c",
"source/pipe.c",
"source/readv.c",
"source/dlopen.c",
"source/process_vm_writev.c",
"source/dlerror.c",
"source/shm_open.c",
"source/madvise.c",
"source/mprotect.c",
"source/getpagesize.c",
"source/shm_unlink.c",
}, &.{
"-Wall",
"-Wextra",
});
const winpthreads_dep = b.dependency("winpthreads", .{
.optimize = optimize,
.target = target,
});
const winpthreads = winpthreads_dep.artifact("winpthreads");
libposixGW.linkLibrary(winpthreads);
libposixGW.installLibraryHeaders(winpthreads);
libposixGW.linkLibC();
libposixGW.installHeadersDirectory("include", "");
b.installArtifact(libposixGW);
if (tests) {
buildExe(b, libposixGW, .{
.name = "test_process_vm_readv",
.file = "tests/test_process_vm_readv.c",
});
buildExe(b, libposixGW, .{
.name = "test_mmap",
.file = "tests/test_mmap.c",
});
}
}
fn buildExe(b: *std.Build, lib: *std.Build.Step.Compile, binfo: BuildInfo) void {
const exe = b.addExecutable(.{
.name = binfo.name,
.target = lib.target,
.optimize = lib.optimize,
});
if (lib.optimize != .Debug)
exe.strip = true;
exe.want_lto = false;
for (lib.include_dirs.items) |include| {
exe.include_dirs.append(include) catch {};
}
exe.linkLibrary(lib);
exe.addCSourceFile(.{
.file = .{ .path = binfo.file },
.flags = &.{
"-Wall",
"-Wextra",
"-Wpedantic",
},
});
exe.linkLibC();
b.installArtifact(exe);
const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
}
const run_step = b.step(binfo.name, b.fmt("Run the {s} app.", .{binfo.name}));
run_step.dependOn(&run_cmd.step);
}
const BuildInfo = struct {
name: []const u8,
file: []const u8,
};
fn checkVersion() bool {
const builtin = @import("builtin");
if (!@hasDecl(builtin, "zig_version")) {
return false;
}
const needed_version = std.SemanticVersion.parse("0.11.0") catch unreachable;
const version = builtin.zig_version;
const order = version.order(needed_version);
return order != .lt;
}