diff --git a/.gitignore b/.gitignore index 378eac2..ad68e1f 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,6 @@ build + +# Nix +.direnv +.envrc +result diff --git a/README.md b/README.md index 703545d..769ed66 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,19 @@ If not, you'll need to provide the path to the Slang compiler with The executable should then be `build/demo`. +#### Nix + +If you use Nix, no need to install Slang or other dependencies; use these +commands in your clone of this repo to do a reproducible build and run it: + +```sh +nix build # flakes must be enabled +result/bin/demo # outside of NixOS, you may need https://github.com/nix-community/nixGL +``` + +Alternatively, you can use `nix develop` to enter a shell with all necessary +dependencies, then run the same `cmake` build commands listed above. + ### Windows 1. Install [CMake](https://cmake.org), [Ninja](https://ninja-build.org), [Visual Studio 2022](https://visualstudio.microsoft.com/vs/) (Community edition is fine, we just need the MSVC compiler from this), [Python](https://www.python.org/), [LLVM](https://releases.llvm.org/) and [VCPKG](https://vcpkg.io/en/). diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..1f5b985 --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1752446735, + "narHash": "sha256-Nz2vtUEaRB/UjvPfuhHpez060P/4mvGpXW4JCDIboA4=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "a421ac6595024edcfbb1ef950a3712b89161c359", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..07372d5 --- /dev/null +++ b/flake.nix @@ -0,0 +1,50 @@ +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + self.submodules = true; + }; + outputs = + { + self, + nixpkgs, + flake-utils, + }: + flake-utils.lib.eachDefaultSystem ( + system: + let + pkgs = import nixpkgs { inherit system; }; + nativeBuildInputs = [ + pkgs.cmake + pkgs.python3 + pkgs.python3Packages.libclang + pkgs.shader-slang + ]; + buildInputs = [ + pkgs.SDL2 + pkgs.vulkan-headers + pkgs.vulkan-loader + ]; + CPATH = "${pkgs.glibc.dev}/include"; + in + { + defaultPackage = pkgs.stdenv.mkDerivation { + name = "slang-simple-vulkan"; + src = ./.; + strictDeps = true; + inherit nativeBuildInputs buildInputs CPATH; + installPhase = '' + mkdir -p $out/bin + cp *.spv demo $out/bin/ + ''; + }; + devShell = pkgs.mkShell { + inherit buildInputs CPATH; + nativeBuildInputs = nativeBuildInputs ++ [ + pkgs.clang-tools + pkgs.nixfmt-rfc-style + ]; + }; + } + ); +}