diff --git a/.gitignore b/.gitignore index 920b172..40c3ccb 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,7 @@ cmake-build-release/ .idea/ node_modules/ *.dSYM -.vs/ \ No newline at end of file +.vs/ +.direnv/ +.envrc +build/ diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..b450a06 --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1747327360, + "narHash": "sha256-LSmTbiq/nqZR9B2t4MRnWG7cb0KVNU70dB7RT4+wYK4=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "e06158e58f3adee28b139e9c2bcfcc41f8625b46", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..ff2d70f --- /dev/null +++ b/flake.nix @@ -0,0 +1,164 @@ +{ + description = "Clay (short for C Layout) is a high performance 2D UI layout library."; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + }; + + outputs = { + self, + nixpkgs, + }: let + inherit (nixpkgs) lib; + systems = lib.systems.flakeExposed; + forAllSystems = lib.genAttrs systems; + nixpkgsFor = forAllSystems (system: nixpkgs.legacyPackages.${system}); + in { + checks = forAllSystems ( + system: let + pkgs = nixpkgsFor.${system}; + in { + formatting = + pkgs.runCommand "format-flake" { + nativeBuildInputs = with pkgs; [ + alejandra + deadnix + statix + ]; + } '' + echo "Checking nix formatting" + alejandra --check . + + echo "Checking dead code" + deadnix --fail . + + echo "Checking statix" + statix check . + ''; + } + ); + + devShells = forAllSystems ( + system: let + pkgs = nixpkgsFor.${system}; + in { + default = pkgs.mkShell { + # For testing renderers and examples, aswell as tests + packages = with pkgs; [ + # Renderers + SDL2 + SDL2_image + SDL2_ttf + + sdl3 + sdl3-ttf + sdl3-image + + cairo + raylib + sokol + + cmake # this is needed for building examples and tests + gcc + clang-tools # for clangd and clang-tidy + pkg-config + alejandra # for formatting nix + + # for tests + docker + docker-compose + + # dependencies for examples and tests + xorg.libXrandr + xorg.libXinerama + xorg.libXcursor + xorg.libXi + ]; + + LD_LIBRARY_PATH = "${lib.makeLibraryPath [ + # Renderers + pkgs.SDL2 + pkgs.SDL2_image + pkgs.SDL2_ttf + + pkgs.sdl3 + pkgs.sdl3-ttf + pkgs.sdl3-image + + pkgs.cairo + pkgs.raylib + pkgs.sokol + + # dependencies for examples and tests + pkgs.xorg.libXrandr + pkgs.xorg.libXinerama + pkgs.xorg.libXcursor + pkgs.xorg.libXi + ]}"; + }; + } + ); + + formatter = forAllSystems (system: nixpkgsFor.${system}.alejandra); + + packages = forAllSystems ( + system: let + pkgs = nixpkgsFor.${system}; + git_tag + date = let + # YYYYMMDD + date' = lib.substring 0 8 self.lastModifiedDate; + year = lib.substring 0 4 date'; + month = lib.substring 4 2 date'; + date = lib.substring 6 2 date'; + in + if (self ? "lastModifiedDate") + then + lib.concatStringsSep "-" [ + year + month + date + ] + else "unknown"; + in { + default = pkgs.stdenv.mkDerivation (finalAttrs { + pname = "clay"; + version = "v0.14-master-${date}"; + src = ./.; + + dontBuild = true; + + installPhase = '' + mkdir -p $out/include + mkdir -p $out/lib/pkgconfig + + cp clay.h $out/include + + cat <$out/lib/pkgconfig/clay.pc + prefix=$out + includedir=$out/include + Name: Clay + Description: Clay (short for C Layout) is a high performance 2D UI layout library. + Version: $version + Cflags: -I$out/include + EOF + ''; + + passthru.tests.pkg-config = testers.testMetaPkgConfig finalAttrs.finalPackage; + + meta = with lib; { + description = "Clay (short for C Layout) is a high performance 2D UI layout library."; + homepage = "https://github.com/nicbarker/clay"; + license = licenses.zlib; + maintainers = with maintainers; [nicbarker]; + pkgConfigModules = ["clay"]; + # FIXME: I'm not sure what platforms this supports. + platforms = platforms.all; + }; + }); + + defaultPackage = self.packages.${system}.default; + } + ); + }; +}