Repository navigation
Expand file tree
/
Copy pathbuild.zig
More file actions
1926 lines (1754 loc) · 82.4 KB
/
Copy pathbuild.zig
File metadata and controls
1926 lines (1754 loc) · 82.4 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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
const std = @import("std");
const builtin = @import("builtin");
const optimize_deps: std.lang.Optimize = .fast;
const ShaderLang = enum { glsl410, hlsl5 };
var shader_sources_updated: std.EnumSet(ShaderLang) = .empty;
pub const Renderer = enum { terminal, gui };
pub fn build(b: *std.Build) void {
const flow_options: FlowOptions = .{
.all_targets = b.option(bool, "all-targets", "Build all known good targets during release builds (default: no)") orelse false,
.tracy_enabled = b.option(bool, "enable-tracy", "Enable tracy client library (default: no)") orelse false,
.use_tree_sitter = b.option(bool, "use-tree-sitter", "Enable tree-sitter (default: yes)") orelse true,
.strip = b.option(bool, "strip", "Disable debug information (default: no)") orelse false,
.use_llvm = b.option(bool, "use-llvm", "Enable llvm backend (default: none)"),
.pie = b.option(bool, "pie", "Produce an executable with position independent code (default: none)"),
.renderer = b.option(Renderer, "renderer", "Renderer backend: terminal (default), gui") orelse .terminal,
.test_filters = b.option([]const []const u8, "test-filter", "Skip tests that do not match any filter") orelse &[0][]const u8{},
.embed_emoji = b.option(bool, "embed-emoji", "Embed Noto Color Emoji as a built-in color glyph fallback (default: true)") orelse true,
.install_tests = b.option(bool, "install-tests", "Install unit test executables (default: no)") orelse false,
};
const flow_steps: FlowSteps = .{
.run_step = b.step("run", "Run the app"),
.check_step = b.step("check", "Check the app"),
.test_step = b.step("test", "Run unit tests"),
.lint_step = b.step("lint", "Run lints"),
};
var version: std.Io.Writer.Allocating = .init(b.allocator);
defer version.deinit();
gen_version(b, &version.writer) catch |e| {
if (b.graph.release_mode != .off)
std.debug.panic("gen_version failed: {any}", .{e});
version.clearRetainingCapacity();
version.writer.writeAll("unknown") catch {};
};
const release = switch (b.graph.release_mode) {
.off => false,
.any => blk: {
b.graph.release_mode = .fast;
break :blk true;
},
else => true,
};
return (if (release) &build_release else &build_development)(
b,
flow_steps,
flow_options,
version.written(),
);
}
const FlowSteps = struct {
run_step: *std.Build.Step,
check_step: *std.Build.Step,
test_step: *std.Build.Step,
lint_step: *std.Build.Step,
};
const FlowOptions = struct {
tracy_enabled: bool,
use_tree_sitter: bool,
strip: bool,
use_llvm: ?bool,
pie: ?bool,
renderer: Renderer,
all_targets: bool,
test_filters: []const []const u8,
embed_emoji: bool,
install_tests: bool,
};
fn build_development(
b: *std.Build,
flow_steps: FlowSteps,
flow_options: FlowOptions,
version: []const u8,
) void {
// The gui renderer links system GL/X11 libraries which are not available
// via the musl sysroot, so use the native ABI when building it.
const force_musl = builtin.os.tag == .linux and !flow_options.tracy_enabled and flow_options.renderer != .gui;
const target = b.resolveTargetQuery(with_default_macos_min(
b.standardTargetOptionsQueryOnly(.{ .default_target = .{ .abi = if (force_musl) .musl else null } }),
));
const optimize = b.standardOptimizeOption(.{});
return build_exe(
b,
flow_steps,
flow_options,
target,
optimize,
.{},
version,
);
}
fn build_release(
b: *std.Build,
flow_steps: FlowSteps,
flow_options: FlowOptions,
version: []const u8,
) void {
const targets: []const struct { std.Target.Query, Renderer } = if (flow_options.all_targets) &.{
.{ .{ .cpu_arch = .x86_64, .os_tag = .linux, .abi = .musl }, .terminal },
.{ .{ .cpu_arch = .x86_64, .os_tag = .linux, .abi = .gnu }, .gui },
.{ .{ .cpu_arch = .x86, .os_tag = .linux, .abi = .musl }, .terminal },
.{ .{ .cpu_arch = .aarch64, .os_tag = .linux, .abi = .musl }, .terminal },
.{ .{ .cpu_arch = .aarch64, .os_tag = .linux, .abi = .gnu }, .gui },
.{ .{ .cpu_arch = .arm, .os_tag = .linux, .abi = .musleabihf }, .terminal },
.{ .{ .cpu_arch = .x86_64, .os_tag = .macos }, .terminal },
.{ .{ .cpu_arch = .x86_64, .os_tag = .macos }, .gui },
.{ .{ .cpu_arch = .aarch64, .os_tag = .macos }, .terminal },
.{ .{ .cpu_arch = .aarch64, .os_tag = .macos }, .gui },
.{ .{ .cpu_arch = .x86_64, .os_tag = .windows }, .terminal },
.{ .{ .cpu_arch = .x86_64, .os_tag = .windows }, .gui },
.{ .{ .cpu_arch = .aarch64, .os_tag = .windows }, .terminal },
.{ .{ .cpu_arch = .aarch64, .os_tag = .windows }, .gui },
.{ .{ .cpu_arch = .x86_64, .os_tag = .freebsd }, .terminal },
.{ .{ .cpu_arch = .x86_64, .os_tag = .freebsd }, .gui },
.{ .{ .cpu_arch = .aarch64, .os_tag = .freebsd }, .terminal },
.{ .{ .cpu_arch = .aarch64, .os_tag = .freebsd }, .gui },
} else blk: {
const maybe_triple = b.option(
[]const u8,
"target",
"The CPU architecture, OS, and ABI to build for",
);
const triple = maybe_triple orelse {
const native_target = b.resolveTargetQuery(.{}).result;
break :blk switch (native_target.os.tag) {
.linux => &.{
.{ .{ .cpu_arch = native_target.cpu.arch, .os_tag = native_target.os.tag, .abi = .musl }, .terminal },
.{ .{ .cpu_arch = native_target.cpu.arch, .os_tag = native_target.os.tag, .abi = null }, .gui },
},
.windows, .macos, .freebsd => &.{
.{ .{ .cpu_arch = native_target.cpu.arch, .os_tag = native_target.os.tag }, .terminal },
.{ .{ .cpu_arch = native_target.cpu.arch, .os_tag = native_target.os.tag }, .gui },
},
else => &.{
.{ .{ .cpu_arch = native_target.cpu.arch, .os_tag = native_target.os.tag }, .terminal },
},
};
};
const selected_target = std.Build.parseTargetQuery(.{
.arch_os_abi = triple,
}) catch |err| switch (err) {
error.ParseFailed => @panic("unknown target"),
};
break :blk switch (selected_target.os_tag.?) {
.linux => &.{
.{ .{ .cpu_arch = selected_target.cpu_arch, .os_tag = selected_target.os_tag, .abi = .musl }, .terminal },
.{ .{ .cpu_arch = selected_target.cpu_arch, .os_tag = selected_target.os_tag, .abi = .gnu }, .gui },
},
.windows, .macos, .freebsd => &.{
.{ .{ .cpu_arch = selected_target.cpu_arch, .os_tag = selected_target.os_tag, .abi = selected_target.abi }, .terminal },
.{ .{ .cpu_arch = selected_target.cpu_arch, .os_tag = selected_target.os_tag, .abi = selected_target.abi }, .gui },
},
else => &.{
.{ .{ .cpu_arch = selected_target.cpu_arch, .os_tag = selected_target.os_tag, .abi = selected_target.abi }, .terminal },
},
};
};
const optimize = b.standardOptimizeOption(.{});
const write_file_step = b.addWriteFiles();
const version_file = write_file_step.add("version", version);
b.getInstallStep().dependOn(&b.addInstallFile(version_file, "version").step);
for (targets) |t| {
var options = flow_options;
options.renderer = t.@"1";
options.strip = false;
const target = b.resolveTargetQuery(with_default_macos_min(t.@"0"));
var triple = std.mem.splitScalar(u8, t.@"0".zigTriple(b.allocator) catch unreachable, '-');
const arch = triple.next() orelse unreachable;
const os = triple.next() orelse unreachable;
const target_path = std.mem.join(b.allocator, "-", &[_][]const u8{ os, arch }) catch unreachable;
build_exe(
b,
flow_steps,
options,
target,
optimize,
.{ .dest_dir = .{ .override = .{ .custom = target_path } } },
version,
);
}
}
/// should match LSMinimumSystemVersion in plist
const macos_version_min: std.SemanticVersion = .{ .major = 13, .minor = 0, .patch = 0 };
fn with_default_macos_min(query: std.Target.Query) std.Target.Query {
var q = query;
if (q.os_tag == .macos and q.os_version_min == null)
q.os_version_min = .{ .semver = macos_version_min };
return q;
}
pub fn build_exe(
b: *std.Build,
flow_steps: FlowSteps,
flow_options: FlowOptions,
target: std.Build.ResolvedTarget,
optimize: std.builtin.OptimizeMode,
exe_install_options: std.Build.Step.InstallArtifact.Options,
version: []const u8,
) void {
const run_step = flow_steps.run_step;
const check_step = flow_steps.check_step;
const test_step = flow_steps.test_step;
const lint_step = flow_steps.lint_step;
const tracy_enabled = flow_options.tracy_enabled;
const use_tree_sitter = flow_options.use_tree_sitter;
const strip = flow_options.strip;
const use_llvm = flow_options.use_llvm;
const pie = flow_options.pie;
const renderer = flow_options.renderer;
const test_filters = flow_options.test_filters;
const embed_emoji = flow_options.embed_emoji;
const install_tests = flow_options.install_tests;
const use_lld = if (isDarwin(target)) null else use_llvm;
const is_native = target.query.isNative();
const options = b.addOptions();
options.addOption(bool, "enable_tracy", tracy_enabled);
options.addOption(bool, "use_tree_sitter", use_tree_sitter);
options.addOption(bool, "gui", renderer != .terminal);
const options_mod = options.createModule();
std.Io.Dir.cwd().createDir(b.graph.io, ".cache", .default_dir) catch |e| switch (e) {
error.PathAlreadyExists => {},
else => std.debug.panic("makeDir(\".cache\") failed: {any}", .{e}),
};
std.Io.Dir.cwd().createDir(b.graph.io, ".cache/cdb", .default_dir) catch |e| switch (e) {
error.PathAlreadyExists => {},
else => std.debug.panic("makeDir(\".cache/cdb\") failed: {any}", .{e}),
};
var version_info: std.Io.Writer.Allocating = .init(b.allocator);
defer version_info.deinit();
gen_version_info(b, target, &version_info.writer, optimize, renderer) catch |e| {
if (b.graph.release_mode != .off)
std.debug.panic("gen_version_info failed: {any}", .{e});
version_info.clearRetainingCapacity();
version_info.writer.writeAll("unknown") catch {};
};
const wf = b.addWriteFiles();
const version_file = wf.add("version", version);
const version_info_file = wf.add("version_info", version_info.written());
const vaxis_dep = b.dependency("vaxis", .{
.target = target,
.optimize = optimize,
});
const vaxis_mod = vaxis_dep.module("vaxis");
const flags_dep = b.dependency("flags", .{
.target = target,
.optimize = optimize,
});
const dizzy_dep = b.dependency("dizzy", .{
.target = target,
.optimize = optimize,
});
const fuzzig_dep = b.dependency("fuzzig", .{
.target = target,
.optimize = optimize,
});
const thespian_dep = b.dependency("thespian", .{
.target = target,
.optimize = optimize_deps,
.enable_tracy = tracy_enabled,
});
const thespian_mod = thespian_dep.module("thespian");
const cbor_dep = thespian_dep.builder.dependency("cbor", .{
.target = target,
.optimize = optimize_deps,
});
const cbor_mod = cbor_dep.module("cbor");
const remote_mod = thespian_dep.module("remote");
const tracy_dep = if (tracy_enabled) thespian_dep.builder.dependency("zig_tracy", .{
.target = target,
.optimize = optimize,
}) else undefined;
const tracy_mod = if (tracy_enabled) tracy_dep.module("tracy") else b.createModule(.{
.root_source_file = b.path("src/tracy_noop.zig"),
});
const zeit_dep = b.dependency("zeit", .{
.target = target,
.optimize = optimize,
});
const zeit_mod = zeit_dep.module("zeit");
const regex_dep = b.dependency("regex", .{
.target = target,
.optimize = optimize,
});
const regex_mod = regex_dep.module("regex");
const themes_dep = b.dependency("themes", .{});
const vscode_theme_mod = b.createModule(.{
.root_source_file = themes_dep.path("src/vscode_theme.zig"),
.imports = &.{
.{ .name = "theme", .module = themes_dep.module("theme") },
.{ .name = "cbor", .module = cbor_mod },
},
});
const syntax_dep = b.dependency("syntax", .{
.target = target,
.optimize = optimize_deps,
.use_tree_sitter = use_tree_sitter,
.@"use-llvm" = use_llvm,
});
const syntax_mod = syntax_dep.module("syntax");
const nightwatch_dep = if (target.result.os.tag == .macos) b.dependency("nightwatch", .{
.target = target,
.optimize = optimize,
.macos_fsevents = true,
}) else b.dependency("nightwatch", .{
.target = target,
.optimize = optimize,
});
const nightwatch_mod = nightwatch_dep.module("nightwatch");
const Translator = @import("translate_c").Translator;
const translate_c = b.dependency("translate_c", .{});
const help_mod = b.createModule(.{
.root_source_file = b.path("help.md"),
});
const soft_root_mod = b.createModule(.{
.root_source_file = b.path("src/soft_root.zig"),
.imports = &.{},
});
const crash_mod = b.createModule(.{
.root_source_file = b.path("src/crash.zig"),
.imports = &.{
.{ .name = "soft_root", .module = soft_root_mod },
.{ .name = "thespian", .module = thespian_mod },
.{ .name = "build_options", .module = options_mod },
},
});
const time_fmt_mod = b.createModule(.{
.root_source_file = b.path("src/time_fmt.zig"),
});
const config_mod = b.createModule(.{
.root_source_file = b.path("src/config.zig"),
.imports = &.{
.{ .name = "cbor", .module = cbor_mod },
.{ .name = "build_options", .module = options_mod },
},
});
const gui_config_mod = b.createModule(.{
.root_source_file = b.path("src/gui_config.zig"),
.imports = &.{
.{ .name = "cbor", .module = cbor_mod },
},
});
const file_link_mod = b.createModule(.{
.root_source_file = b.path("src/file_link.zig"),
.imports = &.{
.{ .name = "soft_root", .module = soft_root_mod },
.{ .name = "thespian", .module = thespian_mod },
},
});
const file_type_config_mod = b.createModule(.{
.root_source_file = b.path("src/file_type_config.zig"),
.imports = &.{
.{ .name = "soft_root", .module = soft_root_mod },
.{ .name = "syntax", .module = syntax_mod },
},
});
const argv_mod = b.createModule(.{
.root_source_file = b.path("src/argv.zig"),
.imports = &.{
.{ .name = "cbor", .module = cbor_mod },
},
});
const lsp_config_mod = b.createModule(.{
.root_source_file = b.path("src/lsp_config.zig"),
.imports = &.{
.{ .name = "soft_root", .module = soft_root_mod },
},
});
const log_mod = b.createModule(.{
.root_source_file = b.path("src/log.zig"),
.imports = &.{
.{ .name = "thespian", .module = thespian_mod },
},
});
const command_mod = b.createModule(.{
.root_source_file = b.path("src/command.zig"),
.imports = &.{
.{ .name = "thespian", .module = thespian_mod },
.{ .name = "log", .module = log_mod },
.{ .name = "cbor", .module = cbor_mod },
.{ .name = "soft_root", .module = soft_root_mod },
},
});
const EventHandler_mod = b.createModule(.{
.root_source_file = b.path("src/EventHandler.zig"),
.imports = &.{
.{ .name = "thespian", .module = thespian_mod },
},
});
const VcsStatus_mod = b.createModule(.{
.root_source_file = b.path("src/VcsStatus.zig"),
.imports = &.{},
});
const VcsBlame_mod = b.createModule(.{
.root_source_file = b.path("src/VcsBlame.zig"),
.imports = &.{},
});
const color_mod = b.createModule(.{
.root_source_file = b.path("src/color.zig"),
});
const xterm_mod = b.createModule(.{
.root_source_file = b.path("src/xterm.zig"),
});
const match_mod = b.createModule(.{
.root_source_file = b.path("src/match.zig"),
});
const gitignore_mod = b.createModule(.{
.root_source_file = b.path("src/gitignore/gitignore.zig"),
});
const dbus_mod = b.createModule(.{
.root_source_file = b.path("src/dbus/dbus.zig"),
.imports = &.{
.{ .name = "cbor", .module = cbor_mod },
.{ .name = "thespian", .module = thespian_mod },
},
});
const rc_common_mod = b.createModule(.{
.root_source_file = b.path("src/rc/common/common.zig"),
.imports = &.{
.{ .name = "version", .module = b.createModule(.{ .root_source_file = version_file }) },
},
});
const RcServer_mod = b.createModule(.{
.root_source_file = b.path("src/rc/server/RcServer.zig"),
.imports = &.{
.{ .name = "cbor", .module = cbor_mod },
.{ .name = "thespian", .module = thespian_mod },
.{ .name = "remote", .module = remote_mod },
.{ .name = "common", .module = rc_common_mod },
},
});
const RcClient_mod = b.createModule(.{
.root_source_file = b.path("src/rc/client/RcClient.zig"),
.imports = &.{
.{ .name = "cbor", .module = cbor_mod },
.{ .name = "thespian", .module = thespian_mod },
.{ .name = "remote", .module = remote_mod },
.{ .name = "common", .module = rc_common_mod },
},
});
const syntax_validator_mod = b.createModule(.{
.root_source_file = b.path("src/syntax_validator.zig"),
.imports = &.{
.{ .name = "cbor", .module = cbor_mod },
.{ .name = "syntax", .module = syntax_mod },
.{ .name = "match", .module = match_mod },
.{ .name = "regex", .module = regex_mod },
.{ .name = "soft_root", .module = soft_root_mod },
},
});
const bin_path_mod = b.createModule(.{
.root_source_file = b.path("src/bin_path.zig"),
});
const snippet_mod = b.createModule(.{
.root_source_file = b.path("src/snippet.zig"),
});
const lsp_types_mod = b.createModule(.{
.root_source_file = b.path("src/lsp_types.zig"),
});
const TypedInt_mod = b.createModule(.{
.root_source_file = b.path("src/TypedInt.zig"),
.imports = &.{
.{ .name = "cbor", .module = cbor_mod },
},
});
const file_watcher_mod = b.createModule(.{
.root_source_file = b.path("src/file_watcher.zig"),
.imports = &.{
.{ .name = "soft_root", .module = soft_root_mod },
.{ .name = "nightwatch", .module = nightwatch_mod },
.{ .name = "gitignore", .module = gitignore_mod },
.{ .name = "cbor", .module = cbor_mod },
.{ .name = "thespian", .module = thespian_mod },
},
});
const EditSet_mod = b.createModule(.{
.root_source_file = b.path("src/EditSet.zig"),
.imports = &.{
.{ .name = "cbor", .module = cbor_mod },
.{ .name = "dizzy", .module = dizzy_dep.module("dizzy") },
},
});
const FileStore_mod = b.createModule(.{
.root_source_file = b.path("src/FileStore.zig"),
.imports = &.{
.{ .name = "EditSet", .module = EditSet_mod },
.{ .name = "cbor", .module = cbor_mod },
.{ .name = "thespian", .module = thespian_mod },
.{ .name = "log", .module = log_mod },
.{ .name = "file_watcher", .module = file_watcher_mod },
.{ .name = "soft_root", .module = soft_root_mod },
},
});
const EditorConfig_mod = b.createModule(.{
.root_source_file = b.path("src/EditorConfig.zig"),
.imports = &.{
.{ .name = "cbor", .module = cbor_mod },
.{ .name = "thespian", .module = thespian_mod },
.{ .name = "soft_root", .module = soft_root_mod },
},
});
const Buffer_mod = b.createModule(.{
.root_source_file = b.path("src/buffer/Buffer.zig"),
.imports = &.{
.{ .name = "EditSet", .module = EditSet_mod },
.{ .name = "FileStore", .module = FileStore_mod },
.{ .name = "tracy", .module = tracy_mod },
.{ .name = "cbor", .module = cbor_mod },
.{ .name = "thespian", .module = thespian_mod },
.{ .name = "TypedInt", .module = TypedInt_mod },
.{ .name = "vaxis", .module = vaxis_mod },
.{ .name = "file_type_config", .module = file_type_config_mod },
.{ .name = "VcsBlame", .module = VcsBlame_mod },
.{ .name = "regex", .module = regex_mod },
.{ .name = "config", .module = config_mod },
.{ .name = "soft_root", .module = soft_root_mod },
},
});
const fetch_mod = b.createModule(.{
.root_source_file = b.path("src/fetch.zig"),
});
const double_mapped_ring_buffer_mod = b.createModule(.{
.root_source_file = b.path("src/DoubleMappedRingBuffer.zig"),
});
const command_line_mod = b.createModule(.{
.root_source_file = b.path("src/command_line.zig"),
});
const Terminal_mod = b.createModule(.{
.root_source_file = b.path("src/terminal/Terminal.zig"),
.imports = &.{
.{ .name = "config", .module = config_mod },
.{ .name = "vaxis", .module = vaxis_mod },
.{ .name = "DoubleMappedRingBuffer", .module = double_mapped_ring_buffer_mod },
.{ .name = "cbor", .module = cbor_mod },
.{ .name = "xterm", .module = xterm_mod },
.{ .name = "soft_root", .module = soft_root_mod },
.{ .name = "command_line", .module = command_line_mod },
},
});
const input_mod = b.createModule(.{
.root_source_file = b.path("src/renderer/vaxis/input.zig"),
.imports = &.{
.{ .name = "vaxis", .module = vaxis_mod },
},
});
const MouseEvent_mod = b.createModule(.{
.root_source_file = b.path("src/MouseEvent.zig"),
.imports = &.{
.{ .name = "vaxis", .module = vaxis_mod },
.{ .name = "cbor", .module = cbor_mod },
.{ .name = "config", .module = config_mod },
},
});
const tui_renderer_mod = b.createModule(.{
.root_source_file = b.path("src/renderer/vaxis/renderer.zig"),
.imports = &.{
.{ .name = "vaxis", .module = vaxis_mod },
.{ .name = "input", .module = input_mod },
.{ .name = "MouseEvent", .module = MouseEvent_mod },
.{ .name = "theme", .module = themes_dep.module("theme") },
.{ .name = "cbor", .module = cbor_mod },
.{ .name = "log", .module = log_mod },
.{ .name = "thespian", .module = thespian_mod },
.{ .name = "Buffer", .module = Buffer_mod },
.{ .name = "color", .module = color_mod },
.{ .name = "TypedInt", .module = TypedInt_mod },
.{ .name = "crash", .module = crash_mod },
},
});
const renderer_mod = blk: {
switch (renderer) {
.terminal => break :blk tui_renderer_mod,
.gui => {
const wio_dep_lazy = b.lazyDependency("wio", .{
.target = target,
.optimize = optimize_deps,
.enable_opengl = true,
});
const sokol_dep_lazy = b.lazyDependency("sokol", .{
.target = target,
.optimize = optimize_deps,
.gl = switch (target.result.os.tag) {
.windows => false,
else => true,
},
.dont_link_system_libs = true,
.libs = "log,gfx",
});
const wio_dep = wio_dep_lazy orelse break :blk tui_renderer_mod;
const sokol_dep = sokol_dep_lazy orelse break :blk tui_renderer_mod;
const wio_mod = wio_dep.module("wio");
const sokol_mod = sokol_dep.module("sokol");
const cross_unix = switch (target.result.os.tag) {
.linux, .freebsd => !is_native,
else => false,
};
const flow_gui_headers_dep = if (cross_unix)
b.lazyDependency("flow_gui_headers", .{}) orelse break :blk tui_renderer_mod
else
null;
if (cross_unix) {
const sokol_clib = sokol_dep.artifact("sokol_clib");
if (b.lazyDependency("wio_unix_headers", .{})) |unix_headers|
sokol_clib.root_module.addSystemIncludePath(unix_headers.path("."));
sokol_clib.root_module.addSystemIncludePath(flow_gui_headers_dep.?.path("include"));
} else if (target.result.os.tag == .freebsd) {
sokol_dep.artifact("sokol_clib").root_module.linkSystemLibrary("gl", .{});
}
const cross_macos = target.result.os.tag == .macos and !is_native;
if (cross_macos) {
const sokol_clib = sokol_dep.artifact("sokol_clib");
if (wio_dep.builder.lazyDependency("wio_macos_sdk", .{})) |macos_sdk| {
sokol_clib.root_module.addSystemFrameworkPath(macos_sdk.path("System/Library/Frameworks"));
sokol_clib.root_module.addSystemIncludePath(macos_sdk.path("usr/include"));
sokol_clib.root_module.addLibraryPath(macos_sdk.path("usr/lib"));
}
}
const sokol_build = b.lazyImport(@This(), "sokol") orelse break :blk tui_renderer_mod;
const shader_lang: ShaderLang = switch (target.result.os.tag) {
.windows => .hlsl5,
else => .glsl410,
};
const shader_source = b.fmt("src/gui/gpu/builtin.{t}.zig", .{shader_lang});
const shader_path = if (sokol_build.host_has_shdc) shader: {
const shdc = sokol_build.shdc;
const slang: shdc.Slang = switch (shader_lang) {
.glsl410 => .{ .glsl410 = true },
.hlsl5 => .{ .hlsl5 = true },
};
const generated = shdc.compile(b, .{
.shdc_dep = sokol_dep.builder.dependency("shdc", .{}),
.input = "src/gui/gpu/builtin.glsl",
.output = "builtin.glsl.zig",
.slang = slang,
.format = .sokol_zig,
}) catch |e| std.debug.panic("sokol-shdc compile failed: {s}", .{@errorName(e)});
if (!shader_sources_updated.contains(shader_lang)) {
shader_sources_updated.insert(shader_lang);
const update = b.addUpdateSourceFiles();
update.addCopyFileToSource(generated, shader_source);
b.getInstallStep().dependOn(&update.step);
}
break :shader generated;
} else b.path(shader_source);
const shader_mod = b.createModule(.{
.root_source_file = shader_path,
.imports = &.{.{ .name = "sokol", .module = sokol_mod }},
});
const gui_xy_mod = b.createModule(.{ .root_source_file = b.path("src/gui/xy.zig") });
const gui_blit_mod = b.createModule(.{
.root_source_file = b.path("src/gui/rasterizer/blit.zig"),
.target = target,
.optimize = .fast,
});
const gui_glyph_constraint_mod = b.createModule(.{ .root_source_file = b.path("src/gui/glyph_constraint.zig") });
const gui_face_metrics_mod = b.createModule(.{ .root_source_file = b.path("src/gui/rasterizer/face_metrics.zig") });
const gui_cell_mod = b.createModule(.{
.root_source_file = b.path("src/gui/cell.zig"),
.imports = &.{
.{ .name = "color", .module = color_mod },
},
});
const gui_glyph_atlas_mod = b.createModule(.{
.root_source_file = b.path("src/gui/GlyphAtlas.zig"),
.imports = &.{
.{ .name = "xy", .module = gui_xy_mod },
},
});
const flow_sprite_dep = b.lazyDependency("flow_sprite", .{
.target = target,
.optimize = optimize_deps,
}) orelse break :blk tui_renderer_mod;
const flow_sprite_mod = flow_sprite_dep.module("sprite");
const z2d_mod = flow_sprite_dep.builder.dependency("z2d", .{
.target = target,
.optimize = optimize_deps,
}).module("z2d");
const uucode_utils_mod = b.createModule(.{
.root_source_file = b.path("src/gui/uucode_utils.zig"),
.target = target,
.imports = &.{
.{ .name = "vaxis", .module = vaxis_mod },
},
});
const combined_rasterizer_mod = b.createModule(.{
.root_source_file = b.path("src/gui/rasterizer/combined.zig"),
.target = target,
.imports = &.{
.{ .name = "xy", .module = gui_xy_mod },
.{ .name = "gui_config", .module = gui_config_mod },
.{ .name = "glyph_constraint", .module = gui_glyph_constraint_mod },
},
});
const nerd_font_mod = blk2: {
const nerd_dep = b.lazyDependency("nerd_fonts", .{}) orelse break :blk2 null;
break :blk2 b.createModule(.{
.root_source_file = nerd_dep.path("SymbolsNerdFontMono-Regular.ttf"),
});
};
const noto_emoji_font_mod = blk2: {
const flow_fonts_dep = b.lazyDependency("flow_fonts", .{}) orelse break :blk2 null;
break :blk2 b.createModule(.{
.root_source_file = flow_fonts_dep.path("noto-emoji-2.051/NotoColorEmoji.ttf"),
});
};
const Face = struct { name: []const u8, file: []const u8 };
const iosevka_faces = [_]Face{
.{ .name = "iosevka_light", .file = "iosevka-34.8.0/Iosevka-Light.ttf" },
.{ .name = "iosevka_medium", .file = "iosevka-34.8.0/Iosevka-Medium.ttf" },
.{ .name = "iosevka_extrabold", .file = "iosevka-34.8.0/Iosevka-ExtraBold.ttf" },
.{ .name = "iosevka_light_italic", .file = "iosevka-34.8.0/Iosevka-LightItalic.ttf" },
.{ .name = "iosevka_medium_italic", .file = "iosevka-34.8.0/Iosevka-MediumItalic.ttf" },
.{ .name = "iosevka_extrabold_italic", .file = "iosevka-34.8.0/Iosevka-ExtraBoldItalic.ttf" },
};
const iosevka_mods: ?[iosevka_faces.len]*std.Build.Module = blk2: {
const flow_fonts_dep = b.lazyDependency("flow_fonts", .{}) orelse break :blk2 null;
var mods: [iosevka_faces.len]*std.Build.Module = undefined;
inline for (iosevka_faces, 0..) |face, i| {
mods[i] = b.createModule(.{
.root_source_file = flow_fonts_dep.path(face.file),
});
}
break :blk2 mods;
};
const add_iosevka = struct {
fn f(mod: *std.Build.Module, mods: ?[iosevka_faces.len]*std.Build.Module) void {
const m = mods orelse return;
inline for (iosevka_faces, 0..) |face, i|
mod.addImport(face.name, m[i]);
}
}.f;
const gui_embed_options = b.addOptions();
gui_embed_options.addOption(bool, "embed_emoji", embed_emoji);
const gui_embed_options_mod = gui_embed_options.createModule();
if (target.result.os.tag == .windows) {
const win32_dep = b.lazyDependency("win32", .{}) orelse break :blk tui_renderer_mod;
const win32_mod = win32_dep.module("win32");
const dwrite_rasterizer_mod = b.createModule(.{
.root_source_file = b.path("src/gui/rasterizer/dwrite.zig"),
.target = target,
.imports = &.{
.{ .name = "xy", .module = gui_xy_mod },
.{ .name = "gui_config", .module = gui_config_mod },
.{ .name = "win32", .module = win32_mod },
.{ .name = "uucode_utils", .module = uucode_utils_mod },
.{ .name = "flow_sprite", .module = flow_sprite_mod },
.{ .name = "glyph_constraint", .module = gui_glyph_constraint_mod },
.{ .name = "face_metrics", .module = gui_face_metrics_mod },
.{ .name = "blit", .module = gui_blit_mod },
.{ .name = "build_options", .module = gui_embed_options_mod },
},
});
if (nerd_font_mod) |m| dwrite_rasterizer_mod.addImport("nerd_font", m);
if (noto_emoji_font_mod) |m| dwrite_rasterizer_mod.addImport("noto_emoji_font", m);
add_iosevka(dwrite_rasterizer_mod, iosevka_mods);
combined_rasterizer_mod.addImport("dw_rasterizer", dwrite_rasterizer_mod);
} else {
const have_freetype = target.result.os.tag != .macos;
const have_coretext = target.result.os.tag == .macos;
if (have_coretext) {
const coretext_rasterizer_mod = b.createModule(.{
.root_source_file = b.path("src/gui/rasterizer/coretext.zig"),
.target = target,
.imports = &.{
.{ .name = "xy", .module = gui_xy_mod },
.{ .name = "gui_config", .module = gui_config_mod },
.{ .name = "uucode_utils", .module = uucode_utils_mod },
.{ .name = "flow_sprite", .module = flow_sprite_mod },
.{ .name = "glyph_constraint", .module = gui_glyph_constraint_mod },
.{ .name = "face_metrics", .module = gui_face_metrics_mod },
.{ .name = "blit", .module = gui_blit_mod },
.{ .name = "build_options", .module = gui_embed_options_mod },
},
});
if (nerd_font_mod) |m| coretext_rasterizer_mod.addImport("nerd_font", m);
if (noto_emoji_font_mod) |m| coretext_rasterizer_mod.addImport("noto_emoji_font", m);
add_iosevka(coretext_rasterizer_mod, iosevka_mods);
if (cross_macos) {
if (wio_dep.builder.lazyDependency("wio_macos_sdk", .{})) |macos_sdk|
coretext_rasterizer_mod.addSystemFrameworkPath(macos_sdk.path("System/Library/Frameworks"));
}
coretext_rasterizer_mod.linkFramework("CoreFoundation", .{});
coretext_rasterizer_mod.linkFramework("CoreGraphics", .{});
coretext_rasterizer_mod.linkFramework("CoreText", .{});
coretext_rasterizer_mod.link_libc = true;
combined_rasterizer_mod.addImport("ct_rasterizer", coretext_rasterizer_mod);
}
const tt_dep = b.lazyDependency("TrueType", .{
.target = target,
.optimize = optimize_deps,
}) orelse break :blk tui_renderer_mod;
const font_finder_mod = b.createModule(.{
.root_source_file = b.path("src/gui/rasterizer/font_finder.zig"),
.target = target,
});
if (target.result.os.tag == .linux or target.result.os.tag == .freebsd) {
const fontconfig_c_step: Translator = .init(translate_c, .{
.c_source_file = b.path("src/gui/rasterizer/font_finder/fontconfig_c.h"),
.target = target,
.optimize = optimize,
});
if (is_native) {
font_finder_mod.linkSystemLibrary("fontconfig", .{});
} else {
const fv = b.lazyImport(@This(), "flow_gui_headers") orelse break :blk tui_renderer_mod;
font_finder_mod.addObjectFile(fv.stubSharedLib(b, target, optimize, "fontconfig", 1, &fv.fontconfig_stub_symbols).getEmittedBin());
font_finder_mod.addIncludePath(flow_gui_headers_dep.?.path("include"));
fontconfig_c_step.addIncludePath(flow_gui_headers_dep.?.path("include"));
}
font_finder_mod.link_libc = true;
font_finder_mod.addImport("c", fontconfig_c_step.mod);
}
const fallback_resolver_mod = b.createModule(.{
.root_source_file = b.path("src/gui/rasterizer/fallback_resolver.zig"),
.target = target,
.imports = &.{
.{ .name = "font_finder", .module = font_finder_mod },
.{ .name = "face_metrics", .module = gui_face_metrics_mod },
},
});
const truetype_rasterizer_mod = b.createModule(.{
.root_source_file = b.path("src/gui/rasterizer/truetype.zig"),
.target = target,
.imports = &.{
.{ .name = "soft_root", .module = soft_root_mod },
.{ .name = "TrueType", .module = tt_dep.module("TrueType") },
.{ .name = "xy", .module = gui_xy_mod },
.{ .name = "flow_sprite", .module = flow_sprite_mod },
.{ .name = "font_finder", .module = font_finder_mod },
.{ .name = "fallback_resolver", .module = fallback_resolver_mod },
.{ .name = "gui_config", .module = gui_config_mod },
.{ .name = "uucode_utils", .module = uucode_utils_mod },
.{ .name = "glyph_constraint", .module = gui_glyph_constraint_mod },
.{ .name = "blit", .module = gui_blit_mod },
},
});
if (nerd_font_mod) |m| truetype_rasterizer_mod.addImport("nerd_font", m);
add_iosevka(truetype_rasterizer_mod, iosevka_mods);
if (have_freetype) {
const freetype_rasterizer_mod = b.createModule(.{
.root_source_file = b.path("src/gui/rasterizer/freetype.zig"),
.target = target,
.imports = &.{
.{ .name = "xy", .module = gui_xy_mod },
.{ .name = "flow_sprite", .module = flow_sprite_mod },
.{ .name = "font_finder", .module = font_finder_mod },
.{ .name = "fallback_resolver", .module = fallback_resolver_mod },
.{ .name = "gui_config", .module = gui_config_mod },
.{ .name = "uucode_utils", .module = uucode_utils_mod },
.{ .name = "build_options", .module = gui_embed_options_mod },
.{ .name = "glyph_constraint", .module = gui_glyph_constraint_mod },
.{ .name = "blit", .module = gui_blit_mod },
},
});
if (nerd_font_mod) |m| freetype_rasterizer_mod.addImport("nerd_font", m);
if (noto_emoji_font_mod) |m| freetype_rasterizer_mod.addImport("noto_emoji_font", m);
add_iosevka(freetype_rasterizer_mod, iosevka_mods);
if (cross_unix) {
const fv = b.lazyImport(@This(), "flow_gui_headers") orelse break :blk tui_renderer_mod;
freetype_rasterizer_mod.addObjectFile(fv.stubSharedLib(b, target, optimize, "freetype", 6, &fv.freetype_stub_symbols).getEmittedBin());
} else {
freetype_rasterizer_mod.linkSystemLibrary("freetype2", .{});
}
const freetype_dep = b.lazyDependency("freetype", .{}) orelse break :blk tui_renderer_mod;
freetype_rasterizer_mod.addIncludePath(freetype_dep.path("include"));
freetype_rasterizer_mod.link_libc = true;
const freetype_c_step: Translator = .init(translate_c, .{
.c_source_file = b.path("src/gui/rasterizer/freetype_c.h"),
.target = target,
.optimize = optimize,
});
freetype_c_step.addIncludePath(freetype_dep.path("include"));
freetype_rasterizer_mod.addImport("c", freetype_c_step.mod);
combined_rasterizer_mod.addImport("ft_rasterizer", freetype_rasterizer_mod);
}
combined_rasterizer_mod.addImport("tt_rasterizer", truetype_rasterizer_mod);
}
const gpu_mod = b.createModule(.{
.root_source_file = b.path("src/gui/gpu/gpu.zig"),
.imports = &.{
.{ .name = "color", .module = color_mod },
.{ .name = "sokol", .module = sokol_mod },
.{ .name = "rasterizer", .module = combined_rasterizer_mod },
.{ .name = "xy", .module = gui_xy_mod },
.{ .name = "cell", .module = gui_cell_mod },
.{ .name = "GlyphAtlas", .module = gui_glyph_atlas_mod },
.{ .name = "shader", .module = shader_mod },
},
});
if (target.result.os.tag == .windows) {
const win32_dep = b.lazyDependency("win32", .{}) orelse break :blk tui_renderer_mod;
gpu_mod.addImport("win32", win32_dep.module("win32"));
}
const nerd_font_attributes_mod = b.createModule(.{
.root_source_file = flow_sprite_dep.path("src/font/nerd_font_attributes.zig"),
.imports = &.{
.{ .name = "Glyph.zig", .module = b.createModule(.{
.root_source_file = b.path("src/gui/GlyphAdaptor.zig"),
.imports = &.{