Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
build

# Nix
.direnv
.envrc
result
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/).
Expand Down
61 changes: 61 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 50 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since there's a lockfile with pinned versions I'd prefer using a stable nixpkgs channel (say, nixos-25.04) so we get to use cached dependency builds for a longer time without updating the lockfile.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh interesting, I wasn't aware that the cache on a release channel like nixos-25.05 lasts longer than the cache for nixpkgs-unstable. Out of curiosity, is there some documentation about the Nixpkgs cache policy that I can read?

Unfortunately switching this from nixpkgs-unstable to nixos-25.05 doesn't currently work, because the Slang version there is still only v2025.8.1, which is too old to compile this demo.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know of an official policy, the closest thing I know is https://nixos.wiki/wiki/Nix_channels

Anyway the idea is that stable gets fewer updates in general so it's more likely that a given build hash is still relevant.

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/
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having the .spv files in PATH if someone were to launch a (non-dev) shell with this or even install it globally... would get a bit awkward. I guess one option would be to wrap the demo to cd to a data dir in $out/usr/share before launching the actual binary? Alternatively changing the demo code so it explicitly looks there would be even nicer.

Anyway that's a fair bit of work for just a simple demo so that can also be done later if someone feels like it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough! This was just a minimal attempt with the goal of making no changes to the rest of the code. If I were making other changes then I would have also gotten rid of the pip install command that tries to run and times out in nix build, for instance.

Copy link
Copy Markdown
Contributor Author

@samestep samestep Jul 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This demo also doesn't even work when running the built binary with cwd outside this repo clone, because it assumes that $PWD/data/Slang_LogoBug.png exists.

'';
};
devShell = pkgs.mkShell {
inherit buildInputs CPATH;
nativeBuildInputs = nativeBuildInputs ++ [
pkgs.clang-tools
pkgs.nixfmt-rfc-style
];
};
}
);
}