Conversation
- Use Zig 0.15.1. - Use mlugg/setup-zig@v2. - Use same test setup for all OS platforms. - Lint `build.zig`.
- Add recipes for fetching Zig packages. - Add recipe for running example.
- Use descriptive name for file ('to-html').
- Save output HTML in a file.
- Ignore output files in version control.
- Update 'minimum_zig_version'. - Add 'examples' directory to paths.
kivikakk
left a comment
There was a problem hiding this comment.
Awesome! Thank you so much for this. I've noticed a few things that aren't quite working as before, and I don't yet have the Zig context to suggest the corrections myself! 😆
src/main.zig
Outdated
|
|
||
| if (args.positionals[0]) |pos| { | ||
| const markdown = try std.fs.cwd().readFileAlloc(allocator, pos, 1024 * 1024 * 1024); | ||
| const markdown = try std.fs.cwd().readFileAlloc(allocator, pos, MAX_BUFFER_SIZE); |
There was a problem hiding this comment.
This limits the input file to 64KiB.
pub fn readFileAlloc(
dir: Dir,
io: Io,
/// On Windows, should be encoded as [WTF-8](https://wtf-8.codeberg.page/).
/// On WASI, should be encoded as valid UTF-8.
/// On other platforms, an opaque sequence of bytes with no particular encoding.
sub_path: []const u8,
/// Used to allocate the result.
gpa: Allocator,
/// If reached or exceeded, `error.StreamTooLong` is returned instead.
limit: Io.Limit,
) ReadFileAllocError![]u8 {There was a problem hiding this comment.
I agree. The limit is too small. The limit was meant for buffers for streaming. I forgot to use a different value for maximum limits.
| var stdin_reader = std.fs.File.stdin().readerStreaming(&stdin_buf); | ||
| var alloc_writer = std.Io.Writer.Allocating.init(allocator); | ||
| errdefer alloc_writer.deinit(); | ||
|
|
||
| _ = try stdin_reader.interface.streamRemaining(&alloc_writer.writer); | ||
| const markdown = alloc_writer.written(); |
There was a problem hiding this comment.
Something is not going right in the stdin branch:
$ echo hello | zig build run
thread 4416362 panic: Invalid free
/nix/store/k0376vyf5iqm9flh332rm81a7pvw713b-zig-0.15.2/lib/zig/std/heap/debug_allocator.zig:875:49: 0x1010f72cf in free (koino)
if (bucket.canary != config.canary) @panic("Invalid free");
^
/nix/store/k0376vyf5iqm9flh332rm81a7pvw713b-zig-0.15.2/lib/zig/std/mem/Allocator.zig:147:25: 0x1010d9107 in free__anon_22796 (koino)
return a.vtable.free(a.ptr, memory, alignment, ret_addr);
^
/Users/kivikakk/g/koino/src/main.zig:56:29: 0x1010f544f in main (koino)
defer allocator.free(markdown);
^
/nix/store/k0376vyf5iqm9flh332rm81a7pvw713b-zig-0.15.2/lib/zig/std/start.zig:627:37: 0x1010f6033 in main (koino)
const result = root.main() catch |err| {
^
???:?:?: 0x18bec1d53 in ??? (???)
???:?:?: 0x0 in ??? (???)
run
└─ run exe koino failure
error: the following command terminated unexpectedly:
/Users/kivikakk/g/koino/zig-out/bin/koino
Build Summary: 9/11 steps succeeded; 1 failed
run transitive failure
└─ run exe koino failure
error: the following build command failed with exit code 1:
.zig-cache/o/d182dfa2e10cdd8568e99467210dc909/build /nix/store/k0376vyf5iqm9flh332rm81a7pvw713b-zig-0.15.2/bin/zig /nix/store/k0376vyf5iqm9flh332rm81a7pvw713b-zig-0.15.2/lib/zig /Users/kivikakk/g/koino .zig-cache /Users/kivikakk/.cache/zig --seed 0x5010b42d -Z4d21e190086d921a runI am on 0.15.2, so there's possibly a difference here, but worth seeing if you can reproduce.
| try stderr.interface.writeAll("Usage: koino "); | ||
| try clap.usage(&stderr.interface, clap.Help, ¶ms); | ||
| try stderr.interface.writeAll("\n\nOptions:\n"); | ||
| try clap.help(&stderr.interface, clap.Help, ¶ms, .{}); |
There was a problem hiding this comment.
This might need to be flushed? I haven't caught up on the new interface:
$ zig build run -- --help
$There was a problem hiding this comment.
It needs to be flushed. I'll do so.
| fetch-clap: | ||
| zig fetch --save https://github.com/Hejsil/zig-clap/archive/refs/tags/0.11.0.tar.gz | ||
|
|
||
| fetch-htmlentities: | ||
| zig fetch --save git+https://nossa.ee/~talya/htmlentities.zig | ||
|
|
||
| fetch-libpcre: | ||
| zig fetch --save git+https://github.com/kivikakk/libpcre.zig | ||
|
|
||
| fetch-zunicode: | ||
| zig fetch --save git+https://github.com/mishieck/zunicode | ||
|
|
||
| example: | ||
| zig build example |
Yep, no problems! 👍 |
|
What about the failing spec action? I couldn't figure out what goes in |
- Fix [buffer limit issue](kivikakk#63 (comment)). - Fix [invalid free issue](kivikakk#63 (comment)). - [Don't forget to flush](kivikakk#63 (comment))!
|
The spec was only failing since the binary itself was crashing — all looks OK now! |
OK. Great. |
I made the following changes:
Note
I used mishieck/zunicode instead of gernest/zunicode because the repo only accepts contributions from collaborators.