-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.zig
More file actions
239 lines (216 loc) · 8.78 KB
/
build.zig
File metadata and controls
239 lines (216 loc) · 8.78 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
// ── External dependencies (fetched via build.zig.zon) ──────────────
const zlib_dep = b.dependency("zlib", .{ .target = target, .optimize = optimize });
const libpng_dep = b.dependency("libpng", .{ .target = target, .optimize = optimize });
const freetype_dep = b.dependency("freetype", .{
.target = target,
.optimize = optimize,
.@"enable-libpng" = true,
});
const zlib_lib = zlib_dep.artifact("z");
const libpng_lib = libpng_dep.artifact("png");
const freetype_lib = freetype_dep.artifact("freetype");
// ── msdfgen-core (static) ──────────────────────────────────────────
const msdfgen_core = b.addLibrary(.{
.name = "msdfgen-core",
.linkage = .static,
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
.link_libc = true,
.link_libcpp = true,
}),
});
msdfgen_core.root_module.addIncludePath(b.path("generated"));
msdfgen_core.root_module.addIncludePath(b.path("msdf-atlas-gen/msdfgen"));
msdfgen_core.root_module.addCSourceFiles(.{
.root = b.path("msdf-atlas-gen/msdfgen/core"),
.files = msdfgen_core_sources,
.flags = &cpp11_flags,
});
for (msdfgen_core_defines) |def| msdfgen_core.root_module.addCMacro(def[0], def[1]);
// ── msdfgen-ext (static) ───────────────────────────────────────────
const msdfgen_ext = b.addLibrary(.{
.name = "msdfgen-ext",
.linkage = .static,
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
.link_libc = true,
.link_libcpp = true,
}),
});
msdfgen_ext.root_module.addIncludePath(b.path("generated"));
msdfgen_ext.root_module.addIncludePath(b.path("msdf-atlas-gen/msdfgen"));
msdfgen_ext.root_module.linkLibrary(freetype_lib);
msdfgen_ext.root_module.linkLibrary(libpng_lib);
msdfgen_ext.root_module.linkLibrary(msdfgen_core);
msdfgen_ext.root_module.addCSourceFiles(.{
.root = b.path("msdf-atlas-gen/msdfgen/ext"),
.files = msdfgen_ext_sources,
.flags = &cpp11_flags,
});
for (msdfgen_ext_defines) |def| msdfgen_ext.root_module.addCMacro(def[0], def[1]);
// ── msdf-atlas-gen (static) ────────────────────────────────────────
const msdf_atlas = b.addLibrary(.{
.name = "msdf-atlas-gen",
.linkage = .static,
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
.link_libc = true,
.link_libcpp = true,
}),
});
msdf_atlas.root_module.addIncludePath(b.path("generated"));
msdf_atlas.root_module.addIncludePath(b.path("msdf-atlas-gen"));
msdf_atlas.root_module.addIncludePath(b.path("msdf-atlas-gen/artery-font-format"));
msdf_atlas.root_module.addIncludePath(b.path("msdf-atlas-gen/msdfgen"));
msdf_atlas.root_module.linkLibrary(msdfgen_core);
msdf_atlas.root_module.linkLibrary(msdfgen_ext);
msdf_atlas.root_module.linkLibrary(libpng_lib);
msdf_atlas.root_module.addCSourceFiles(.{
.root = b.path("msdf-atlas-gen/msdf-atlas-gen"),
.files = msdf_atlas_gen_sources,
.flags = &cpp11_flags,
});
for (msdf_atlas_gen_defines) |def| msdf_atlas.root_module.addCMacro(def[0], def[1]);
// ── wrapper shared library (Zig root + C++ bridge) ─────────────────
const wrapper = b.addLibrary(.{
.name = "msdf_atlas_gen",
.linkage = .dynamic,
.root_module = b.createModule(.{
.root_source_file = b.path("wrapper/msdf_wrapper.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
.link_libcpp = true,
}),
});
wrapper.root_module.addIncludePath(b.path("generated"));
wrapper.root_module.addIncludePath(b.path("wrapper"));
wrapper.root_module.addIncludePath(b.path("msdf-atlas-gen"));
wrapper.root_module.addIncludePath(b.path("msdf-atlas-gen/msdfgen"));
wrapper.root_module.linkLibrary(msdf_atlas);
wrapper.root_module.linkLibrary(msdfgen_ext);
wrapper.root_module.linkLibrary(msdfgen_core);
wrapper.root_module.linkLibrary(freetype_lib);
wrapper.root_module.linkLibrary(libpng_lib);
wrapper.root_module.linkLibrary(zlib_lib);
wrapper.root_module.addCSourceFiles(.{
.files = &.{"wrapper/bridge.cpp"},
.flags = &.{ "-std=c++17", "-fno-sanitize=undefined", "-fvisibility=hidden" },
});
// Default install into zig-out/lib/
b.installArtifact(wrapper);
// ── Copy to lib/ directory ─────────────────────────────────────────
const copy_to_lib = b.addInstallArtifact(wrapper, .{
.dest_dir = .{ .override = .{ .custom = "../lib" } },
});
// ── Copy to msdf/libs/{platform}/ ─────────────────────────────
const os_name: []const u8 = switch (target.result.os.tag) {
.macos => "darwin",
.linux => "linux",
.windows => "windows",
else => "unknown",
};
const arch_name: []const u8 = switch (target.result.cpu.arch) {
.aarch64 => "arm64",
.x86_64 => "amd64",
else => "unknown",
};
const embed_dir = b.fmt("../msdf/libs/{s}_{s}", .{ os_name, arch_name });
const copy_to_embed = b.addInstallArtifact(wrapper, .{
.dest_dir = .{ .override = .{ .custom = embed_dir } },
});
// Wire both copies into the default install step
b.getInstallStep().dependOn(©_to_lib.step);
b.getInstallStep().dependOn(©_to_embed.step);
}
// ── Source file lists ──────────────────────────────────────────────────
const msdfgen_core_sources: []const []const u8 = &.{
"contour-combiners.cpp",
"Contour.cpp",
"convergent-curve-ordering.cpp",
"DistanceMapping.cpp",
"edge-coloring.cpp",
"edge-segments.cpp",
"edge-selectors.cpp",
"EdgeHolder.cpp",
"equation-solver.cpp",
"export-svg.cpp",
"msdf-error-correction.cpp",
"MSDFErrorCorrection.cpp",
"msdfgen.cpp",
"Projection.cpp",
"rasterization.cpp",
"render-sdf.cpp",
"save-bmp.cpp",
"save-fl32.cpp",
"save-rgba.cpp",
"save-tiff.cpp",
"Scanline.cpp",
"sdf-error-estimation.cpp",
"shape-description.cpp",
"Shape.cpp",
};
const msdfgen_ext_sources: []const []const u8 = &.{
"import-font.cpp",
"import-svg.cpp",
"resolve-shape-geometry.cpp",
"save-png.cpp",
};
const msdf_atlas_gen_sources: []const []const u8 = &.{
"artery-font-export.cpp",
"bitmap-blit.cpp",
"charset-parser.cpp",
"Charset.cpp",
"csv-export.cpp",
"FontGeometry.cpp",
"glyph-generators.cpp",
"GlyphGeometry.cpp",
"GridAtlasPacker.cpp",
"image-encode.cpp",
"json-export.cpp",
"Padding.cpp",
"RectanglePacker.cpp",
"shadron-preview-generator.cpp",
"size-selectors.cpp",
"TightAtlasPacker.cpp",
"utf8.cpp",
"Workload.cpp",
};
// ── Compile defines ────────────────────────────────────────────────────
const msdfgen_core_defines: []const [2][]const u8 = &.{
.{ "MSDFGEN_USE_CPP11", "1" },
.{ "MSDFGEN_PUBLIC", "" },
};
const msdfgen_ext_defines: []const [2][]const u8 = &.{
.{ "MSDFGEN_USE_CPP11", "1" },
.{ "MSDFGEN_PUBLIC", "" },
.{ "MSDFGEN_EXT_PUBLIC", "" },
.{ "MSDFGEN_EXTENSIONS", "1" },
.{ "MSDFGEN_USE_LIBPNG", "1" },
.{ "MSDFGEN_DISABLE_SVG", "1" },
};
const msdf_atlas_gen_defines: []const [2][]const u8 = &.{
.{ "MSDFGEN_USE_CPP11", "1" },
.{ "MSDFGEN_PUBLIC", "" },
.{ "MSDFGEN_EXT_PUBLIC", "" },
.{ "MSDF_ATLAS_PUBLIC", "" },
.{ "MSDFGEN_EXTENSIONS", "1" },
.{ "MSDFGEN_USE_LIBPNG", "1" },
.{ "MSDFGEN_DISABLE_SVG", "1" },
};
// ── Compiler flags ─────────────────────────────────────────────────────
const cpp11_flags: [2][]const u8 = .{
"-std=c++11",
"-fno-sanitize=undefined",
};
const cpp17_flags: [2][]const u8 = .{
"-std=c++17",
"-fno-sanitize=undefined",
};