Repository navigation
Expand file tree
/
Copy pathbuild.zig
More file actions
146 lines (134 loc) · 6 KB
/
Copy pathbuild.zig
File metadata and controls
146 lines (134 loc) · 6 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
const std = @import("std");
const app_bundle = "MacDirStat.app";
const macos_dir = app_bundle ++ "/Contents/MacOS";
const resources_dir = app_bundle ++ "/Contents/Resources";
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
// ReleaseSafe by default: the scanner does a lot of index arithmetic over a
// hand-managed node array, and the bounds checks cost far less than the
// syscalls they sit between. Spelled out rather than via
// `standardOptimizeOption`, which swaps `-Doptimize` for a `-Drelease`
// boolean as soon as a preferred mode is given.
const optimize = b.option(
std.builtin.OptimizeMode,
"optimize",
"Optimization mode (default: ReleaseSafe)",
) orelse .ReleaseSafe;
const mod = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
});
// Zig ships only libSystem for Darwin; AppKit and friends live in Apple's
// SDK, and it only auto-detects that for the *native* target. Building the
// other macOS architecture — which a universal release needs — therefore
// has to be pointed at the SDK explicitly.
if (target.result.os.tag.isDarwin() and !target.query.isNative()) {
const sdk = std.mem.trim(u8, b.run(&.{ "xcrun", "--show-sdk-path" }), " \r\n");
mod.addSystemFrameworkPath(.{ .cwd_relative = b.pathJoin(&.{ sdk, "System/Library/Frameworks" }) });
mod.addSystemIncludePath(.{ .cwd_relative = b.pathJoin(&.{ sdk, "usr/include" }) });
mod.addLibraryPath(.{ .cwd_relative = b.pathJoin(&.{ sdk, "usr/lib" }) });
}
mod.linkFramework("Foundation", .{});
mod.linkFramework("AppKit", .{});
mod.linkFramework("CoreGraphics", .{});
mod.linkFramework("UniformTypeIdentifiers", .{});
const exe = b.addExecutable(.{
.name = "macdirstat",
.root_module = mod,
});
const install_exe = b.addInstallArtifact(exe, .{
.dest_dir = .{ .override = .{ .custom = macos_dir } },
});
b.getInstallStep().dependOn(&install_exe.step);
// Generated by `macdirstat --make-icon`, then `iconutil -c icns`.
const install_icon = b.addInstallFile(
b.path("resources/MacDirStat.icns"),
resources_dir ++ "/MacDirStat.icns",
);
b.getInstallStep().dependOn(&install_icon.step);
const plist = b.addWriteFiles();
const plist_file = plist.add("Info.plist", info_plist);
const install_plist = b.addInstallFile(plist_file, app_bundle ++ "/Contents/Info.plist");
b.getInstallStep().dependOn(&install_plist.step);
// Ad-hoc sign the finished bundle. Without a stable signature macOS treats
// each rebuild as a different program, so a Full Disk Access grant — which
// this needs to measure ~/Library at all — would have to be given again
// every time.
const sign = b.addSystemCommand(&.{
"codesign", "--force", "--sign", "-",
b.pathJoin(&.{ b.install_prefix, app_bundle }),
});
sign.step.dependOn(&install_exe.step);
sign.step.dependOn(&install_plist.step);
sign.step.dependOn(&install_icon.step);
b.getInstallStep().dependOn(&sign.step);
// The binary must run from inside the bundle so AppKit finds Info.plist and
// the process gets a proper activation policy and TCC identity.
const run = b.addSystemCommand(&.{
b.pathJoin(&.{ b.install_prefix, macos_dir, "macdirstat" }),
});
run.step.dependOn(b.getInstallStep());
if (b.args) |args| run.addArgs(args);
b.step("run", "Build and run MacDirStat.app").dependOn(&run.step);
const test_mod = b.createModule(.{
.root_source_file = b.path("src/test_all.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
});
test_mod.linkFramework("Foundation", .{});
test_mod.linkFramework("AppKit", .{});
test_mod.linkFramework("CoreGraphics", .{});
const unit_tests = b.addTest(.{ .root_module = test_mod });
const run_tests = b.addRunArtifact(unit_tests);
b.step("test", "Run unit tests").dependOn(&run_tests.step);
}
const info_plist =
\\<?xml version="1.0" encoding="UTF-8"?>
\\<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
\\<plist version="1.0">
\\<dict>
\\ <key>CFBundleDevelopmentRegion</key>
\\ <string>en</string>
\\ <key>CFBundleExecutable</key>
\\ <string>macdirstat</string>
\\ <key>CFBundleIconFile</key>
\\ <string>MacDirStat</string>
\\ <key>CFBundleIdentifier</key>
\\ <string>nl.typeguru.macdirstat</string>
\\ <key>CFBundleInfoDictionaryVersion</key>
\\ <string>6.0</string>
\\ <key>CFBundleName</key>
\\ <string>MacDirStat</string>
\\ <key>CFBundleDisplayName</key>
\\ <string>MacDirStat</string>
\\ <key>CFBundlePackageType</key>
\\ <string>APPL</string>
\\ <key>CFBundleShortVersionString</key>
\\ <string>0.1.0</string>
\\ <key>CFBundleVersion</key>
\\ <string>1</string>
\\ <key>NSHumanReadableCopyright</key>
\\ <string>Disk usage as a treemap. After WinDirStat.</string>
\\ <key>LSApplicationCategoryType</key>
\\ <string>public.app-category.utilities</string>
\\ <key>LSMinimumSystemVersion</key>
\\ <string>12.0</string>
\\ <key>NSHighResolutionCapable</key>
\\ <true/>
\\ <key>NSSupportsAutomaticGraphicsSwitching</key>
\\ <true/>
\\ <key>NSDesktopFolderUsageDescription</key>
\\ <string>MacDirStat needs access to measure the size of your Desktop.</string>
\\ <key>NSDocumentsFolderUsageDescription</key>
\\ <string>MacDirStat needs access to measure the size of your Documents.</string>
\\ <key>NSDownloadsFolderUsageDescription</key>
\\ <string>MacDirStat needs access to measure the size of your Downloads.</string>
\\ <key>NSRemovableVolumesUsageDescription</key>
\\ <string>MacDirStat needs access to measure the size of external volumes.</string>
\\</dict>
\\</plist>
\\
;