Compare commits

...

9 Commits
dev ... ci-dev

Author SHA1 Message Date
LeRoyce Pearson 4da048648f upload x86_86-linux-gnu artifact
/ build-dist (push) Successful in 1m17s Details
2024-05-30 00:02:11 -06:00
LeRoyce Pearson a47d3a56e0 split each binary into it's own upload step
/ build-dist (push) Successful in 1m21s Details
2024-05-29 23:50:31 -06:00
LeRoyce Pearson 3d01e0e7e0 use wildcard
/ build-x86_64-linux-gnu (push) Successful in 1m19s Details
2024-05-29 23:05:18 -06:00
LeRoyce Pearson 5c4a10bf26 feat: build.zig: add step to build for all platforms
/ build-x86_64-linux-gnu (push) Successful in 1m10s Details
2024-05-29 22:57:00 -06:00
LeRoyce Pearson 026d835803 fix: use upload-artifact v3
/ build-x86_64-linux-gnu (push) Successful in 58s Details
2024-05-29 22:16:33 -06:00
LeRoyce Pearson 20c6c18079 feat: add version info and upload built artifacts
/ build-x86_64-linux-gnu (push) Failing after 1m3s Details
2024-05-29 22:08:57 -06:00
LeRoyce Pearson 7e434c2bc2 disable cache for setup-zig and checkout repository
/ test (push) Successful in 58s Details
The cache wasn't working and the timeout took way too long. Redownloading
zig every time it is, then.
2024-05-29 21:20:07 -06:00
LeRoyce Pearson d70f48afda feat: setup zig and run `zig build`
/ test (push) Failing after 9m34s Details
2024-05-29 21:08:40 -06:00
LeRoyce Pearson 8846d2cb87 feat: add demo forgejo workflow
/ test (push) Successful in 33s Details
2024-05-29 20:20:17 -06:00
3 changed files with 170 additions and 48 deletions

View File

@ -0,0 +1,38 @@
on: [push]
jobs:
build-dist:
runs-on: docker
steps:
- name: Setup Zig
uses: https://git.samsehu.perli.casa/Twins/action-setup-zig@v2.2.0
with:
version: 0.12.0
cache: false
- uses: actions/checkout@v4
- name: zig build dist
run: zig build dist --summary all -Doptimize=ReleaseSmall
- name: upload-artifact x86_64-linux-gnu
uses: https://code.forgejo.org/forgejo/upload-artifact@v3
with:
name: seizer-solitaire.x86_64-linux-gnu
path: zig-out/bin/x86_64-linux-gnu/seizer-solitaire
- name: upload-artifact aarch64-linux-gnu
uses: https://code.forgejo.org/forgejo/upload-artifact@v3
with:
name: seizer-solitaire.aarch64-linux-gnu
path: zig-out/bin/aarch64-linux-gnu/seizer-solitaire
- name: upload-artifact aarch64-linux-gnu
uses: https://code.forgejo.org/forgejo/upload-artifact@v3
with:
name: seizer-solitaire.arm-linux-gnueabihf
path: zig-out/bin/arm-linux-gnueabihf/seizer-solitaire
- name: upload-artifact aarch64-linux-gnu
uses: https://code.forgejo.org/forgejo/upload-artifact@v3
with:
name: seizer-solitaire.wasm32-wasi-none
path: zig-out/bin/wasm32-wasi-none/seizer-solitaire
- name: upload-artifact aarch64-linux-gnu
uses: https://code.forgejo.org/forgejo/upload-artifact@v3
with:
name: seizer-solitaire.html
path: zig-out/www/seizer-solitaire.html

169
build.zig
View File

@ -1,46 +1,18 @@
const std = @import("std"); const std = @import("std");
const mem = std.mem;
const seizer_solitaire_version = std.SemanticVersion{ .major = 0, .minor = 1, .patch = 0 };
// Although this function looks imperative, note that its job is to // Although this function looks imperative, note that its job is to
// declaratively construct a build graph that will be executed by an external // declaratively construct a build graph that will be executed by an external
// runner. // runner.
pub fn build(b: *std.Build) void { pub fn build(b: *std.Build) !void {
// Standard target options allows the person running `zig build` to choose
// what target to build for. Here we do not override the defaults, which
// means any target is allowed, and the default is native. Other options
// for restricting supported target set are available.
const target = b.standardTargetOptions(.{}); const target = b.standardTargetOptions(.{});
// Standard optimization options allow the person running `zig build` to select
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. Here we do not
// set a preferred release mode, allowing the user to decide how to optimize.
const optimize = b.standardOptimizeOption(.{}); const optimize = b.standardOptimizeOption(.{});
const seizer = b.dependency("seizer", .{ const version = try getVersionString(b);
.target = target,
.optimize = optimize,
});
const exe = b.addExecutable(.{ const exe = try addSeizerSolitaireExe(b, b.getInstallStep(), .{ .target = target, .optimize = optimize, .version = version });
.name = "seizer-solitaire",
.root_source_file = .{ .path = "src/main.zig" },
.target = target,
.optimize = optimize,
});
exe.root_module.addImport("seizer", seizer.module("seizer"));
b.installArtifact(exe);
// additionally generate an HTML file with the wasm module embedded when we use the wasi target
if (target.result.os.tag == .wasi) {
exe.wasi_exec_model = .reactor;
const bundle_webpage_exe = seizer.artifact("bundle-webpage");
const bundle_webpage = b.addRunArtifact(bundle_webpage_exe);
bundle_webpage.addArtifactArg(exe);
const install_html = b.addInstallFile(bundle_webpage.captureStdOut(), "www/seizer-solitaire.html");
b.getInstallStep().dependOn(&install_html.step);
}
const run_cmd = b.addRunArtifact(exe); const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(b.getInstallStep()); run_cmd.step.dependOn(b.getInstallStep());
@ -52,18 +24,119 @@ pub fn build(b: *std.Build) void {
const run_step = b.step("run", "Run the app"); const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step); run_step.dependOn(&run_cmd.step);
const exe_unit_tests = b.addTest(.{ // build for all targets
.root_source_file = .{ .path = "src/main.zig" }, const dist_step = b.step("dist", "Build binaries for all targets");
.target = target, _ = try addSeizerSolitaireExe(b, dist_step, .{ .optimize = optimize, .version = version, .target = b.resolveTargetQuery(.{ .cpu_arch = .x86_64, .os_tag = .linux, .abi = .gnu }) });
.optimize = optimize, _ = try addSeizerSolitaireExe(b, dist_step, .{ .optimize = optimize, .version = version, .target = b.resolveTargetQuery(.{ .cpu_arch = .arm, .os_tag = .linux, .abi = .gnueabihf }) });
}); _ = try addSeizerSolitaireExe(b, dist_step, .{ .optimize = optimize, .version = version, .target = b.resolveTargetQuery(.{ .cpu_arch = .aarch64, .os_tag = .linux, .abi = .gnu }) });
exe_unit_tests.root_module.addImport("seizer", seizer.module("seizer")); _ = try addSeizerSolitaireExe(b, dist_step, .{ .optimize = optimize, .version = version, .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .wasi, .abi = .none }) });
}
const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests);
pub fn addSeizerSolitaireExe(b: *std.Build, install_step: *std.Build.Step, options: struct {
// Similar to creating the run step earlier, this exposes a `test` step to target: std.Build.ResolvedTarget,
// the `zig build --help` menu, providing a way for the user to request optimize: std.builtin.OptimizeMode,
// running the unit tests. version: [:0]const u8,
const test_step = b.step("test", "Run unit tests"); }) !*std.Build.Step.Compile {
test_step.dependOn(&run_exe_unit_tests.step); const seizer = b.dependency("seizer", .{
.target = options.target,
.optimize = options.optimize,
});
const exe = b.addExecutable(.{
.name = "seizer-solitaire",
.root_source_file = .{ .path = "src/main.zig" },
.target = options.target,
.optimize = options.optimize,
});
exe.root_module.addImport("seizer", seizer.module("seizer"));
const install_exe = b.addInstallArtifact(exe, .{ .dest_sub_path = b.fmt("{s}/{s}", .{ try options.target.result.linuxTriple(b.allocator), exe.name }) });
install_step.dependOn(&install_exe.step);
// additionally generate an HTML file with the wasm module embedded when we use the wasi target
if (options.target.result.os.tag == .wasi) {
exe.wasi_exec_model = .reactor;
const bundle_webpage_exe = seizer.artifact("bundle-webpage");
const bundle_webpage = b.addRunArtifact(bundle_webpage_exe);
bundle_webpage.addArtifactArg(exe);
const install_html = b.addInstallFile(bundle_webpage.captureStdOut(), "www/seizer-solitaire.html");
install_step.dependOn(&install_html.step);
}
// code to add version to binary, stolen from the zig language's build.zig
const exe_options = b.addOptions();
exe.root_module.addOptions("build_options", exe_options);
exe_options.addOption([:0]const u8, "version", options.version);
return exe;
}
pub fn getVersionString(b: *std.Build) ![:0]const u8 {
const opt_version_string = b.option([]const u8, "version-string", "Override version string. Default is to find out with git.");
if (opt_version_string) |version| {
return try b.allocator.dupeZ(u8, version);
}
if (!std.process.can_spawn) {
std.debug.print("error: version info cannot be retrieved from git. Zig version must be provided using -Dversion-string\n", .{});
std.process.exit(1);
}
const version_string = b.fmt("{d}.{d}.{d}", .{ seizer_solitaire_version.major, seizer_solitaire_version.minor, seizer_solitaire_version.patch });
var code: u8 = undefined;
const git_describe_untrimmed = b.runAllowFail(&[_][]const u8{
"git",
"-C",
b.build_root.path orelse ".",
"describe",
"--match",
"*.*.*",
"--tags",
"--abbrev=9",
}, &code, .Ignore) catch {
return try b.allocator.dupeZ(u8, version_string);
};
const git_describe = mem.trim(u8, git_describe_untrimmed, " \n\r");
switch (mem.count(u8, git_describe, "-")) {
0 => {
// Tagged release version (e.g. 0.10.0).
if (!mem.eql(u8, git_describe, version_string)) {
std.debug.print("Zig version '{s}' does not match Git tag '{s}'\n", .{ version_string, git_describe });
std.process.exit(1);
}
return try b.allocator.dupeZ(u8, version_string);
},
2 => {
// Untagged development build (e.g. 0.10.0-dev.2025+ecf0050a9).
var it = mem.splitScalar(u8, git_describe, '-');
const tagged_ancestor = it.first();
const commit_height = it.next().?;
const commit_id = it.next().?;
const ancestor_ver = try std.SemanticVersion.parse(tagged_ancestor);
if (seizer_solitaire_version.order(ancestor_ver) != .gt) {
std.debug.print("version '{}' must be greater than tagged ancestor '{}'\n", .{ seizer_solitaire_version, ancestor_ver });
std.process.exit(1);
}
// Check that the commit hash is prefixed with a 'g' (a Git convention).
if (commit_id.len < 1 or commit_id[0] != 'g') {
std.debug.print("Unexpected `git describe` output: {s}\n", .{git_describe});
return try b.allocator.dupeZ(u8, version_string);
}
// The version is reformatted in accordance with the https://semver.org specification.
const formatted_version = b.fmt("{s}-dev.{s}+{s}", .{ version_string, commit_height, commit_id[1..] });
return try b.allocator.dupeZ(u8, formatted_version);
},
else => {
std.debug.print("Unexpected `git describe` output: {s}\n", .{git_describe});
return try b.allocator.dupeZ(u8, version_string);
},
}
} }

View File

@ -259,6 +259,16 @@ fn render(window: seizer.Window) !void {
@floor((canvas.window_size[1] - space_taken_by_board[1]) / 2), @floor((canvas.window_size[1] - space_taken_by_board[1]) / 2),
}; };
_ = canvas.printText(
.{
0,
canvas.window_size[1],
},
"{s}",
.{build_options.version},
.{ .@"align" = .left, .baseline = .bottom, .scale = scalef },
);
if (win_count) |w| { if (win_count) |w| {
_ = canvas.printText( _ = canvas.printText(
.{ .{
@ -898,6 +908,7 @@ const Snapshot = struct {
const DeckSprites = assets.DeckSprites; const DeckSprites = assets.DeckSprites;
const Card = assets.Card; const Card = assets.Card;
const build_options = @import("build_options");
const assets = @import("./assets.zig"); const assets = @import("./assets.zig");
const builtin = @import("builtin"); const builtin = @import("builtin");
const seizer = @import("seizer"); const seizer = @import("seizer");