#!/bin/sh # Run a command with the spikes' build and run environment (NixOS): the # native libraries GPUI and voelin-media link, Mesa (lavapipe, the software # Vulkan device), the Vulkan loader, Xvfb, a window manager and the X tools # the measurements use, and a Rust toolchain on PATH. # # spikes/gpui/shell.sh cargo build --locked --release # TOOLCHAIN=nightly spikes/gpui/shell.sh cargo build --locked # # TOOLCHAIN: 1.95 (default: the oldest release gpui-kit builds with), 1.94 # (rust-toolchain.toml's, which cannot build gpui-kit), stable or nightly, # all from one pinned fenix (stable: 2026-10-15's, nightly: 2026-10-24's); # RUST_BIN overrides the directory with cargo and rustc. VK_DRIVER_FILES: the # Vulkan drivers GPUI may use (default: lavapipe alone). set -eu substituters="https://cache.nixos.org/ https://nix-community.cachix.org" fenix=github:nix-community/fenix/e691190ae78c9551d1e6a0cba156555c8f7cceca components='[ "cargo" "rustc" "rust-std" "clippy" "rustfmt" ]' case "${TOOLCHAIN:-1.95}" in 1.95) toolchain="(f.toolchainOf { channel = \"1.95.0\"; sha256 = \"sha256-gh/xTkxKHL4eiRXzWv8KP7vfjSk61Iq48x47BEDFgfk=\"; })" ;; 1.94) toolchain="(f.toolchainOf { channel = \"1.94.0\"; sha256 = \"sha256-qqF33vNuAdU5vua96VKVIwuc43j4EFeEXbjQ6+l4mO4=\"; })" ;; stable) toolchain=f.stable ;; nightly) toolchain=f.latest ;; *) echo "shell.sh: TOOLCHAIN is 1.95, 1.94, stable or nightly" >&2; exit 2 ;; esac if [ -z "${RUST_BIN:-}" ]; then default_bin=$(nix build --option substituters "$substituters" --no-link --print-out-paths --impure \ --expr "let f = (builtins.getFlake \"$fenix\").packages.x86_64-linux; in $toolchain.withComponents $components")/bin fi RUST_BIN=${RUST_BIN:-$default_bin} # Tools (bin/ on PATH) and libraries (lib/ and pkg-config files). tools="gcc cmake gnumake pkg-config jq xvfb xdotool xwd imagemagick vulkan-tools procps xclip coreutils openbox dbus xrandr xdpyinfo xprop xwininfo" # Libraries with every output (lib/ and the pkg-config files are in different # ones). libs="alsa-lib openssl libvpx dav1d pipewire fontconfig freetype libxkbcommon expat wayland libxcb vulkan-loader libglvnd libx11 libxcursor libxrandr libxi libxext libxrender" installables="nixpkgs#libclang.lib nixpkgs#glibc.dev nixpkgs#mesa nixpkgs#noto-fonts-color-emoji nixpkgs#noto-fonts-cjk-sans" for p in $tools; do installables="$installables nixpkgs#$p"; done for p in $libs; do installables="$installables nixpkgs#$p^*"; done # shellcheck disable=SC2086 paths=$(nix build --option substituters "$substituters" --no-link --print-out-paths $installables) bin= pc= lib= for p in $paths; do [ -d "$p/bin" ] && bin="$bin:$p/bin" [ -d "$p/lib/pkgconfig" ] && pc="$pc:$p/lib/pkgconfig" [ -d "$p/share/pkgconfig" ] && pc="$pc:$p/share/pkgconfig" [ -d "$p/lib" ] && lib="$lib:$p/lib" case $p in *-mesa-[0-9]*) [ -e "$p/share/vulkan/icd.d/lvp_icd.x86_64.json" ] && MESA=$p ;; *-clang-*-lib) [ -e "$p/lib/libclang.so" ] && LIBCLANG_PATH=$p/lib ;; *-glibc-*-dev) GLIBC_INCLUDE=$p/include ;; *-noto-fonts-color-emoji-*) SPIKE_EMOJI_FONT=$p/share/fonts/noto/NotoColorEmoji.ttf ;; *-noto-fonts-cjk-sans-*) SPIKE_EXTRA_FONTS=$p/share/fonts/opentype/noto-cjk/NotoSansCJK-VF.otf.ttc ;; esac done export PATH="$RUST_BIN$bin:$PATH" export PKG_CONFIG_PATH="${pc#:}" # Run time: the Vulkan loader, libGL/EGL, Wayland and xkbcommon are opened # by name (dlopen); link time: -L for every library above. export LD_LIBRARY_PATH="${lib#:}${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" export LIBRARY_PATH="${lib#:}" export LIBCLANG_PATH MESA # The fonts the spikes add to GPUI (common/src/fonts.rs): colour emoji, CJK. export SPIKE_EMOJI_FONT SPIKE_EXTRA_FONTS # bindgen (libclang, unwrapped) needs the C library's headers. export BINDGEN_EXTRA_CLANG_ARGS="-isystem $GLIBC_INCLUDE" export VK_DRIVER_FILES="${VK_DRIVER_FILES:-$MESA/share/vulkan/icd.d/lvp_icd.x86_64.json}" export __EGL_VENDOR_LIBRARY_DIRS="$MESA/share/glvnd/egl_vendor.d" exec "$@"