From 5188d778befd9ca21a190cd85d9f8fcdd8242d2e Mon Sep 17 00:00:00 2001 From: Rokas Puzonas Date: Sun, 13 Oct 2024 16:47:58 +0300 Subject: [PATCH] update to zig 0.13.0 --- .gitignore | 2 +- README.md | 15 ++++++++ api/enum_string_utils.zig | 2 +- build.zig | 10 +++-- build.zig.zon | 11 ++++-- default.nix | 9 +++-- deps.nix | 78 +++++++++++++++++++++++++++++++++++++++ flake.lock | 8 ++-- flake.nix | 3 +- 9 files changed, 121 insertions(+), 17 deletions(-) create mode 100644 README.md create mode 100644 deps.nix diff --git a/.gitignore b/.gitignore index 658b6ad..5bedc86 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ -zig-cache +.zig-cache zig-out result diff --git a/README.md b/README.md new file mode 100644 index 0000000..72cd59f --- /dev/null +++ b/README.md @@ -0,0 +1,15 @@ +# Artificer + +## Run the CLI + +```shell +zig build run-cli -- +``` + +## Update nix build.zig.zon dependencies + +```shell +nix run github:Cloudef/zig2nix#zon2json-lock -- build.zig.zon +nix run github:Cloudef/zig2nix#zon2nix -- build.zig.zon > ./deps.nix +rm build.zig.zon2json-lock +``` diff --git a/api/enum_string_utils.zig b/api/enum_string_utils.zig index 11fb79a..6928b4f 100644 --- a/api/enum_string_utils.zig +++ b/api/enum_string_utils.zig @@ -6,7 +6,7 @@ pub fn EnumStringUtils(TargetEnum: anytype, str_to_tag_mapping: anytype) type { @compileLog("Mapping is not exhaustive"); } - const EnumMapping = std.ComptimeStringMap(TargetEnum, str_to_tag_mapping); + const EnumMapping = std.StaticStringMap(TargetEnum).initComptime(str_to_tag_mapping); return struct { pub fn fromString(str: []const u8) ?TargetEnum { diff --git a/build.zig b/build.zig index ef65365..6ecd8f0 100644 --- a/build.zig +++ b/build.zig @@ -65,6 +65,9 @@ pub fn build(b: *std.Build) void { const run_step = b.step("run-cli", "Run the CLI"); run_step.dependOn(&run_cmd.step); + + const build_step = b.step("build-cli", "Build the CLI"); + build_step.dependOn(&b.addInstallArtifact(cli, .{}).step); } { @@ -83,15 +86,14 @@ pub fn build(b: *std.Build) void { gui.linkLibrary(raylib_dep.artifact("raylib")); gui.root_module.addImport("raylib", raylib_dep.module("raylib")); - b.installArtifact(gui); - const run_cmd = b.addRunArtifact(gui); - run_cmd.step.dependOn(b.getInstallStep()); - if (b.args) |args| { run_cmd.addArgs(args); } + const build_step = b.step("build-gui", "Build the GUI"); + build_step.dependOn(&b.addInstallArtifact(gui, .{}).step); + const run_step = b.step("run-gui", "Run the GUI"); run_step.dependOn(&run_cmd.step); } diff --git a/build.zig.zon b/build.zig.zon index 2ec7198..99bd785 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -1,15 +1,20 @@ .{ .name = "artificer", .version = "0.1.0", - .minimum_zig_version = "0.12.0", + .minimum_zig_version = "0.13.0", .dependencies = .{ .@"raylib-zig" = .{ .url = "https://github.com/Not-Nik/raylib-zig/archive/43d15b05c2b97cab30103fa2b46cff26e91619ec.tar.gz", .hash = "12204a223b19043e17b79300413d02f60fc8004c0d9629b8d8072831e352a78bf212" }, + // TODO: Use 's2s' from 'ziglibs' when zig 0.14.0 is released + // .s2s = .{ + // .url = "https://github.com/ziglibs/s2s/archive/b30205d5e9204899fb6d0fdf28d00ed4d18fe9c9.tar.gz", + // .hash = "12202c39c98f05041f1052c268132669dbfcda87e4dbb0353cd84a6070924c8ac0e3", + // }, .s2s = .{ - .url = "https://github.com/ziglibs/s2s/archive/b30205d5e9204899fb6d0fdf28d00ed4d18fe9c9.tar.gz", - .hash = "12202c39c98f05041f1052c268132669dbfcda87e4dbb0353cd84a6070924c8ac0e3", + .url = "https://github.com/Deecellar/s2s/archive/4314e9bd2a50cbfd497868a66d758464eefe5076.tar.gz", + .hash = "1220d2cf253817dd18c8486336b68b465e7c98268d3c5449df81736f42d7be0870a8", }, }, .paths = .{""}, diff --git a/default.nix b/default.nix index 9028c7c..c1e977f 100644 --- a/default.nix +++ b/default.nix @@ -1,6 +1,7 @@ { stdenv, - zig_0_12, + zig_0_13, lib, + callPackage, version ? "git", ... }: @@ -10,10 +11,12 @@ stdenv.mkDerivation { src = lib.cleanSource ./.; nativeBuildInputs = [ - zig_0_12.hook + zig_0_13.hook ]; preConfigure = '' - zigBuildFlags="-Dtarget=x86_64-linux --release=fast" + mkdir -p .cache + ln -s ${callPackage ./deps.nix { zig = zig_0_13; }} .cache/p + zigBuildFlags="build-cli -Dtarget=x86_64-linux --release=fast --global-cache-dir $(pwd)/.cache" ''; } diff --git a/deps.nix b/deps.nix new file mode 100644 index 0000000..1173367 --- /dev/null +++ b/deps.nix @@ -0,0 +1,78 @@ +# generated by zon2nix (https://github.com/Cloudef/zig2nix) + +{ lib, linkFarm, fetchurl, fetchgit, runCommandLocal, zig, name ? "zig-packages" }: + +with builtins; +with lib; + +let + unpackZigArtifact = { name, artifact }: runCommandLocal name { + nativeBuildInputs = [ zig ]; + } '' + hash="$(zig fetch --global-cache-dir "$TMPDIR" ${artifact})" + mv "$TMPDIR/p/$hash" "$out" + chmod 755 "$out" + ''; + + fetchZig = { name, url, hash }: let + artifact = fetchurl { inherit url hash; }; + in unpackZigArtifact { inherit name artifact; }; + + fetchGitZig = { name, url, hash }: let + parts = splitString "#" url; + url_base = elemAt parts 0; + url_without_query = elemAt (splitString "?" url_base) 0; + rev_base = elemAt parts 1; + rev = if match "^[a-fA-F0-9]{40}$" rev_base != null then rev_base else "refs/heads/${rev_base}"; + in fetchgit { + inherit name rev hash; + url = url_without_query; + deepClone = false; + }; + + fetchZigArtifact = { name, url, hash }: let + parts = splitString "://" url; + proto = elemAt parts 0; + path = elemAt parts 1; + fetcher = { + "git+http" = fetchGitZig { inherit name hash; url = "http://${path}"; }; + "git+https" = fetchGitZig { inherit name hash; url = "https://${path}"; }; + http = fetchZig { inherit name hash; url = "http://${path}"; }; + https = fetchZig { inherit name hash; url = "https://${path}"; }; + file = unpackZigArtifact { inherit name; artifact = /. + path; }; + }; + in fetcher.${proto}; +in linkFarm name [ + { + name = "12204a223b19043e17b79300413d02f60fc8004c0d9629b8d8072831e352a78bf212"; + path = fetchZigArtifact { + name = "raylib-zig"; + url = "https://github.com/Not-Nik/raylib-zig/archive/43d15b05c2b97cab30103fa2b46cff26e91619ec.tar.gz"; + hash = "sha256-4SQd50vIK9XWMyuj/ymclmvj39BX4dp6ueFrgaEwRYM="; + }; + } + { + name = "1220aa75240ee6459499456ef520ab7e8bddffaed8a5055441da457b198fc4e92b26"; + path = fetchZigArtifact { + name = "raylib"; + url = "https://github.com/raysan5/raylib/archive/5767c4cd059e07355ae5588966d0aee97038a86b.tar.gz"; + hash = "sha256-ijvgBlAfUD71p07Zg/oMzZnneQ95RoiaJXIkNlB26oc="; + }; + } + { + name = "122002d98ca255ec706ef8e5497b3723d6c6e163511761d116dac3aee87747d46cf1"; + path = fetchZigArtifact { + name = "raygui"; + url = "https://github.com/raysan5/raygui/archive/4b3d94f5df6a5a2aa86286350f7e20c0ca35f516.tar.gz"; + hash = "sha256-AjU+fyonXnGTG8ZBMb10ScB3G6iI97eiL9N3anm+r1Q="; + }; + } + { + name = "1220d2cf253817dd18c8486336b68b465e7c98268d3c5449df81736f42d7be0870a8"; + path = fetchZigArtifact { + name = "s2s"; + url = "https://github.com/Deecellar/s2s/archive/4314e9bd2a50cbfd497868a66d758464eefe5076.tar.gz"; + hash = "sha256-3d4O2roswVE62i2PMdik7fea5Rdc0ogDtcHUx9VUiM4="; + }; + } +] \ No newline at end of file diff --git a/flake.lock b/flake.lock index 830f54e..49bf1bc 100644 --- a/flake.lock +++ b/flake.lock @@ -2,16 +2,16 @@ "nodes": { "nixpkgs": { "locked": { - "lastModified": 1722869614, - "narHash": "sha256-7ojM1KSk3mzutD7SkrdSflHXEujPvW1u7QuqWoTLXQU=", + "lastModified": 1728492678, + "narHash": "sha256-9UTxR8eukdg+XZeHgxW5hQA9fIKHsKCdOIUycTryeVw=", "owner": "nixos", "repo": "nixpkgs", - "rev": "883180e6550c1723395a3a342f830bfc5c371f6b", + "rev": "5633bcff0c6162b9e4b5f1264264611e950c8ec7", "type": "github" }, "original": { "owner": "nixos", - "ref": "nixos-24.05", + "ref": "nixos-unstable", "repo": "nixpkgs", "type": "github" } diff --git a/flake.nix b/flake.nix index 49e28c5..c3c2d88 100644 --- a/flake.nix +++ b/flake.nix @@ -2,7 +2,8 @@ description = "Artifacts MMO automation client"; inputs = { - nixpkgs.url = "github:nixos/nixpkgs/nixos-24.05"; + # TODO: Switch off 'unstable' when zig 0.13.0 is released in the stable branch + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; }; outputs = { self, nixpkgs }: