vulkano-rs/vulkano

can't find crate for `vulkano_shaders`

nulvinge opened this issue · 11 comments

  • Version of vulkano: 0.34.0, and latest master
  • OS: ubuntu linux
  • GPU (the selected PhysicalDevice): Intel UHD
  • GPU Driver: Mesa
  • Rust version: 1.75 and latest 1.80

Issue

I'm trying to run one of the examples. I have the repo checked out and run:
SHADERC_LIB_DIR=/home/nik/prj/shaderc/install/lib cargo run -v --bin triangle

Which results in this:

     Running `rustc --crate-name triangle --edition=2021 examples/triangle/main.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=105 --crate-type bin --emit=dep-info,link -C opt-level=3 -C embed-bitcode=no -C metadata=5a98d40c8cfda99c -C extra-filename=-5a98d40c8cfda99c --out-dir /home/nik/prj/vulkano/target/release/deps -L dependency=/home/nik/prj/vulkano/target/release/deps --extern vulkano=/home/nik/prj/vulkano/target/release/deps/libvulkano-6ff585a2bb4978f9.rlib --extern vulkano_shaders=/home/nik/prj/vulkano/target/release/deps/libvulkano_shaders-db6fd8155ed47d7b.so --extern winit=/home/nik/prj/vulkano/target/release/deps/libwinit-83039023fbbc3866.rlib`

error[E0463]: can't find crate for `vulkano_shaders`
   --> examples/triangle/main.rs:306:9
    |
306 |         vulkano_shaders::shader! {
    |         ^^^^^^^^^^^^^^^ can't find crate

I've tried many things, but nothing seems to work.
Does anyone know what is going wrong?

I suggest making a fresh crate and running it like this:

cargo new shaderc-test && cd shaderc-test && cargo add shaderc && cargo build

Because you aren't going to go far with that diagnostic that Rust outputs when a linker error happens when building a proc macro dependency.

Thanks for being so quick to answer, sorry for being so slow.

That succeeded:

cargo new shaderc-test && cd shaderc-test && cargo add shaderc && cargo build
     Created binary (application) `shaderc-test` package
    Updating crates.io index
      Adding shaderc v0.8.3 to dependencies.
             Features:
             - build-from-source
             - prefer-static-linking
    Updating crates.io index
   Compiling shlex v1.3.0
   Compiling xmlparser v0.13.6
   Compiling libc v0.2.158
   Compiling cc v1.1.14
   Compiling roxmltree v0.14.1
   Compiling cmake v0.1.51
   Compiling shaderc-sys v0.8.3
   Compiling shaderc v0.8.3
   Compiling shaderc-test v0.1.0 (/home/nik/prj/shaderc-test)
    Finished dev [unoptimized + debuginfo] target(s) in 2.36s

I'm quite new at rust, so I'm unsure of what exactly is going wrong.
But I guess looking into shaderc is a good start?

I was expecting that to fail, actually, and show you the errors (which Rust doesn't display when compiling the proc macro). I don't know what to do now.

Same issue here on NixOS 24.11 (Linux 6.10.9), when following the tutorial:

error[E0463]: can't find crate for `vulkano_shaders`
  --> src/main.rs:47:5
   |
47 | use vulkano_shaders::shader;
   |     ^^^^^^^^^^^^^^^ can't find crate

main.rs

// ...
// LSP does show the crate and its contents.
// Running it throws the error.
use vulkano_shaders::shader; 

mod vs {
    shader! {
        ty: "vertex",
        src: r"
            #version 460

            layout(location = 0) in vec2 position;

            void main() {
                gl_Position = vec4(position, 0.0, 1.0);
            }
        ",
    }
}
// ...

Cargo: 1.82.0
Rust Compiler: 1.82.0

$ rustup default    
stable-x86_64-unknown-linux-gnu (default)

Cargo.toml:

[package]
name = "name"
version = "0.1.0"
edition = "2021"

[dependencies]
vulkano = "0.34.0"
vulkano-shaders = "0.34.0"
# ...

I run $ nix develop as well as the setup script inside the VulkanSDK:

# Copyright (c) 2015-2023 LunarG, Inc.

# source this file into an existing shell to setup your environment.
#
# See docs for in depth documentation:
# https://vulkan.lunarg.com/doc/sdk/latest/linux/getting_started.html

ARCH="$(uname -m)"
VULKAN_SDK="$(dirname "$(readlink -f "${BASH_SOURCE:-$0}" )" )/$ARCH"
export VULKAN_SDK
PATH="$VULKAN_SDK/bin:$PATH"
export PATH
LD_LIBRARY_PATH="$VULKAN_SDK/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
export LD_LIBRARY_PATH
VK_ADD_LAYER_PATH="$VULKAN_SDK/share/vulkan/explicit_layer.d${VK_ADD_LAYER_PATH:+:$VK_ADD_LAYER_PATH}"
export VK_ADD_LAYER_PATH
if [ -n "${VK_LAYER_PATH-}" ]; then
    echo "Unsetting VK_LAYER_PATH environment variable for SDK usage"
    unset VK_LAYER_PATH
fi

flake.nix:

{
  description = "Vulkan Dev Flake";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
  };

  outputs =
    { self, nixpkgs }@inputs:
    let
      lib = nixpkgs.lib;
      pkgs = import inputs.nixpkgs {
        system = "x86_64-linux";
      };
    in
    {
      devShells.x86_64-linux.default = pkgs.mkShell rec {
        name = "Test Env";

        buildInputs = with pkgs; [
          libxkbcommon
          libGL

          wayland
          cmake

          pkg-config

          xorg.libX11
          xorg.libXrandr
          xorg.libXcursor
          xorg.libXi
          xorg.libXxf86vm

          glfw3
          glslang
          fontconfig
          spirv-tools
          vulkan-volk
          vulkan-tools
          vulkan-loader
          vulkan-headers
          vulkan-validation-layers
          vulkan-tools-lunarg
          vulkan-extension-layer
        ];

        LD_LIBRARY_PATH = "${lib.makeLibraryPath buildInputs}";
        VK_LAYER_PATH = "${pkgs.vulkan-validation-layers}/share/vulkan/explicit_layer.d";
        VULKAN_SDK = "${pkgs.vulkan-validation-layers}/share/vulkan/";
      };
    };
}