Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile bug: Nix + cross compilation + Vulkan doesn't work #11654

Open
hacker1024 opened this issue Feb 4, 2025 · 1 comment
Open

Compile bug: Nix + cross compilation + Vulkan doesn't work #11654

hacker1024 opened this issue Feb 4, 2025 · 1 comment

Comments

@hacker1024
Copy link

Git commit

106045e

Operating systems

Linux

GGML backends

Vulkan

Problem description & steps to reproduce

I am trying to use Nix (with the derivations in this repo) to cross compile a static build with musl and LLVM.

I am using the following Nix file:

let
  pkgs = import <nixpkgs> {
    crossSystem = {
      config = "aarch64-unknown-linux-musl";
      useLLVM = true;
      isStatic = true;
    };

    # Optimisation - disable unnecessary X11 dependencies.
    overlays = [ (self: super: { vulkan-loader = super.vulkan-loader.override { enableX11 = false; }; }) ];
  };

  llama-cpp = pkgs.callPackage (builtins.fetchTarball "https://github.com/ggerganov/llama.cpp/archive/master.tar.gz" + "/.devops/nix/scope.nix") { };
in
llama-cpp.llama-cpp.override {
  enableCurl = false;
  useVulkan = true;
}

There are a couple of issues:

  1. CMake cannot find Vulkan. This is because shaderc is actually a build-time dependency, and should be put in the nativeBuildInputs list rather than buildInputs.

    For now, this can be worked around like so:

    (llama-cpp.llama-cpp.override {
      enableCurl = false;
      useVulkan = true;
    }).overrideAttrs ({ nativeBuildInputs ? [ ], ... }: {
      nativeBuildInputs = nativeBuildInputs ++ (with pkgs.pkgsBuildHost; [ shaderc ]);
    })
  2. Building vulkan-shaders-gen fails. It seems to try to use GNU ld, which makes no sense, because I'm using LLVM (so lld is the correct linker). It looks like the host toolchain logic does not account for this correctly, as well as potentially other Nix CMake settings.

First Bad Commit

No response

Compile command

nix-build path/to/give/file.nix

Relevant log output

-- The C compiler identification is Clang 19.1.6
-- The CXX compiler identification is Clang 19.1.6
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: /nix/store/2d1r5kvz7plg24bwb316972knqmiyf2p-clang-19.1.6/bin/clang
-- Check for working C compiler: /nix/store/2d1r5kvz7plg24bwb316972knqmiyf2p-clang-19.1.6/bin/clang - broken
CMake Error at /nix/store/mfrfb675a16gqchycqv16aziivn09dxa-cmake-3.31.3/share/cmake-3.31/Modules/CMakeTestCCompiler.cmake:67 (message):
  The C compiler

    "/nix/store/2d1r5kvz7plg24bwb316972knqmiyf2p-clang-19.1.6/bin/clang"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: '/build/source/build/ggml/src/ggml-vulkan/vulkan-shaders-gen-prefix/src/vulkan-shaders-gen-build/CMakeFiles/CMakeScratch/TryCompile-sMlsZU'
    
    Run Build Command(s): /nix/store/sqzac7j4cazddikz1nqb7y7q9v9vcwg0-ninja-1.12.1/bin/ninja -v cmTC_9a82f
    [1/2] /nix/store/2d1r5kvz7plg24bwb316972knqmiyf2p-clang-19.1.6/bin/clang   -O2  -O3 -DNDEBUG -MD -MT CMakeFiles/cmTC_9a82f.dir/testCCompiler.c.o -MF CMakeFiles/cmTC_9a82f.dir/testCCompiler.c.o.d -o CMakeFiles/cmTC_9a82f.dir/testCCompiler.c.o -c /build/source/build/ggml/src/ggml-vulkan/vulkan-shaders-gen-prefix/src/vulkan-shaders-gen-build/CMakeFiles/CMakeScratch/TryCompile-sMlsZU/testCCompiler.c
    [2/2] : && /nix/store/2d1r5kvz7plg24bwb316972knqmiyf2p-clang-19.1.6/bin/clang -O2  -O3 -DNDEBUG -rdynamic CMakeFiles/cmTC_9a82f.dir/testCCompiler.c.o -o cmTC_9a82f   && :
    FAILED: cmTC_9a82f 
    : && /nix/store/2d1r5kvz7plg24bwb316972knqmiyf2p-clang-19.1.6/bin/clang -O2  -O3 -DNDEBUG -rdynamic CMakeFiles/cmTC_9a82f.dir/testCCompiler.c.o -o cmTC_9a82f   && :
    clang: error: unable to execute command: Executable "ld" doesn't exist!
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    ninja: build stopped: subcommand failed.
    
    

  

  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt
@gogo2464
Copy link

gogo2464 commented Feb 5, 2025

did you installed clang?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants