Skip to content

Commit

Permalink
Merge pull request #47 from nektro/main
Browse files Browse the repository at this point in the history
update to Zig 0.11
  • Loading branch information
kivikakk authored Aug 28, 2023
2 parents 5cff47a + b8fa77a commit ce3d36f
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 49 deletions.
10 changes: 2 additions & 8 deletions .github/workflows/spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,10 @@ jobs:
name: Run CommonMark specs
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
submodules: recursive
- uses: goto-bus-stop/setup-zig@v1
with:
version: master
version: 0.11.0
- run: make spec
id: spec-runner
- uses: LouisBrunner/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
name: Specs ${{ steps.spec-runner.outputs.specs-succeeded }}/${{ steps.spec-runner.outputs.spec-count }}
conclusion: ${{ steps.spec-runner.outputs.conclusion }}
22 changes: 11 additions & 11 deletions .github/workflows/zig.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,35 @@ jobs:
test-linux:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
submodules: recursive
- uses: goto-bus-stop/setup-zig@v1
with:
version: master
version: 0.11.0
- run: zig build
- run: zig build test
test-macos:
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
submodules: recursive
- uses: goto-bus-stop/setup-zig@v1
with:
version: master
- run: brew install pkg-config pcre
- run: env ZIG_SYSTEM_LINKER_HACK=1 zig build
- run: env ZIG_SYSTEM_LINKER_HACK=1 zig build test
version: 0.11.0
- run: brew install pcre
- run: zig build
- run: zig build test
test-windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
submodules: recursive
- uses: goto-bus-stop/setup-zig@v1
with:
version: master
version: 0.11.0
- run: c:; cd \vcpkg; git pull; .\bootstrap-vcpkg.bat
- run: vcpkg integrate install
- run: vcpkg install pcre --triplet x64-windows-static
Expand All @@ -45,10 +45,10 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
submodules: recursive
- uses: goto-bus-stop/setup-zig@v1
with:
version: master
version: 0.11.0
- run: zig fmt --check src/*.zig
7 changes: 1 addition & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,4 @@ test:

spec:
zig build
temp_file=$$(mktemp); \
(cd vendor/cmark-gfm/test && python3 spec_tests.py --program=../../../zig-out/bin/koino 2>&1) | tee $$temp_file; \
printf "::set-output name=specs-succeeded::"; tail -n 1 $$temp_file | perl -pne '/(\d+) passed, (\d+) failed, (\d+) errored, (\d+) skipped/; $$_ = $$1'; \
printf "\n::set-output name=spec-count::"; tail -n 1 $$temp_file | perl -pne '/(\d+) passed, (\d+) failed, (\d+) errored, (\d+) skipped/; $$_ = $$1 + $$2 + $$3 + $$4'; \
printf "\n::set-output name=conclusion::"; tail -n 1 $$temp_file | perl -pne '/(\d+) passed, (\d+) failed, (\d+) errored, (\d+) skipped/; $$_ = ($$2 + $$3 > 0) ? "failure" : "success"'; \
printf "\n"
cd vendor/cmark-gfm/test && python3 spec_tests.py --program=../../../zig-out/bin/koino
8 changes: 4 additions & 4 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub fn build(b: *std.Build) !void {
.target = target,
.optimize = optimize,
});
try addCommonRequirements(exe, &deps);
try addCommonRequirements(b, exe, &deps);
b.installArtifact(exe);

const run_cmd = b.addRunArtifact(exe);
Expand All @@ -35,15 +35,15 @@ pub fn build(b: *std.Build) !void {
.target = target,
.optimize = optimize,
});
try addCommonRequirements(test_exe, &deps);
try addCommonRequirements(b, test_exe, &deps);
const test_step = b.step("test", "Run all the tests");
test_step.dependOn(&test_exe.step);
}

fn addCommonRequirements(cs: *std.build.CompileStep, deps: *const std.StringHashMap(*std.build.Module)) !void {
fn addCommonRequirements(b: *std.Build, cs: *std.build.CompileStep, deps: *const std.StringHashMap(*std.build.Module)) !void {
var it = deps.iterator();
while (it.next()) |entry| {
cs.addModule(entry.key_ptr.*, entry.value_ptr.*);
}
try linkPcre(cs);
try linkPcre(b, cs);
}
9 changes: 5 additions & 4 deletions src/inlines.zig
Original file line number Diff line number Diff line change
Expand Up @@ -754,13 +754,14 @@ pub const Subject = struct {
brackets_len -= 1;

if (kind == .Link) {
var i = @intCast(i32, brackets_len) - 1;
var i: i32 = @intCast(brackets_len);
i -= 1;
while (i >= 0) : (i -= 1) {
if (self.brackets.items[@intCast(usize, i)].kind == .Link) {
if (!self.brackets.items[@intCast(usize, i)].active) {
if (self.brackets.items[@intCast(i)].kind == .Link) {
if (!self.brackets.items[@intCast(i)].active) {
break;
} else {
self.brackets.items[@intCast(usize, i)].active = false;
self.brackets.items[@intCast(i)].active = false;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/parser.zig
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ pub const Parser = struct {
else => try scanners.htmlBlockStart7(line[self.first_nonspace..], &matched),
})) {
const nhb = nodes.NodeHtmlBlock{
.block_type = @truncate(u8, matched),
.block_type = @truncate(matched),
.literal = std.ArrayList(u8).init(self.allocator),
};
container = try self.addChild(container, .{ .HtmlBlock = nhb });
Expand Down Expand Up @@ -800,7 +800,7 @@ pub const Parser = struct {
const chars_to_tab = TAB_STOP - (self.column % TAB_STOP);
if (columns) {
self.partially_consumed_tab = chars_to_tab > count;
const chars_to_advance = std.math.min(count, chars_to_tab);
const chars_to_advance = @min(count, chars_to_tab);
self.column += chars_to_advance;
self.offset += @as(u8, if (self.partially_consumed_tab) 0 else 1);
count -= chars_to_advance;
Expand Down
18 changes: 9 additions & 9 deletions src/strings.zig
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ test "chopTrailingHashtags" {
try testing.expectEqualStrings("xyz", chopTrailingHashtags("xyz ##"));
}

pub fn normalizeCode(allocator: mem.Allocator, s: []const u8) ![]u8 {
pub fn normalizeCode(allocator: mem.Allocator, s: []const u8) mem.Allocator.Error![]u8 {
var code = try std.ArrayList(u8).initCapacity(allocator, s.len);
errdefer code.deinit();

Expand Down Expand Up @@ -258,15 +258,15 @@ pub fn unescapeInto(text: []const u8, out: *std.ArrayList(u8)) !?usize {
i = 1;
while (i < text.len and ascii.isDigit(text[i])) {
codepoint = (codepoint * 10) + (@as(u32, text[i]) - '0');
codepoint = std.math.min(codepoint, 0x11_0000);
codepoint = @min(codepoint, 0x11_0000);
i += 1;
}
break :block i - 1;
} else if (text[1] == 'x' or text[1] == 'X') {
i = 2;
while (i < text.len and ascii.isHex(text[i])) {
codepoint = (codepoint * 16) + (@as(u32, text[i]) | 32) % 39 - 9;
codepoint = std.math.min(codepoint, 0x11_0000);
codepoint = @min(codepoint, 0x11_0000);
i += 1;
}
break :block i - 2;
Expand All @@ -275,12 +275,12 @@ pub fn unescapeInto(text: []const u8, out: *std.ArrayList(u8)) !?usize {
};

if (num_digits >= 1 and num_digits <= 8 and i < text.len and text[i] == ';') {
try encodeUtf8Into(@truncate(u21, codepoint), out);
try encodeUtf8Into(@truncate(codepoint), out);
return i + 1;
}
}

const size = std.math.min(text.len, ENTITY_MAX_LENGTH);
const size = @min(text.len, ENTITY_MAX_LENGTH);
var i = ENTITY_MIN_LENGTH;
while (i < size) : (i += 1) {
if (text[i] == ' ')
Expand Down Expand Up @@ -437,7 +437,7 @@ pub fn normalizeLabel(allocator: mem.Allocator, s: []const u8) ![]u8 {
var view = std.unicode.Utf8View.initUnchecked(trimmed);
var it = view.iterator();
while (it.nextCodepoint()) |cp| {
var rune = @intCast(i32, cp);
var rune: i32 = @intCast(cp);
if (zunicode.isSpace(rune)) {
if (!last_was_whitespace) {
last_was_whitespace = true;
Expand All @@ -446,7 +446,7 @@ pub fn normalizeLabel(allocator: mem.Allocator, s: []const u8) ![]u8 {
} else {
last_was_whitespace = false;
var lower = zunicode.toLower(rune);
try encodeUtf8Into(@intCast(u21, lower), &buffer);
try encodeUtf8Into(@intCast(lower), &buffer);
}
}
return buffer.toOwnedSlice();
Expand All @@ -466,9 +466,9 @@ pub fn toLower(allocator: mem.Allocator, s: []const u8) ![]u8 {
var view = try std.unicode.Utf8View.init(s);
var it = view.iterator();
while (it.nextCodepoint()) |cp| {
var rune = @intCast(i32, cp);
var rune: i32 = @intCast(cp);
var lower = zunicode.toLower(rune);
try encodeUtf8Into(@intCast(u21, lower), &buffer);
try encodeUtf8Into(@intCast(lower), &buffer);
}
return buffer.toOwnedSlice();
}
Expand Down
2 changes: 1 addition & 1 deletion src/table.zig
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ fn tryOpeningRow(parser: *Parser, container: *nodes.AstNode, aligns: []nodes.Tab
const new_row = try parser.addChild(container, .{ .TableRow = .Body });

var i: usize = 0;
while (i < std.math.min(aligns.len, this_row.len)) : (i += 1) {
while (i < @min(aligns.len, this_row.len)) : (i += 1) {
var cell = try parser.addChild(new_row, .TableCell);
try cell.data.content.appendSlice(this_row[i]);
}
Expand Down
2 changes: 1 addition & 1 deletion vendor/htmlentities
Submodule htmlentities updated 1 files
+24 −18 build.zig
2 changes: 1 addition & 1 deletion vendor/libpcre
2 changes: 1 addition & 1 deletion vendor/zig-clap
Submodule zig-clap updated 2 files
+1 −1 build.zig
+57 −30 clap.zig
2 changes: 1 addition & 1 deletion vendor/zunicode

0 comments on commit ce3d36f

Please sign in to comment.