-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmakelinks.zig
90 lines (85 loc) · 2.78 KB
/
makelinks.zig
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
const std = @import("std");
const Platform = struct {
name: []const u8,
ext: []const u8,
arches: []const []const u8,
};
const platforms = [_]Platform{ .{
.name = "windows",
.ext = "zip",
.arches = &[_][]const u8{
"x86_64",
"x86",
"aarch64",
},
}, .{
.name = "macos",
.ext = "tar.xz",
.arches = &[_][]const u8{
"aarch64",
"x86_64",
},
}, .{
.name = "linux",
.ext = "tar.xz",
.arches = &[_][]const u8{
"x86_64",
"x86",
"aarch64",
"riscv64",
"powerpc64le",
"powerpc",
},
} };
pub fn main() !void {
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
const al = arena.allocator();
const cmd_args = try std.process.argsAlloc(al);
if (cmd_args.len != 3) {
try std.io.getStdErr().writer().writeAll("Usage: zig run makelinks.zig -- VERSION ziglang|bazel\n");
std.os.exit(0xff);
}
const version = cmd_args[1];
const kind_str = cmd_args[2];
const kind: enum { ziglang, bazel } = blk: {
if (std.mem.eql(u8, kind_str, "ziglang")) break :blk .ziglang;
if (std.mem.eql(u8, kind_str, "bazel")) break :blk .bazel;
std.log.err("expected 'ziglang' or 'bazel' but got '{s}'", .{kind_str});
std.os.exit(0xff);
};
const stdout = std.io.getStdOut().writer();
try stdout.print("### {s} Summary\n\n", .{version});
try stdout.writeAll("| Platform | Download Link |\n");
try stdout.writeAll("|----------|---------------|\n");
for (platforms) |platform| {
var links_buf = std.ArrayList(u8).init(al);
defer links_buf.deinit();
const links_writer = links_buf.writer();
var prefix: []const u8 = "";
for (platform.arches) |arch| {
try links_writer.writeAll(prefix);
prefix = " | ";
switch (kind) {
.ziglang => try links_writer.print(
"[{[arch]s}](https://ziglang.org/builds/zig-{[name]s}-{[arch]s}-{[version]s}.{[ext]s})",
.{
.arch = arch,
.name = platform.name,
.version = version,
.ext = platform.ext,
},
),
.bazel => try links_writer.print(
"[{[arch]s}](https://mirror.bazel.build/ziglang.org/builds/zig-{[name]s}-{[arch]s}-{[version]s}.{[ext]s})",
.{
.arch = arch,
.name = platform.name,
.version = version,
.ext = platform.ext,
},
),
}
}
try stdout.print("| {s} | {s} |\n", .{ platform.name, links_buf.items });
}
}