diff options
| author | 2024-02-19 23:38:33 +0200 | |
|---|---|---|
| committer | 2024-02-19 23:38:33 +0200 | |
| commit | d5d5f7f06397d73f497d352f2f38b1a53d932b0d (patch) | |
| tree | 63e34f5f945f4ecf28f844ee02a5a0b7fc581459 /build.zig | |
| parent | Create parent directory if doesn't exist on save (diff) | |
| download | es-d5d5f7f06397d73f497d352f2f38b1a53d932b0d.tar.gz es-d5d5f7f06397d73f497d352f2f38b1a53d932b0d.tar.xz es-d5d5f7f06397d73f497d352f2f38b1a53d932b0d.zip | |
Big update to modern zig
Diffstat (limited to '')
| -rw-r--r-- | build.zig | 38 |
1 files changed, 18 insertions, 20 deletions
| @@ -1,11 +1,12 @@ | |||
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | 2 | ||
| 3 | const Builder = std.build.Builder; | 3 | const Builder = std.Build; |
| 4 | const SemanticVersion = std.SemanticVersion; | 4 | const SemanticVersion = std.SemanticVersion; |
| 5 | 5 | ||
| 6 | const share_prefix = "share/arkta/es/"; | 6 | const share_prefix = "share/arkta/es/"; |
| 7 | 7 | ||
| 8 | const version = "0.3.0"; | 8 | const version = "0.3.0"; |
| 9 | const semver = SemanticVersion.parse(version) catch unreachable; | ||
| 9 | 10 | ||
| 10 | const config = struct { | 11 | const config = struct { |
| 11 | template: []const u8 = @embedFile("es.ini.in"), | 12 | template: []const u8 = @embedFile("es.ini.in"), |
| @@ -18,37 +19,34 @@ const config = struct { | |||
| 18 | }{}; | 19 | }{}; |
| 19 | 20 | ||
| 20 | fn installGeneratedFile(b: *Builder, comptime name: []const u8, data: []const u8) void { | 21 | fn installGeneratedFile(b: *Builder, comptime name: []const u8, data: []const u8) void { |
| 21 | const write_file = b.addWriteFile(name, data); | 22 | const write_files = b.addWriteFiles(); |
| 22 | 23 | const write_file = write_files.add(name, data); | |
| 23 | const write_file_install = b.addInstallFile( | 24 | const write_file_install = b.addInstallFile(write_file, share_prefix ++ name); |
| 24 | write_file.getFileSource(name).?, | 25 | write_file_install.step.dependOn(&write_files.step); |
| 25 | share_prefix ++ name, | ||
| 26 | ); | ||
| 27 | write_file_install.step.dependOn(&write_file.step); | ||
| 28 | 26 | ||
| 29 | b.getInstallStep().dependOn(&write_file_install.step); | 27 | b.getInstallStep().dependOn(&write_file_install.step); |
| 30 | } | 28 | } |
| 31 | 29 | ||
| 32 | pub fn build(b: *Builder) void { | 30 | pub fn build(b: *Builder) void { |
| 33 | const target = b.standardTargetOptions(.{}); | 31 | const target = b.standardTargetOptions(.{}); |
| 34 | const mode = b.standardReleaseOptions(); | 32 | const optimize = b.standardOptimizeOption(.{}); |
| 35 | 33 | ||
| 36 | const options = b.addOptions(); | 34 | const options = b.addOptions(); |
| 37 | options.addOption( | 35 | options.addOption(SemanticVersion, "es_version", semver); |
| 38 | SemanticVersion, | ||
| 39 | "es_version", | ||
| 40 | SemanticVersion.parse(version) catch unreachable, | ||
| 41 | ); | ||
| 42 | options.addOption(bool, "default_hard_tabs", config.default.hard_tabs); | 36 | options.addOption(bool, "default_hard_tabs", config.default.hard_tabs); |
| 43 | options.addOption(usize, "default_line_limit", config.default.line_limit); | 37 | options.addOption(usize, "default_line_limit", config.default.line_limit); |
| 44 | options.addOption(usize, "default_page_overlap", config.default.page_overlap); | 38 | options.addOption(usize, "default_page_overlap", config.default.page_overlap); |
| 45 | options.addOption(usize, "default_tab_stop", config.default.tab_stop); | 39 | options.addOption(usize, "default_tab_stop", config.default.tab_stop); |
| 46 | 40 | ||
| 47 | const exe = b.addExecutable("es", "src/main.zig"); | 41 | const exe = b.addExecutable(.{ |
| 48 | exe.setTarget(target); | 42 | .name = "es", |
| 49 | exe.setBuildMode(mode); | 43 | .version = semver, |
| 50 | exe.addOptions("es-config", options); | 44 | .root_source_file = .{ .path = "src/main.zig" }, |
| 51 | exe.install(); | 45 | .target = target, |
| 46 | .optimize = optimize, | ||
| 47 | }); | ||
| 48 | exe.root_module.addOptions("es-config", options); | ||
| 49 | b.installArtifact(exe); | ||
| 52 | 50 | ||
| 53 | installGeneratedFile( | 51 | installGeneratedFile( |
| 54 | b, | 52 | b, |
| @@ -56,7 +54,7 @@ pub fn build(b: *Builder) void { | |||
| 56 | comptime std.fmt.comptimePrint(config.template, config.default), | 54 | comptime std.fmt.comptimePrint(config.template, config.default), |
| 57 | ); | 55 | ); |
| 58 | 56 | ||
| 59 | const run_cmd = exe.run(); | 57 | const run_cmd = b.addRunArtifact(exe); |
| 60 | run_cmd.step.dependOn(b.getInstallStep()); | 58 | run_cmd.step.dependOn(b.getInstallStep()); |
| 61 | if (b.args) |args| { | 59 | if (b.args) |args| { |
| 62 | run_cmd.addArgs(args); | 60 | run_cmd.addArgs(args); |