nix: properly patch in the vulkan-loader

now we can run `./result/bin/*` without any special environment.
This commit is contained in:
2022-07-05 23:32:39 -07:00
parent 029a278177
commit 46ac8b28b6

View File

@@ -21,14 +21,12 @@
# docs: https://github.com/oxalica/rust-overlay # docs: https://github.com/oxalica/rust-overlay
coremem-wavefront = pkgs.rustPlatform.buildRustPackage { coremem-wavefront = pkgs.rustPlatform.buildRustPackage {
name = "coremem-wavefront"; name = "coremem-wavefront";
# buildInputs = [ pkgs.vulkan-loader ]; buildInputs = [ pkgs.vulkan-loader ];
buildInputs = with pkgs; [ nativeBuildInputs = with pkgs; with xorg; [
pkgconfig rust-toolchain
mesa pkgconfig rustup xlibsWrapper libxkbcommon
xlibsWrapper xorg.libXcursor xorg.libXrandr xorg.libXi libX11 libXcursor libXi libXrandr vulkan-loader
vulkan-tools vulkan-headers vulkan-loader vulkan-validation-layers
]; ];
nativeBuildInputs = [ rust-toolchain pkgs.pkgconfig pkgs.mesa pkgs.vulkan-loader ];
src = self; src = self;
cargoLock = { cargoLock = {
lockFile = ./Cargo.lock; lockFile = ./Cargo.lock;
@@ -39,33 +37,32 @@
# rgpu tests expectedly fail due to a lack of spirv adapter exposed to the builder. # rgpu tests expectedly fail due to a lack of spirv adapter exposed to the builder.
doCheck = false; doCheck = false;
# enables debug builds, if we want: https://github.com/NixOS/nixpkgs/issues/60919.
hardeningDisable = [ "fortify" ]; hardeningDisable = [ "fortify" ];
# i guess the proper fix for this is to split rustc_codegen_spirv into its own postFixup = let
# package (see how we're also special-casing it in cargoLock), but this suffices too. libPath = nixpkgs.lib.makeLibraryPath [ pkgs.vulkan-loader ];
postInstall = '' in ''
cp $releaseDir/deps/librustc_codegen_spirv-*.so $out/lib/ # strictly speaking not *all* binaries need this, but this is easy.
# might be better to use `wrapProgram`, not sure.
echo adding rpath "${libPath}"
patchelf --add-rpath "${libPath}" $out/bin/*
''; '';
LD_LIBRARY_PATH = nixpkgs.lib.makeLibraryPath [ pkgs.vulkan-loader ]; LD_LIBRARY_PATH = nixpkgs.lib.makeLibraryPath [ pkgs.vulkan-loader ];
}; };
}; };
defaultPackage = packages.coremem-wavefront; defaultPackage = packages.coremem-wavefront;
devShells.default = with pkgs; mkShell { devShells.default = with pkgs; mkShell {
# buildInputs = with pkgs; [ # enables debug builds, if we want: https://github.com/NixOS/nixpkgs/issues/60919.
# rust-toolchain vulkan-loader
# ];
# hardeningDisable = [ "fortify" ];
# Workaround for https://github.com/NixOS/nixpkgs/issues/60919.
hardeningDisable = [ "fortify" ]; hardeningDisable = [ "fortify" ];
# Allow cargo to download crates. # Allow cargo to download crates.
SSL_CERT_FILE = "${cacert}/etc/ssl/certs/ca-bundle.crt"; SSL_CERT_FILE = "${cacert}/etc/ssl/certs/ca-bundle.crt";
buildInputs = [ buildInputs = [
pkgconfig rustup xlibsWrapper libxkbcommon pkgconfig rust-toolchain xlibsWrapper libxkbcommon
]; ];
# Runtime dependencies. # Runtime dependencies.