diff options
| author | 2021-12-28 21:14:25 +0200 | |
|---|---|---|
| committer | 2021-12-28 21:14:25 +0200 | |
| commit | 096995c04c4fd3378a537ea90ec17a461c230f6a (patch) | |
| tree | aec61d74dbb7c2098d68dcc1ab8870a2e70f70d2 | |
| parent | Added more build-time config (diff) | |
| download | es-096995c04c4fd3378a537ea90ec17a461c230f6a.tar.gz es-096995c04c4fd3378a537ea90ec17a461c230f6a.tar.xz es-096995c04c4fd3378a537ea90ec17a461c230f6a.zip | |
Added a generated default config file
| -rw-r--r-- | build.zig | 35 | ||||
| -rw-r--r-- | es.ini.in | 7 |
2 files changed, 39 insertions, 3 deletions
| @@ -3,8 +3,31 @@ const std = @import("std"); | |||
| 3 | const Builder = std.build.Builder; | 3 | const Builder = std.build.Builder; |
| 4 | const SemanticVersion = std.SemanticVersion; | 4 | const SemanticVersion = std.SemanticVersion; |
| 5 | 5 | ||
| 6 | const share_prefix = "share/arkta/es/"; | ||
| 7 | |||
| 6 | const version = "0.3.0"; | 8 | const version = "0.3.0"; |
| 7 | 9 | ||
| 10 | const config = struct { | ||
| 11 | template: []const u8 = @embedFile("es.ini.in"), | ||
| 12 | default: struct { | ||
| 13 | line_limit: usize = 100, | ||
| 14 | page_overlap: usize = 2, | ||
| 15 | tab_stop: usize = 8, | ||
| 16 | } = .{}, | ||
| 17 | }{}; | ||
| 18 | |||
| 19 | fn installGeneratedFile(b: *Builder, comptime name: []const u8, data: []const u8) void { | ||
| 20 | const write_file = b.addWriteFile(name, data); | ||
| 21 | |||
| 22 | const write_file_install = b.addInstallFile( | ||
| 23 | write_file.getFileSource(name).?, | ||
| 24 | share_prefix ++ name, | ||
| 25 | ); | ||
| 26 | write_file_install.step.dependOn(&write_file.step); | ||
| 27 | |||
| 28 | b.getInstallStep().dependOn(&write_file_install.step); | ||
| 29 | } | ||
| 30 | |||
| 8 | pub fn build(b: *Builder) void { | 31 | pub fn build(b: *Builder) void { |
| 9 | const target = b.standardTargetOptions(.{}); | 32 | const target = b.standardTargetOptions(.{}); |
| 10 | const mode = b.standardReleaseOptions(); | 33 | const mode = b.standardReleaseOptions(); |
| @@ -15,9 +38,9 @@ pub fn build(b: *Builder) void { | |||
| 15 | "es_version", | 38 | "es_version", |
| 16 | SemanticVersion.parse(version) catch unreachable, | 39 | SemanticVersion.parse(version) catch unreachable, |
| 17 | ); | 40 | ); |
| 18 | options.addOption(usize, "default_line_limit", 100); | 41 | options.addOption(usize, "default_line_limit", config.default.line_limit); |
| 19 | options.addOption(usize, "default_page_overlap", 2); | 42 | options.addOption(usize, "default_page_overlap", config.default.page_overlap); |
| 20 | options.addOption(usize, "default_tab_stop", 8); | 43 | options.addOption(usize, "default_tab_stop", config.default.tab_stop); |
| 21 | 44 | ||
| 22 | const exe = b.addExecutable("es", "src/main.zig"); | 45 | const exe = b.addExecutable("es", "src/main.zig"); |
| 23 | exe.setTarget(target); | 46 | exe.setTarget(target); |
| @@ -25,6 +48,12 @@ pub fn build(b: *Builder) void { | |||
| 25 | exe.addOptions("es-config", options); | 48 | exe.addOptions("es-config", options); |
| 26 | exe.install(); | 49 | exe.install(); |
| 27 | 50 | ||
| 51 | installGeneratedFile( | ||
| 52 | b, | ||
| 53 | "es.ini", | ||
| 54 | comptime std.fmt.comptimePrint(config.template, config.default), | ||
| 55 | ); | ||
| 56 | |||
| 28 | const run_cmd = exe.run(); | 57 | const run_cmd = exe.run(); |
| 29 | run_cmd.step.dependOn(b.getInstallStep()); | 58 | run_cmd.step.dependOn(b.getInstallStep()); |
| 30 | if (b.args) |args| { | 59 | if (b.args) |args| { |
diff --git a/es.ini.in b/es.ini.in new file mode 100644 index 0000000..4de9e2a --- /dev/null +++ b/es.ini.in | |||
| @@ -0,0 +1,7 @@ | |||
| 1 | # This is the default es.ini config. | ||
| 2 | # | ||
| 3 | # Copy this config to ~/.config/arkta/es/es.ini to modify it. | ||
| 4 | |||
| 5 | line_limit = {[line_limit]} | ||
| 6 | page_overlap = {[page_overlap]} | ||
| 7 | tab_stop = {[tab_stop]} | ||