Skip to content

Commit de85b82

Browse files
committed
update config header to more accurately resolve values from target
1 parent c1e507c commit de85b82

1 file changed

Lines changed: 18 additions & 9 deletions

File tree

build.zig

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,18 @@ pub fn build(b: *std.Build) void {
4444
b.getInstallStep().dependOn(&b.addInstallFileWithDir(upstream.path("expat/AUTHORS"), .prefix, "AUTHORS").step);
4545
b.getInstallStep().dependOn(&b.addInstallFileWithDir(upstream.path("expat/Changes"), .prefix, "changelog").step);
4646

47+
const has_getrandom: bool = switch (target.result.os.tag) {
48+
.linux => if (target.result.isMuslLibC())
49+
true
50+
else if (target.result.isGnuLibC())
51+
target.result.os.version_range.linux.glibc.order(.{ .major = 2, .minor = 25, .patch = 0 }) != .lt
52+
else
53+
unreachable,
54+
.freebsd => target.result.os.isAtLeast(.freebsd, .{ .major = 12, .minor = 0, .patch = 0 }) orelse false,
55+
.netbsd => target.result.os.isAtLeast(.netbsd, .{ .major = 10, .minor = 0, .patch = 0 }) orelse false,
56+
else => false,
57+
};
58+
4759
const config_header = b.addConfigHeader(.{
4860
.style = .{ .cmake = upstream.path("expat/expat_config.h.cmake") },
4961
.include_path = "expat_config.h",
@@ -67,22 +79,19 @@ pub fn build(b: *std.Build) void {
6779
=> true,
6880
else => false,
6981
},
70-
.HAVE_DLFCN_H = true,
82+
.HAVE_DLFCN_H = target.result.os.tag != .windows,
7183
.HAVE_FCNTL_H = true,
72-
.HAVE_GETPAGESIZE = true,
73-
.HAVE_GETRANDOM = switch (target.result.os.tag) {
74-
.linux, .freebsd => true,
75-
else => false,
76-
},
84+
.HAVE_GETPAGESIZE = target.result.os.tag.isBSD(),
85+
.HAVE_GETRANDOM = has_getrandom,
7786
.HAVE_INTTYPES_H = true,
7887
.HAVE_LIBBSD = null,
7988
.HAVE_MEMORY_H = true,
80-
.HAVE_MMAP = true,
89+
.HAVE_MMAP = target.result.os.tag != .windows and target.result.os.tag != .wasi,
8190
.HAVE_STDINT_H = true,
8291
.HAVE_STDLIB_H = true,
8392
.HAVE_STRINGS_H = true,
8493
.HAVE_STRING_H = true,
85-
.HAVE_SYSCALL_GETRANDOM = target.result.os.tag == .linux,
94+
.HAVE_SYSCALL_GETRANDOM = has_getrandom,
8695
.HAVE_SYS_STAT_H = true,
8796
.HAVE_SYS_TYPES_H = true,
8897
.HAVE_UNISTD_H = true,
@@ -94,7 +103,7 @@ pub fn build(b: *std.Build) void {
94103
.PACKAGE_URL = "",
95104
.PACKAGE_VERSION = b.fmt("{}", .{version}),
96105
.STDC_HEADERS = true,
97-
.WORDS_BIGENDIAN = null,
106+
.WORDS_BIGENDIAN = target.result.cpu.arch.endian() == .big,
98107
.XML_ATTR_INFO = attr_info,
99108
.XML_CONTEXT_BYTES = context_bytes,
100109
.XML_DEV_URANDOM = target.result.os.tag != .windows,

0 commit comments

Comments
 (0)