From d30255f66f2aa64e35aae41764fc9abe9657bd7f Mon Sep 17 00:00:00 2001 From: multisn8 Date: Thu, 18 Apr 2024 00:08:09 +0200 Subject: [PATCH] repo: add `shell.nix` and `.envrc` (#5519) * repo: add shell.nix and .envrc Makes usage on NixOS easier, by not having to drop into a hurry of `nix-shell -p lots of packages` every time someone wants to experiment around with wgpu. The .envrc causes shell.nix to be eval'd automatically run iff 1. direnv is installed 2. the user `direnv allow`ed the shell.nix * repo(shell.nix): add explanations and remove cruft --- .envrc | 1 + shell.nix | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 .envrc create mode 100644 shell.nix diff --git a/.envrc b/.envrc new file mode 100644 index 000000000..1d953f4bd --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use nix diff --git a/shell.nix b/shell.nix new file mode 100644 index 000000000..6afa34470 --- /dev/null +++ b/shell.nix @@ -0,0 +1,69 @@ +# This file is only relevant for Nix and NixOS users. +# What's actually meant by "Nix" here is not UNIX, but the *package manager* Nix, see https://nixos.org/. +# If you are +# on macOS (and not using nix-darwin) +# or on Windows (and not using Nix in WSL), +# you can carelessly ignore this file. +# +# Otherwise, if you *do* use Nix the package manager, +# this file declares +# common dependencies +# and some nice tools +# which you'll most likely need when working with wgpu. +# Feel free to copy it into your own project if deemed useful. +# +# To use this file, just run `nix-shell` in this folder, +# which will drop you into a shell +# with all the deps needed for building wgpu available. +# +# Or if you're using direnv (https://direnv.net/), +# use `direnv allow` to automatically always use this file +# if you're navigating into this or a subfolder. + +{ pkgs ? import {} }: + +pkgs.mkShell rec { + buildInputs = with pkgs; [ + # necessary for building wgpu in 3rd party packages (in most cases) + libxkbcommon + wayland xorg.libX11 xorg.libXcursor xorg.libXrandr xorg.libXi + alsa-lib + fontconfig freetype + shaderc directx-shader-compiler + pkg-config cmake + mold # could use any linker, needed for rustix (but mold is fast) + + libGL + vulkan-headers vulkan-loader + vulkan-tools vulkan-tools-lunarg + vulkan-extension-layer + vulkan-validation-layers # don't need them *strictly* but immensely helpful + + # necessary for developing (all of) wgpu itself + cargo-nextest cargo-fuzz + + # nice for developing wgpu itself + typos + + # if you don't already have rust installed through other means, + # this shell.nix can do that for you with this below + yq # for tomlq below + rustup + + # nice tools + gdb rr + evcxr + valgrind + renderdoc + ]; + + shellHook = '' + export RUSTC_VERSION="$(tomlq -r .toolchain.channel rust-toolchain.toml)" + export PATH="$PATH:''${CARGO_HOME:-~/.cargo}/bin" + export PATH="$PATH:''${RUSTUP_HOME:-~/.rustup/toolchains/$RUSTC_VERSION-x86_64-unknown-linux/bin}" + export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${builtins.toString (pkgs.lib.makeLibraryPath buildInputs)}"; + + rustup default $RUSTC_VERSION + rustup component add rust-src rust-analyzer + ''; +}