authorchloe caruso <git@paperclover.net> 2024-07-23 04:56:31-07:00
committerchloe caruso <git@paperclover.net> 2024-07-23 04:56:31-07:00
log57d2129baeabbf799abbe58a0c90d035b3134d52
tree67bf454bec8ab9668743242692d63c2b578b39b2
parentb1f58dc720475cbc004da8de483b2aeae4fdb1fc

add automatic version detection from changelog


4 files changed, 32 insertions(+), 9 deletions(-)

CHANGELOG.md+2
......@@ -1,3 +1,5 @@
1## 0.1.5
2
13## 0.1.4
24
35- feat: implement basic struct types (#42)
build.zig+18-4
......@@ -3,7 +3,7 @@ const Build = std.Build;
33const Target = std.Target;
44const OsVersion = Target.Query.OsVersion;
55
6pub fn build(b: *std.Build) void {
6pub fn build(b: *std.Build) !void {
77 b.reference_trace = 20;
88
99 const native_target = b.resolveTargetQuery(.{});
......@@ -40,8 +40,20 @@ pub fn build(b: *std.Build) void {
4040 "Experiment with the Zig self-hosted backends",
4141 ) orelse false;
4242
43 const native_debug = buildWithTarget(b, native_target, .Debug, .none, no_llvm);
44 const main = buildWithTarget(b, target, optimize, tracing, no_llvm);
43 const version = version: {
44 const text = try b.build_root.handle.readFileAlloc(
45 b.graph.arena,
46 "CHANGELOG.md",
47 std.math.maxInt(usize),
48 );
49 const first_header = std.mem.indexOf(u8, text, "## ") orelse unreachable;
50 var tokenizer = std.mem.tokenizeAny(u8, text[first_header + 2 ..], " \t\n");
51 const version_text = tokenizer.next() orelse unreachable;
52 break :version std.SemanticVersion.parse(version_text) catch unreachable;
53 };
54
55 const native_debug = buildWithTarget(b, native_target, .Debug, .none, version, no_llvm);
56 const main = buildWithTarget(b, target, optimize, tracing, version, no_llvm);
4557
4658 b.installArtifact(main.compiler);
4759
......@@ -133,7 +145,7 @@ pub fn build(b: *std.Build) void {
133145 },
134146 ) catch @panic("OOM");
135147
136 const artifacts = buildWithTarget(b, cross_target, .ReleaseSafe, .none, no_llvm);
148 const artifacts = buildWithTarget(b, cross_target, .ReleaseSafe, .none, version, no_llvm);
137149
138150 inline for (.{
139151 .{ artifacts.compiler, "compiler" },
......@@ -173,6 +185,7 @@ fn buildWithTarget(
173185 target: Build.ResolvedTarget,
174186 optimize: std.builtin.OptimizeMode,
175187 tracing: TracingMode,
188 version: std.SemanticVersion,
176189 no_llvm: bool,
177190) Artifacts {
178191 const dep_opts = .{ .target = target, .optimize = optimize };
......@@ -185,6 +198,7 @@ fn buildWithTarget(
185198
186199 // Options
187200 const opts = b.addOptions();
201 opts.addOption(std.SemanticVersion, "version", version);
188202 opts.addOption([]const u8, "tracing", @tagName(tracing));
189203 const opts_mod = opts.createModule();
190204
src/core/js/Link.zig+9-5
......@@ -70,7 +70,10 @@ pub fn linkJsCode(link: *Link, entry_decl: Decl.Index, writer: Writer) !void {
7070 try link.decls.putNoClobber(link.comp.gpa, value, @enumFromInt(gop.index));
7171 }
7272
73 try writer.print("// Language Compiler v0.1.4. Alpha quality software.\n", .{});
73 try writer.writeAll(std.fmt.comptimePrint(
74 "// Language Compiler v{}. Alpha quality software.\n",
75 .{core.version},
76 ));
7477
7578 if (root_function.nodes.len > 1) {
7679 // 2. Print every function decl
......@@ -843,14 +846,15 @@ const Wyhash = std.hash.Wyhash;
843846const log = std.log.scoped(.js_link);
844847const Writer = std.io.AnyWriter;
845848
846const Comp = @import("../Comp.zig");
849const core = @import("../mod.zig");
850const Comp = core.Comp;
847851const Decl = Comp.Decl;
848852
849const Js = @import("Js.zig");
850const Tree = @import("Tree.zig");
853const Js = core.Js;
854const Tree = Js.Tree;
851855const Node = Tree.Node;
852856
853const InternPool = @import("../InternPool.zig");
857const InternPool = core.InternPool;
854858const String = InternPool.String;
855859
856860const tracer = @import("tracer");
src/core/mod.zig+3
......@@ -48,6 +48,9 @@ pub const unicode_props = @import("unicode_props.zig");
4848// The rest of this file is utility functions, which are not specific to any of
4949// the above namespaces. Remember Zig discourages namespaces like `utils`
5050
51/// Language SDK version according to the latest entry in `CHANGELOG.md`
52pub const version = @import("build_options").version;
53
5154/// This is an alternative to `std.debug.assert`, where you want to print some
5255/// debug info instead of "reached unreachable code". Usage is as follows:
5356///