-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathbuild.zig
More file actions
214 lines (190 loc) · 6.85 KB
/
Copy pathbuild.zig
File metadata and controls
214 lines (190 loc) · 6.85 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
const std = @import("std");
// mirror changes here with bindings.js
fn outputPath(target: std.Build.ResolvedTarget) []const u8 {
const os = target.result.os.tag;
const arch = target.result.cpu.arch;
const abi = target.result.abi;
switch (os) {
.macos => switch (arch) {
.aarch64 => return "../npm/darwin-arm64/canvas.node",
.x86_64 => return "../npm/darwin-x64/canvas.node",
else => {},
},
.linux => switch (arch) {
.arm => switch (abi) {
.gnueabihf => return "../npm/linux-arm-gnueabihf/canvas.node",
else => {},
},
.x86 => switch (abi) {
.gnu => return "../npm/linux-x86-gnu/canvas.node",
.musl => return "../npm/linux-x86-musl/canvas.node",
else => {},
},
.aarch64 => switch (abi) {
.gnu => return "../npm/linux-arm64-gnu/canvas.node",
.musl => return "../npm/linux-arm64-musl/canvas.node",
else => {},
},
.riscv64 => switch (abi) {
.gnu => return "../npm/linux-riscv64-gnu/canvas.node",
else => {},
},
.x86_64 => switch (abi) {
.gnu => return "../npm/linux-x64-gnu/canvas.node",
.musl => return "../npm/linux-x64-musl/canvas.node",
else => {},
},
else => {},
},
.windows => switch (arch) {
.aarch64 => return "../npm/win32-arm64/canvas.node",
.x86_64 => return "../npm/win32-x64/canvas.node",
.x86 => return "../npm/win32-x86/canvas.node",
else => {},
},
else => {},
}
return "../bin/canvas.node";
}
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const cairo = b.dependency("cairo", .{
.target = target,
.optimize = optimize,
}).artifact("cairo");
const libjpeg_turbo = b.dependency("libjpeg_turbo", .{
.target = target,
.optimize = optimize,
.pie = true,
}).artifact("libjpeg_turbo");
const giflib = b.dependency("giflib", .{
.target = target,
.optimize = optimize,
}).artifact("giflib");
const libpng = b.dependency("libpng", .{
.target = target,
.optimize = optimize,
}).artifact("png");
const sheenbidi = b.dependency("sheenbidi", .{
.target = target,
.optimize = optimize,
}).artifact("sheenbidi");
const zg = b.dependency("zg", .{
.target = target,
.optimize = optimize,
});
const harfbuzz = b.dependency("harfbuzz", .{
.target = target,
.optimize = optimize,
}).artifact("harfbuzz");
const lunasvg = b.dependency("lunasvg", .{
.target = target,
.optimize = optimize,
}).artifact("lunasvg");
const unicode = b.addLibrary(.{
.name = "unicode",
.linkage = .static,
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
.root_source_file = b.path("src/unicode.zig"),
.link_libc = true,
.pic = true,
})
});
unicode.root_module.addImport("Scripts", zg.module("Scripts"));
unicode.root_module.addImport("Graphemes", zg.module("Graphemes"));
const canvas = b.addLibrary(.{
.name = "canvas",
.linkage = .dynamic,
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
.pic = true,
.link_libc = true,
.link_libcpp = true,
})
});
const node_api = b.dependency("node_api", .{
.target = target,
.optimize = optimize,
}).artifact("node_api");
canvas.root_module.addCSourceFiles(.{
.files = &.{
"src/bmp/BMPParser.cc",
"src/Canvas.cc",
"src/CanvasGradient.cc",
"src/CanvasPattern.cc",
"src/CanvasRenderingContext2d.cc",
"src/closure.cc",
"src/color.cc",
"src/Image.cc",
"src/ImageData.cc",
"src/init.cc",
"src/itemize.cc",
"src/FontManager.cc",
switch (target.result.os.tag) {
.windows => "src/FontManagerWindows.cc",
.macos => "src/FontManagerMacos.cc",
else => "src/FontManagerLinux.cc",
},
"src/FontFace.cc",
"src/FontFaceSet.cc",
"src/FontParser.cc",
"src/FontLayout.cc"
} ,
.flags = &.{
"-DNAPI_DISABLE_CPP_EXCEPTIONS",
"-DNODE_ADDON_API_ENABLE_MAYBE",
"-D_USE_MATH_DEFINES",
"-std=c++20",
// dlclose gets called on the addon
// https://maskray.me/blog/2024-03-17-c++-exit-time-destructors
"-fno-c++-static-destructors",
if (target.result.os.tag == .windows) "-DCAIRO_WIN32_STATIC_BUILD" else "",
"-DLUNASVG_BUILD_STATIC",
}
});
canvas.linker_allow_shlib_undefined = true;
if (optimize != .Debug) {
canvas.root_module.strip = true;
}
canvas.root_module.addObject(node_api);
canvas.root_module.linkLibrary(cairo);
canvas.root_module.linkLibrary(libjpeg_turbo);
canvas.root_module.linkLibrary(libpng);
canvas.root_module.linkLibrary(giflib);
canvas.root_module.linkLibrary(sheenbidi);
canvas.root_module.linkLibrary(unicode);
canvas.root_module.linkLibrary(harfbuzz);
canvas.root_module.linkLibrary(lunasvg);
// some deps, especially lunasvg, compile with -ffunction-sections and
// -fdata-sections so we don't have to distribute unused parts of libraries
canvas.link_gc_sections = true;
if (target.result.os.tag == .windows) {
canvas.root_module.linkSystemLibrary("dwrite", .{});
}
if (target.result.os.tag == .macos) {
// The SDK the toolchain is pointed at, whether that is a full Xcode
// or just the Command Line Tools. The macOS version a binary runs on
// comes from the target, not from this.
const sdk_path = std.mem.trim(
u8,
b.run(&.{ "xcrun", "--show-sdk-path" }),
" \r\n",
);
canvas.root_module.addSystemFrameworkPath(.{
.cwd_relative = b.pathJoin(&.{ sdk_path, "System/Library/Frameworks" }),
});
canvas.root_module.addSystemIncludePath(.{
.cwd_relative = b.pathJoin(&.{ sdk_path, "usr/include" }),
});
canvas.root_module.addLibraryPath(.{
.cwd_relative = b.pathJoin(&.{ sdk_path, "usr/lib" }),
});
}
const move = b.addInstallFile(canvas.getEmittedBin(), outputPath(target));
move.step.dependOn(&canvas.step);
b.getInstallStep().dependOn(&move.step);
}