Skip to content

Commit 44abb10

Browse files
committed
update to latest zig
1 parent 9266b31 commit 44abb10

File tree

11 files changed

+399
-31
lines changed

11 files changed

+399
-31
lines changed

build.zig

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,34 @@ pub fn build(b: *std.Build) !void {
1111
)) |v| .{ .commit = v } else getVersion(b);
1212

1313
const scripty = b.dependency("scripty", .{});
14+
15+
const enable_tracy = b.option(bool, "tracy", "Enable Tracy profiling") orelse false;
16+
const tracy_options = b.addOptions();
17+
tracy_options.addOption(bool, "enable_tracy", enable_tracy);
18+
tracy_options.addOption(bool, "enable_tracy_allocation", false);
19+
tracy_options.addOption(bool, "enable_tracy_callstack", true);
20+
tracy_options.addOption(usize, "tracy_callstack_depth", 10);
21+
1422
const superhtml = b.addModule("superhtml", .{
1523
.root_source_file = b.path("src/root.zig"),
24+
.target = target,
1625
});
1726
superhtml.addImport("scripty", scripty.module("scripty"));
27+
superhtml.addOptions("tracy_options", tracy_options);
28+
29+
if (enable_tracy) {
30+
if (target.result.os.tag == .windows) {
31+
superhtml.linkSystemLibrary("dbghelp", .{});
32+
superhtml.linkSystemLibrary("ws2_32", .{});
33+
}
34+
35+
// superhtml.addObjectFile(b.path("libTracyClient.a"));
36+
//
37+
superhtml.linkSystemLibrary("TracyClient", .{});
38+
superhtml.addLibraryPath(.{ .cwd_relative = "/opt/homebrew/opt/tracy/lib" });
39+
superhtml.link_libc = true;
40+
superhtml.link_libcpp = true;
41+
}
1842

1943
const options = b.addOptions();
2044
const verbose_logging = b.option(bool, "log", "Enable verbose logging also in release modes") orelse false;
@@ -24,8 +48,8 @@ pub fn build(b: *std.Build) !void {
2448
options.addOption([]const u8, "version", version.string());
2549
options.addOption(Version.Kind, "version_kind", version);
2650

27-
const folders = b.dependency("known-folders", .{});
28-
const lsp = b.dependency("zig-lsp-kit", .{});
51+
const folders = b.dependency("known_folders", .{});
52+
const lsp = b.dependency("lsp_kit", .{});
2953

3054
setupTestStep(b, target, superhtml);
3155
setupCliTool(b, target, optimize, options, superhtml, folders, lsp);
@@ -62,7 +86,7 @@ fn setupCheckStep(
6286

6387
super_cli_check.root_module.addImport("superhtml", superhtml);
6488
super_cli_check.root_module.addImport(
65-
"known-folders",
89+
"known_folders",
6690
folders.module("known-folders"),
6791
);
6892
super_cli_check.root_module.addImport("lsp", lsp.module("lsp"));
@@ -109,7 +133,7 @@ fn setupFuzzStep(
109133
target: std.Build.ResolvedTarget,
110134
superhtml: *std.Build.Module,
111135
) void {
112-
const afl = b.lazyImport(@This(), "zig-afl-kit") orelse return;
136+
const afl = b.lazyImport(@This(), "afl_kit") orelse return;
113137
const afl_obj = b.addObject(.{
114138
.name = "superfuzz-afl",
115139
.root_source_file = b.path("src/fuzz/afl.zig"),
@@ -125,9 +149,12 @@ fn setupFuzzStep(
125149
b,
126150
target,
127151
.ReleaseSafe,
152+
null,
153+
false,
128154
afl_obj,
129-
);
155+
) orelse return;
130156
b.getInstallStep().dependOn(&b.addInstallFile(afl_fuzz, "superfuzz-afl").step);
157+
// b.installArtifact(afl_fuzz);
131158

132159
const super_fuzz = b.addExecutable(.{
133160
.name = "superfuzz",
@@ -169,7 +196,7 @@ fn setupCliTool(
169196

170197
super_cli.root_module.addImport("superhtml", superhtml);
171198
super_cli.root_module.addImport(
172-
"known-folders",
199+
"known_folders",
173200
folders.module("known-folders"),
174201
);
175202
super_cli.root_module.addImport("lsp", lsp.module("lsp"));
@@ -245,8 +272,8 @@ fn setupReleaseStep(
245272

246273
super_exe_release.root_module.addImport("superhtml", superhtml);
247274
super_exe_release.root_module.addImport(
248-
"known-folders",
249-
folders.module("known-folders"),
275+
"known_folders",
276+
folders.module("known_folders"),
250277
);
251278
super_exe_release.root_module.addImport("lsp", lsp.module("lsp"));
252279
super_exe_release.root_module.addOptions("build_options", options);

build.zig.zon

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
.{
2-
.name = "superhtml",
2+
.name = .superhtml,
33
.version = "0.4.0",
4+
.fingerprint = 0xc5e9aede3c1db363,
5+
.minimum_zig_version = "0.14.0-dev.3451+d8d2aa9af",
46
.dependencies = .{
5-
.@"zig-lsp-kit" = .{
6-
.url = "git+https://github.com/kristoff-it/zig-lsp-kit#b4bf61d7fbf9cf7cfdb6f01b211947d2de3e42fd",
7-
.hash = "1220b9ce6dc0e1fbcd9e7b406ab164344f81774351495f860a90729187c3c058ef4f",
8-
},
9-
.@"known-folders" = .{
10-
.url = "git+https://github.com/ziglibs/known-folders#1cceeb70e77dec941a4178160ff6c8d05a74de6f",
11-
.hash = "12205f5e7505c96573f6fc5144592ec38942fb0a326d692f9cddc0c7dd38f9028f29",
7+
.lsp_kit = .{
8+
.url = "git+https://github.com/kristoff-it/zig-lsp-kit#87ff3d537a0c852442e180137d9557711963802c",
9+
.hash = "lsp_kit-0.1.0-hAAxO9S9AADv_5D0iplASFtNCFXAPk54M0u-3jj2MRFk",
1210
},
1311
.scripty = .{
14-
.url = "git+https://github.com/kristoff-it/scripty#c76ef31dd5429725220de30504bde89a68565ece",
15-
.hash = "1220c242654fe9bdd1be1fdb7b8e142842adc9adcc987efe7eb64af6451f45cbbc34",
12+
.url = "git+https://github.com/kristoff-it/scripty#458ed4724feeae91727da4771ffccc5d3ea20a12",
13+
.hash = "scripty-0.1.0-LKK5O5--AAAYA23ErngQEPW9Il_kiljcfTRUkDgwK2G4",
1614
},
17-
.@"zig-afl-kit" = .{
18-
.url = "git+https://github.com/kristoff-it/zig-afl-kit#f003bfe714f2964c90939fdc940d5993190a66ec",
19-
.hash = "1220f2d8402bb7bbc4786b9c0aad73910929ea209cbd3b063842371d68abfed33c1e",
15+
.afl_kit = .{
16+
.url = "git+https://github.com/kristoff-it/zig-afl-kit?ref=zig-0.14.0#1e9fcaa08361307d16a9bde82b4a7fd4560ce502",
17+
.hash = "afl_kit-0.1.0-uhOgGDkdAAALG16McR2B4b8QwRUQ2sa9XdgDTFXRWQTY",
2018
.lazy = true,
2119
},
20+
.known_folders = .{
21+
.url = "git+https://github.com/ziglibs/known-folders#aa24df42183ad415d10bc0a33e6238c437fc0f59",
22+
.hash = "known_folders-0.0.0-Fy-PJtLDAADGDOwYwMkVydMSTp_aN-nfjCZw6qPQ2ECL",
23+
},
2224
},
2325
.paths = .{
2426
"LICENSE",

src/cli.zig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
const std = @import("std");
22
const builtin = @import("builtin");
33
const build_options = @import("build_options");
4+
const known = @import("known-folders");
45
const super = @import("super");
56
const logging = @import("cli/logging.zig");
67
const interface_exe = @import("cli/interface.zig");
78
const check_exe = @import("cli/check.zig");
89
const fmt_exe = @import("cli/fmt.zig");
910
const lsp_exe = @import("cli/lsp.zig");
1011

11-
pub const known_folders_config = .{
12+
pub const known_folders_config = known.KnownFolderConfig{
1213
.xdg_force_default = true,
1314
.xdg_on_mac = true,
1415
};

src/cli/logging.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub var log_file: ?std.fs.File = switch (builtin.target.os.tag) {
1818

1919
pub fn logFn(
2020
comptime level: std.log.Level,
21-
comptime scope: @Type(.EnumLiteral),
21+
comptime scope: @Type(.enum_literal),
2222
comptime format: []const u8,
2323
args: anytype,
2424
) void {

src/cli/lsp/Document.zig

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ const log = std.log.scoped(.lsp_document);
99
language: super.Language,
1010
src: []const u8,
1111
html: super.html.Ast,
12-
super: ?super.Ast = null,
12+
super_ast: ?super.Ast = null,
1313

1414
pub fn deinit(doc: *Document, gpa: std.mem.Allocator) void {
1515
doc.html.deinit(gpa);
16-
if (doc.super) |s| s.deinit(gpa);
16+
if (doc.super_ast) |s| s.deinit(gpa);
1717
}
1818

1919
pub fn init(
@@ -31,7 +31,7 @@ pub fn init(
3131
if (language == .superhtml and doc.html.errors.len == 0) {
3232
const super_ast = try super.Ast.init(gpa, doc.html, src);
3333
errdefer super_ast.deinit(gpa);
34-
doc.super = super_ast;
34+
doc.super_ast = super_ast;
3535
}
3636

3737
return doc;
@@ -43,9 +43,9 @@ pub fn reparse(doc: *Document, gpa: std.mem.Allocator) !void {
4343
errdefer doc.html.deinit(gpa);
4444

4545
if (doc.language == .superhtml and doc.html.errors.len == 0) {
46-
doc.super = try super.Ast.init(gpa, doc.html, doc.src);
46+
doc.super_ast = try super.Ast.init(gpa, doc.html, doc.src);
4747
} else {
48-
doc.super = null;
48+
doc.super_ast = null;
4949
}
5050

5151
return;

src/cli/lsp/logic.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub fn loadFile(
5656
}
5757
res.diagnostics = diags;
5858
} else {
59-
if (doc.super) |super_ast| {
59+
if (doc.super_ast) |super_ast| {
6060
const diags = try arena.alloc(
6161
lsp.types.Diagnostic,
6262
super_ast.errors.len,

src/fuzz.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const std = @import("std");
22
const super = @import("superhtml");
33

4-
pub const std_options = .{ .log_level = .err };
4+
pub const std_options: std.Options = .{ .log_level = .err };
55

66
/// This main function is meant to be used via black box fuzzers
77
/// and/or to manually weed out test cases that are not valid anymore

src/fuzz/afl.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const std = @import("std");
22
const super = @import("superhtml");
33
const astgen = @import("astgen.zig");
44

5-
pub const std_options = .{ .log_level = .err };
5+
pub const std_options: std.Options = .{ .log_level = .err };
66

77
export fn zig_fuzz_init() void {}
88

src/html/Ast.zig

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const Ast = @This();
22

33
const std = @import("std");
4+
const tracy = @import("../tracy.zig");
45
const root = @import("../root.zig");
56
const Language = root.Language;
67
const Span = root.Span;
@@ -121,6 +122,9 @@ pub const Node = struct {
121122
};
122123

123124
pub fn startTagIterator(n: Node, src: []const u8, language: Language) TagIterator {
125+
const zone = tracy.trace(@src());
126+
defer zone.end();
127+
124128
var t: Tokenizer = .{
125129
.language = language,
126130
.idx = n.open.start,
@@ -538,12 +542,16 @@ pub fn render(ast: Ast, src: []const u8, w: anytype) !void {
538542
// var last_open_was_vertical = false;
539543
var pre: u32 = 0;
540544
while (true) {
545+
const zone_outer = tracy.trace(@src());
546+
defer zone_outer.end();
541547
log.debug("looping, ind: {}, dir: {s}", .{
542548
indentation,
543549
@tagName(direction),
544550
});
545551
switch (direction) {
546552
.enter => {
553+
const zone = tracy.trace(@src());
554+
defer zone.end();
547555
log.debug("rendering enter ({}): {s} {any}", .{
548556
indentation,
549557
"",
@@ -573,6 +581,8 @@ pub fn render(ast: Ast, src: []const u8, w: anytype) !void {
573581
}
574582
},
575583
.exit => {
584+
const zone = tracy.trace(@src());
585+
defer zone.end();
576586
std.debug.assert(current.kind != .text);
577587
std.debug.assert(current.kind != .element_void);
578588
std.debug.assert(current.kind != .element_self_closing);
@@ -608,13 +618,17 @@ pub fn render(ast: Ast, src: []const u8, w: anytype) !void {
608618
switch (current.kind) {
609619
.root => switch (direction) {
610620
.enter => {
621+
const zone = tracy.trace(@src());
622+
defer zone.end();
611623
if (current.first_child_idx == 0) break;
612624
current = ast.nodes[current.first_child_idx];
613625
},
614626
.exit => break,
615627
},
616628

617629
.text => {
630+
const zone = tracy.trace(@src());
631+
defer zone.end();
618632
std.debug.assert(direction == .enter);
619633

620634
const txt = current.open.slice(src);
@@ -636,6 +650,8 @@ pub fn render(ast: Ast, src: []const u8, w: anytype) !void {
636650
},
637651

638652
.comment => {
653+
const zone = tracy.trace(@src());
654+
defer zone.end();
639655
std.debug.assert(direction == .enter);
640656

641657
try w.writeAll(current.open.slice(src));
@@ -650,6 +666,8 @@ pub fn render(ast: Ast, src: []const u8, w: anytype) !void {
650666
},
651667

652668
.doctype => {
669+
const zone = tracy.trace(@src());
670+
defer zone.end();
653671
last_rbracket = current.open.end;
654672
const maybe_name, const maybe_extra = blk: {
655673
var tt: Tokenizer = .{ .language = ast.language };
@@ -690,6 +708,8 @@ pub fn render(ast: Ast, src: []const u8, w: anytype) !void {
690708

691709
.element, .element_void, .element_self_closing => switch (direction) {
692710
.enter => {
711+
const zone = tracy.trace(@src());
712+
defer zone.end();
693713
last_rbracket = current.open.end;
694714
var tt: Tokenizer = .{
695715
.idx = current.open.start,
@@ -802,6 +822,8 @@ pub fn render(ast: Ast, src: []const u8, w: anytype) !void {
802822
}
803823
},
804824
.exit => {
825+
const zone = tracy.trace(@src());
826+
defer zone.end();
805827
std.debug.assert(current.kind != .element_void);
806828
std.debug.assert(current.kind != .element_self_closing);
807829
last_rbracket = current.close.end;

src/html/Tokenizer.zig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const named_character_references = @import("named_character_references.zig");
1212

1313
const std = @import("std");
1414
const root = @import("../root.zig");
15+
const tracy = @import("../tracy.zig");
1516
const Language = root.Language;
1617
const Span = root.Span;
1718

@@ -396,6 +397,9 @@ pub fn getName(tokenizer: *Tokenizer, tag_src: []const u8) ?Span {
396397
}
397398

398399
pub fn next(self: *Tokenizer, src: []const u8) ?Token {
400+
const zone = tracy.trace(@src());
401+
defer zone.end();
402+
399403
if (self.deferred_token) |t| {
400404
const token_copy = t;
401405
self.deferred_token = null;

0 commit comments

Comments
 (0)