From 3f596a6dc9f62676d9d1c73edc594e458d415d98 Mon Sep 17 00:00:00 2001 From: Fabien Freling Date: Mon, 9 Oct 2023 14:03:56 +0200 Subject: [PATCH 1/3] use zig overlay --- flake.lock | 111 ++++++++++++++++++++++++++++++++++++++++++----------- flake.nix | 73 +++++++++++++++++------------------ 2 files changed, 124 insertions(+), 60 deletions(-) diff --git a/flake.lock b/flake.lock index 135a36e..842cd79 100644 --- a/flake.lock +++ b/flake.lock @@ -1,30 +1,61 @@ { "nodes": { - "flake-parts": { - "inputs": { - "nixpkgs-lib": "nixpkgs-lib" - }, + "flake-compat": { + "flake": false, "locked": { - "lastModified": 1693611461, - "narHash": "sha256-aPODl8vAgGQ0ZYFIRisxYG5MOGSkIczvu2Cd8Gb9+1Y=", - "owner": "hercules-ci", - "repo": "flake-parts", - "rev": "7f53fdb7bdc5bb237da7fefef12d099e4fd611ca", + "lastModified": 1673956053, + "narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9", "type": "github" }, "original": { - "owner": "hercules-ci", - "repo": "flake-parts", + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1694529238, + "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "ff7b65b44d01cf9ba6a71320833626af21126384", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "locked": { + "lastModified": 1659877975, + "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", "type": "github" } }, "nixpkgs": { "locked": { - "lastModified": 1695806987, - "narHash": "sha256-fX5kGs66NZIxCMcpAGIpxuftajHL8Hil1vjHmjjl118=", + "lastModified": 1696725822, + "narHash": "sha256-B7uAOS7TkLlOg1aX01rQlYbydcyB6ZnLJSfaYbKVww8=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "f3dab3509afca932f3f4fd0908957709bb1c1f57", + "rev": "5aabb5780a11c500981993d49ee93cfa6df9307b", "type": "github" }, "original": { @@ -32,28 +63,62 @@ "type": "indirect" } }, - "nixpkgs-lib": { + "nixpkgs_2": { "locked": { - "dir": "lib", - "lastModified": 1693471703, - "narHash": "sha256-0l03ZBL8P1P6z8MaSDS/MvuU8E75rVxe5eE1N6gxeTo=", + "lastModified": 1689088367, + "narHash": "sha256-Y2tl2TlKCWEHrOeM9ivjCLlRAKH3qoPUE/emhZECU14=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "3e52e76b70d5508f3cec70b882a29199f4d1ee85", + "rev": "5c9ddb86679c400d6b7360797b8a22167c2053f8", "type": "github" }, "original": { - "dir": "lib", "owner": "NixOS", - "ref": "nixos-unstable", + "ref": "release-23.05", "repo": "nixpkgs", "type": "github" } }, "root": { "inputs": { - "flake-parts": "flake-parts", - "nixpkgs": "nixpkgs" + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "zig": "zig" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "zig": { + "inputs": { + "flake-compat": "flake-compat", + "flake-utils": "flake-utils_2", + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1696810944, + "narHash": "sha256-yvt223HLZlAJa/u4uzT5aw3ph2bifto/KfU2k+eX+jg=", + "owner": "mitchellh", + "repo": "zig-overlay", + "rev": "6dc03885321cc8aad6356c847148eb40e167f9fb", + "type": "github" + }, + "original": { + "owner": "mitchellh", + "repo": "zig-overlay", + "type": "github" } } }, diff --git a/flake.nix b/flake.nix index bef0b12..f1f53ba 100644 --- a/flake.nix +++ b/flake.nix @@ -1,48 +1,47 @@ { description = "FabApp"; + # Inspired by https://github.com/mitchellh/zig-objc/blob/main/flake.nix inputs = { # take unstable if not specified # nixpkgs.url = "github:nixos/nixpkgs/release-23.05"; - flake-parts.url = "github:hercules-ci/flake-parts"; + # nixpkgs.url = "github:NixOS/nixpkgs/unstable"; + flake-utils.url = "github:numtide/flake-utils"; + zig.url = "github:mitchellh/zig-overlay"; }; - outputs = inputs@{ flake-parts, nixpkgs, ... }: - flake-parts.lib.mkFlake { inherit inputs; } { - flake = { - # Put your original flake attributes here. - }; + outputs = { + self, + nixpkgs, + flake-utils, + ... + } @ inputs: let + overlays = [ + (final: prev: { + zigpkgs = inputs.zig.packages.${prev.system}; + }) + ]; + systems = ["x86_64-linux"]; + in + flake-utils.lib.eachSystem systems ( + system: let + pkgs = import nixpkgs {inherit overlays system;}; + in rec { + devShells.default = pkgs.mkShell { + nativeBuildInputs = with pkgs; [ + zigpkgs.master + zls + emscripten + ]; + buildInputs = with pkgs; [ + sqlite - systems = [ "x86_64-linux" ]; - - # https://flake.parts/module-arguments.html#persystem-module-parameters - perSystem = { pkgs, system, ... }: { - _module.args.pkgs = import nixpkgs { - inherit system; - # config.allowUnfree = true; + # Linux graphical deps + xorg.libX11 + libGL + ]; }; - - devShells.default = with pkgs; - mkShell { - buildInputs = [ - sqlite - - # Zig / webAssembly impl. - zig - zls - emscripten - - # Tools - nixfmt - - # Linux graphical deps - xorg.libX11 - libGL - ]; - - }; - - formatter = pkgs.nixfmt; - }; - }; + formatter = pkgs.alejandra; + } + ); } From 3216292d08152261b22f667566b9a6e032ef32e7 Mon Sep 17 00:00:00 2001 From: Fabien Freling Date: Fri, 13 Oct 2023 15:48:51 +0200 Subject: [PATCH 2/3] add zig overlay Unfortunately, this is not working because of an issue with graphical dependencies. --- flake.lock | 113 +++++++++++++++++++++++++++++++++++++++++++++++------ flake.nix | 27 +++++++++---- 2 files changed, 119 insertions(+), 21 deletions(-) diff --git a/flake.lock b/flake.lock index 135a36e..83db597 100644 --- a/flake.lock +++ b/flake.lock @@ -1,15 +1,31 @@ { "nodes": { + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1673956053, + "narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, "flake-parts": { "inputs": { "nixpkgs-lib": "nixpkgs-lib" }, "locked": { - "lastModified": 1693611461, - "narHash": "sha256-aPODl8vAgGQ0ZYFIRisxYG5MOGSkIczvu2Cd8Gb9+1Y=", + "lastModified": 1696343447, + "narHash": "sha256-B2xAZKLkkeRFG5XcHHSXXcP7To9Xzr59KXeZiRf4vdQ=", "owner": "hercules-ci", "repo": "flake-parts", - "rev": "7f53fdb7bdc5bb237da7fefef12d099e4fd611ca", + "rev": "c9afaba3dfa4085dbd2ccb38dfade5141e33d9d4", "type": "github" }, "original": { @@ -18,28 +34,45 @@ "type": "github" } }, + "flake-utils": { + "locked": { + "lastModified": 1659877975, + "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, "nixpkgs": { "locked": { - "lastModified": 1695806987, - "narHash": "sha256-fX5kGs66NZIxCMcpAGIpxuftajHL8Hil1vjHmjjl118=", - "owner": "NixOS", + "lastModified": 1696983906, + "narHash": "sha256-L7GyeErguS7Pg4h8nK0wGlcUTbfUMDu+HMf1UcyP72k=", + "owner": "nixos", "repo": "nixpkgs", - "rev": "f3dab3509afca932f3f4fd0908957709bb1c1f57", + "rev": "bd1cde45c77891214131cbbea5b1203e485a9d51", "type": "github" }, "original": { - "id": "nixpkgs", - "type": "indirect" + "owner": "nixos", + "ref": "nixos-23.05", + "repo": "nixpkgs", + "type": "github" } }, "nixpkgs-lib": { "locked": { "dir": "lib", - "lastModified": 1693471703, - "narHash": "sha256-0l03ZBL8P1P6z8MaSDS/MvuU8E75rVxe5eE1N6gxeTo=", + "lastModified": 1696019113, + "narHash": "sha256-X3+DKYWJm93DRSdC5M6K5hLqzSya9BjibtBsuARoPco=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "3e52e76b70d5508f3cec70b882a29199f4d1ee85", + "rev": "f5892ddac112a1e9b3612c39af1b72987ee5783a", "type": "github" }, "original": { @@ -50,10 +83,64 @@ "type": "github" } }, + "nixpkgs-unstable": { + "locked": { + "lastModified": 1697009197, + "narHash": "sha256-viVRhBTFT8fPJTb1N3brQIpFZnttmwo3JVKNuWRVc3s=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "01441e14af5e29c9d27ace398e6dd0b293e25a54", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1689088367, + "narHash": "sha256-Y2tl2TlKCWEHrOeM9ivjCLlRAKH3qoPUE/emhZECU14=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "5c9ddb86679c400d6b7360797b8a22167c2053f8", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "release-23.05", + "repo": "nixpkgs", + "type": "github" + } + }, "root": { "inputs": { "flake-parts": "flake-parts", - "nixpkgs": "nixpkgs" + "nixpkgs": "nixpkgs", + "nixpkgs-unstable": "nixpkgs-unstable", + "zig-overlay": "zig-overlay" + } + }, + "zig-overlay": { + "inputs": { + "flake-compat": "flake-compat", + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1697198920, + "narHash": "sha256-dtaoksNoOMC3H+FDF3cK+bP+jYvJokYBAFvzCALLDYk=", + "owner": "mitchellh", + "repo": "zig-overlay", + "rev": "2d779a7657e346323ab048b218994dbdc42655d7", + "type": "github" + }, + "original": { + "owner": "mitchellh", + "repo": "zig-overlay", + "type": "github" } } }, diff --git a/flake.nix b/flake.nix index bef0b12..823a8df 100644 --- a/flake.nix +++ b/flake.nix @@ -2,8 +2,9 @@ description = "FabApp"; inputs = { - # take unstable if not specified - # nixpkgs.url = "github:nixos/nixpkgs/release-23.05"; + nixpkgs.url = "github:nixos/nixpkgs/nixos-23.05"; + nixpkgs-unstable.url = "github:nixos/nixpkgs/nixpkgs-unstable"; + zig-overlay.url = "github:mitchellh/zig-overlay"; flake-parts.url = "github:hercules-ci/flake-parts"; }; @@ -17,11 +18,18 @@ # https://flake.parts/module-arguments.html#persystem-module-parameters perSystem = { pkgs, system, ... }: { - _module.args.pkgs = import nixpkgs { + # We need unstable for Zig + _module.args.pkgs = import inputs.nixpkgs-unstable { inherit system; - # config.allowUnfree = true; + # https://flake.parts/overlays + overlays = [ + inputs.zig-overlay.overlays.default + ]; + config = { }; }; + formatter = pkgs.nixfmt; + devShells.default = with pkgs; mkShell { buildInputs = [ @@ -29,20 +37,23 @@ # Zig / webAssembly impl. zig + # zigpkgs."master" # Issue with X11/GL libraries zls emscripten - # Tools - nixfmt - # Linux graphical deps xorg.libX11 libGL + # xorg.libXcursor + # xorg.libXi + # xorg.libXext + # xorg.libXrandr + # xorg.libXinerama + # libGLU ]; }; - formatter = pkgs.nixfmt; }; }; } From c51423874b9d230ac61ffd70dd2913bbfe06daea Mon Sep 17 00:00:00 2001 From: Fabien Freling Date: Fri, 13 Oct 2023 15:53:58 +0200 Subject: [PATCH 3/3] add raylib.zig as wrapper --- src/main.zig | 10 ++-------- src/raylib.zig | 5 +++++ 2 files changed, 7 insertions(+), 8 deletions(-) create mode 100644 src/raylib.zig diff --git a/src/main.zig b/src/main.zig index d7091b6..253a226 100644 --- a/src/main.zig +++ b/src/main.zig @@ -1,11 +1,5 @@ const std = @import("std"); -const raylib = @cImport({ - @cInclude("raylib.h"); -}); -const raygui = @cImport({ - @cDefine("RAYGUI_IMPLEMENTATION", "1"); - @cInclude("raygui.h"); -}); +const raylib = @import("raylib.zig"); const sqlite = @cImport({ @cInclude("sqlite3.h"); }); @@ -21,7 +15,7 @@ pub fn main() !void { raylib.ClearBackground(raylib.RAYWHITE); raylib.DrawText("Congrats! You created your first window!", 190, 200, 20, raylib.LIGHTGRAY); - if (raygui.GuiButton(.{ .x = 0, .y = 0, .width = 100, .height = 100 }, "MyButton") == 1) {} + if (raylib.GuiButton(.{ .x = 0, .y = 0, .width = 100, .height = 100 }, "MyButton") == 1) {} } raylib.CloseWindow(); } diff --git a/src/raylib.zig b/src/raylib.zig new file mode 100644 index 0000000..e58a659 --- /dev/null +++ b/src/raylib.zig @@ -0,0 +1,5 @@ +pub usingnamespace @cImport({ + @cInclude("raylib.h"); + @cDefine("RAYGUI_IMPLEMENTATION", "1"); + @cInclude("raygui.h"); +});