-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #98 from floooh/docs-build-step
Move doc generation entirely into Zig code...
- Loading branch information
Showing
5 changed files
with
101 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
.vscode/ | ||
docs | ||
.DS_Store | ||
zig-*/ | ||
.zig-*/ | ||
NUL | ||
*.a | ||
*.a.o |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
//! repackage the autodocs sources.tar to only contain sokol sources | ||
//! (which reduces the size from 13 MBytes to abour 500 KBytes) | ||
const std = @import("std"); | ||
const Allocator = std.mem.Allocator; | ||
|
||
pub fn main() !void { | ||
var arena_state = std.heap.ArenaAllocator.init(std.heap.page_allocator); | ||
defer arena_state.deinit(); | ||
const arena = arena_state.allocator(); | ||
|
||
// parse args | ||
const prefix = try arg(arena, "--prefix"); | ||
const input_dir = try arg(arena, "--input"); | ||
const output_path = try arg(arena, "--output"); | ||
|
||
// iterate over sources.tar file, find relevant files and write to output tar file | ||
const inp_path = try std.fs.path.join(arena, &.{ input_dir, "sources.tar" }); | ||
const inp_file = std.fs.openFileAbsolute(inp_path, .{}) catch |err| { | ||
fatal("failed to open input file '{s}' with {}", .{ inp_path, err }); | ||
}; | ||
defer inp_file.close(); | ||
const outp_file = std.fs.createFileAbsolute(output_path, .{}) catch |err| { | ||
fatal("failed to open output file '{s}' with {}", .{ output_path, err }); | ||
}; | ||
defer outp_file.close(); | ||
|
||
var tar_writer = std.tar.writer(outp_file.writer()); | ||
var file_name_buffer: [1024]u8 = undefined; | ||
var link_name_buffer: [1024]u8 = undefined; | ||
var iter = std.tar.iterator(inp_file.reader(), .{ | ||
.file_name_buffer = &file_name_buffer, | ||
.link_name_buffer = &link_name_buffer, | ||
}); | ||
while (try iter.next()) |tar_item| { | ||
switch (tar_item.kind) { | ||
.file => { | ||
if (std.mem.startsWith(u8, tar_item.name, prefix)) { | ||
try tar_writer.writeFileStream(tar_item.name, tar_item.size, tar_item.reader(), .{ .mode = tar_item.mode }); | ||
} | ||
}, | ||
else => continue, | ||
} | ||
} | ||
return std.process.cleanExit(); | ||
} | ||
|
||
fn fatal(comptime fmt: []const u8, args: anytype) noreturn { | ||
std.log.err(fmt, args); | ||
std.process.exit(5); | ||
} | ||
|
||
fn arg(allocator: Allocator, key: []const u8) ![]const u8 { | ||
var arg_iter = try std.process.argsWithAllocator(allocator); | ||
defer arg_iter.deinit(); | ||
while (arg_iter.next()) |cur| { | ||
if (std.mem.eql(u8, key, cur)) { | ||
const val = arg_iter.next() orelse fatal("expected arg after {s}", .{key}); | ||
return allocator.dupe(u8, val); | ||
} | ||
} | ||
fatal("expected arg {s}", .{key}); | ||
} |