authorgravatar for me@paperdave.netdave caruso <me@paperdave.net> 2024-07-23 04:56:31-07:00
committergravatar for me@paperdave.netdave caruso <me@paperdave.net> 2024-07-23 04:56:31-07:00
logd6a1a0803f6a9ecace8ff0c23d4ad54f65670bde
tree67bf454bec8ab9668743242692d63c2b578b39b2
parent7514b71286a8659c2917b78acf7f36b5da7e9657
signature Commit is signed but in an unrecognized format.

add automatic version detection from changelog


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

CHANGELOG.md+2
...@@ -1,3 +1,5 @@...@@ -1,3 +1,5 @@
1## 0.1.5
2
1## 0.1.43## 0.1.4
24
3- feat: implement basic struct types (#42)5- feat: implement basic struct types (#42)
build.zig+18-4
...@@ -3,7 +3,7 @@ const Build = std.Build;...@@ -3,7 +3,7 @@ const Build = std.Build;
3const Target = std.Target;3const Target = std.Target;
4const OsVersion = Target.Query.OsVersion;4const OsVersion = Target.Query.OsVersion;
55
6pub fn build(b: *std.Build) void {6pub fn build(b: *std.Build) !void {
7 b.reference_trace = 20;7 b.reference_trace = 20;
88
9 const native_target = b.resolveTargetQuery(.{});9 const native_target = b.resolveTargetQuery(.{});
...@@ -40,8 +40,20 @@ pub fn build(b: *std.Build) void {...@@ -40,8 +40,20 @@ pub fn build(b: *std.Build) void {
40 "Experiment with the Zig self-hosted backends",40 "Experiment with the Zig self-hosted backends",
41 ) orelse false;41 ) orelse false;
4242
43 const native_debug = buildWithTarget(b, native_target, .Debug, .none, no_llvm);43 const version = version: {
44 const main = buildWithTarget(b, target, optimize, tracing, no_llvm);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
46 b.installArtifact(main.compiler);58 b.installArtifact(main.compiler);
4759
...@@ -133,7 +145,7 @@ pub fn build(b: *std.Build) void {...@@ -133,7 +145,7 @@ pub fn build(b: *std.Build) void {
133 },145 },
134 ) catch @panic("OOM");146 ) 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
138 inline for (.{150 inline for (.{
139 .{ artifacts.compiler, "compiler" },151 .{ artifacts.compiler, "compiler" },
...@@ -173,6 +185,7 @@ fn buildWithTarget(...@@ -173,6 +185,7 @@ fn buildWithTarget(
173 target: Build.ResolvedTarget,185 target: Build.ResolvedTarget,
174 optimize: std.builtin.OptimizeMode,186 optimize: std.builtin.OptimizeMode,
175 tracing: TracingMode,187 tracing: TracingMode,
188 version: std.SemanticVersion,
176 no_llvm: bool,189 no_llvm: bool,
177) Artifacts {190) Artifacts {
178 const dep_opts = .{ .target = target, .optimize = optimize };191 const dep_opts = .{ .target = target, .optimize = optimize };
...@@ -185,6 +198,7 @@ fn buildWithTarget(...@@ -185,6 +198,7 @@ fn buildWithTarget(
185198
186 // Options199 // Options
187 const opts = b.addOptions();200 const opts = b.addOptions();
201 opts.addOption(std.SemanticVersion, "version", version);
188 opts.addOption([]const u8, "tracing", @tagName(tracing));202 opts.addOption([]const u8, "tracing", @tagName(tracing));
189 const opts_mod = opts.createModule();203 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 {...@@ -70,7 +70,10 @@ pub fn linkJsCode(link: *Link, entry_decl: Decl.Index, writer: Writer) !void {
70 try link.decls.putNoClobber(link.comp.gpa, value, @enumFromInt(gop.index));70 try link.decls.putNoClobber(link.comp.gpa, value, @enumFromInt(gop.index));
71 }71 }
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
75 if (root_function.nodes.len > 1) {78 if (root_function.nodes.len > 1) {
76 // 2. Print every function decl79 // 2. Print every function decl
...@@ -843,14 +846,15 @@ const Wyhash = std.hash.Wyhash;...@@ -843,14 +846,15 @@ const Wyhash = std.hash.Wyhash;
843const log = std.log.scoped(.js_link);846const log = std.log.scoped(.js_link);
844const Writer = std.io.AnyWriter;847const Writer = std.io.AnyWriter;
845848
846const Comp = @import("../Comp.zig");849const core = @import("../mod.zig");
850const Comp = core.Comp;
847const Decl = Comp.Decl;851const Decl = Comp.Decl;
848852
849const Js = @import("Js.zig");853const Js = core.Js;
850const Tree = @import("Tree.zig");854const Tree = Js.Tree;
851const Node = Tree.Node;855const Node = Tree.Node;
852856
853const InternPool = @import("../InternPool.zig");857const InternPool = core.InternPool;
854const String = InternPool.String;858const String = InternPool.String;
855859
856const tracer = @import("tracer");860const tracer = @import("tracer");
src/core/mod.zig+3
...@@ -48,6 +48,9 @@ pub const unicode_props = @import("unicode_props.zig");...@@ -48,6 +48,9 @@ pub const unicode_props = @import("unicode_props.zig");
48// The rest of this file is utility functions, which are not specific to any of48// The rest of this file is utility functions, which are not specific to any of
49// the above namespaces. Remember Zig discourages namespaces like `utils`49// 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
51/// This is an alternative to `std.debug.assert`, where you want to print some54/// This is an alternative to `std.debug.assert`, where you want to print some
52/// debug info instead of "reached unreachable code". Usage is as follows:55/// debug info instead of "reached unreachable code". Usage is as follows:
53///56///