-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.zig
More file actions
150 lines (140 loc) · 5.47 KB
/
build.zig
File metadata and controls
150 lines (140 loc) · 5.47 KB
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const small_reader_threads = b.option(u32, "small-reader-threads", "Default small reader threads (Makefile default: 4)") orelse 4;
const block_reader_threads = b.option(u32, "block-reader-threads", "Default block reader threads (Makefile default: 4)") orelse 4;
const upstream = b.dependency("squashfs_tools", .{});
const zlib_dep = b.dependency("zlib", .{
.target = target,
.optimize = optimize,
});
const max_reader_threads: u32 = 1024;
// NOTE: squashfs-tools uses various posix features, does not support windows or MacOS (afaict),
// and we've only tested on Linux
var common_flags = std.ArrayList([]const u8).initCapacity(b.allocator, 32) catch @panic("OOM");
common_flags.appendSlice(b.allocator, &.{
"-D_FILE_OFFSET_BITS=64",
"-D_LARGEFILE_SOURCE",
"-D_GNU_SOURCE",
"-DCOMP_DEFAULT=\"gzip\"",
"-DGZIP_SUPPORT",
"-DXATTR_SUPPORT",
"-DXATTR_OS_SUPPORT",
"-DXATTR_DEFAULT",
"-DVERSION=\"4.7.5\"",
"-DDATE=\"2026/03/01\"",
"-DYEAR=\"2026\"",
b.fmt("-DMAX_READER_THREADS={d}", .{max_reader_threads}),
b.fmt("-DSMALL_READER_THREADS={d}", .{small_reader_threads}),
b.fmt("-DBLOCK_READER_THREADS={d}", .{block_reader_threads}),
"-Wall",
"-Wno-unused-result",
}) catch @panic("OOM");
const mksquashfs_sources = [_][]const u8{
"squashfs-tools/mksquashfs.c",
"squashfs-tools/read_fs.c",
"squashfs-tools/action.c",
"squashfs-tools/swap.c",
"squashfs-tools/pseudo.c",
"squashfs-tools/compressor.c",
"squashfs-tools/sort.c",
"squashfs-tools/progressbar.c",
"squashfs-tools/info.c",
"squashfs-tools/restore.c",
"squashfs-tools/process_fragments.c",
"squashfs-tools/caches-queues-lists.c",
"squashfs-tools/reader.c",
"squashfs-tools/tar.c",
"squashfs-tools/date.c",
"squashfs-tools/memory.c",
"squashfs-tools/print_pager.c",
"squashfs-tools/symbolic_mode.c",
"squashfs-tools/thread.c",
"squashfs-tools/nprocessors_compat.c",
"squashfs-tools/limit.c",
"squashfs-tools/virt_disk_pos.c",
"squashfs-tools/gzip_wrapper.c",
"squashfs-tools/xattr.c",
"squashfs-tools/read_xattrs.c",
"squashfs-tools/tar_xattr.c",
"squashfs-tools/pseudo_xattr.c",
"squashfs-tools/xattr_system.c",
};
const unsquashfs_sources = [_][]const u8{
"squashfs-tools/unsquashfs.c",
"squashfs-tools/unsquash-1.c",
"squashfs-tools/unsquash-2.c",
"squashfs-tools/unsquash-3.c",
"squashfs-tools/unsquash-4.c",
"squashfs-tools/unsquash-123.c",
"squashfs-tools/unsquash-34.c",
"squashfs-tools/unsquash-1234.c",
"squashfs-tools/unsquash-12.c",
"squashfs-tools/swap.c",
"squashfs-tools/compressor.c",
"squashfs-tools/unsquashfs_info.c",
"squashfs-tools/date.c",
"squashfs-tools/memory.c",
"squashfs-tools/print_pager.c",
"squashfs-tools/nprocessors_compat.c",
"squashfs-tools/limit.c",
"squashfs-tools/gzip_wrapper.c",
"squashfs-tools/read_xattrs.c",
"squashfs-tools/unsquashfs_xattr.c",
"squashfs-tools/unsquashfs_xattr_system.c",
};
const mksquashfs = b.addExecutable(.{
.name = "mksquashfs",
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
.link_libc = true,
}),
});
mksquashfs.root_module.addCSourceFiles(.{
.root = upstream.path(""),
.files = &mksquashfs_sources,
.flags = common_flags.items,
});
{
var help_flags = common_flags.clone(b.allocator) catch @panic("OOM");
help_flags.append(b.allocator, "-DCOMPRESSORS=\"gzip (default)\"") catch @panic("OOM");
mksquashfs.root_module.addCSourceFile(.{
.file = upstream.path("squashfs-tools/mksquashfs_help.c"),
.flags = help_flags.items,
});
}
mksquashfs.root_module.addIncludePath(upstream.path("squashfs-tools"));
mksquashfs.linkLibrary(zlib_dep.artifact("z"));
// TODO: explore using musl libm and disabling threading?
mksquashfs.linkSystemLibrary("pthread");
mksquashfs.linkSystemLibrary("m");
b.installArtifact(mksquashfs);
const unsquashfs = b.addExecutable(.{
.name = "unsquashfs",
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
.link_libc = true,
}),
});
unsquashfs.root_module.addCSourceFiles(.{
.root = upstream.path(""),
.files = &unsquashfs_sources,
.flags = common_flags.items,
});
{
var help_flags = common_flags.clone(b.allocator) catch @panic("OOM");
help_flags.append(b.allocator, "-DDECOMPRESSORS=\"gzip\"") catch @panic("OOM");
unsquashfs.root_module.addCSourceFile(.{
.file = upstream.path("squashfs-tools/unsquashfs_help.c"),
.flags = help_flags.items,
});
}
unsquashfs.root_module.addIncludePath(upstream.path("squashfs-tools"));
unsquashfs.linkLibrary(zlib_dep.artifact("z"));
unsquashfs.linkSystemLibrary("pthread");
unsquashfs.linkSystemLibrary("m");
b.installArtifact(unsquashfs);
}