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

Cannot find xcrun when building with Nix flakes on Darwin/MacOS #6117

Closed
josephst opened this issue Mar 17, 2024 · 1 comment · Fixed by #6118
Closed

Cannot find xcrun when building with Nix flakes on Darwin/MacOS #6117

josephst opened this issue Mar 17, 2024 · 1 comment · Fixed by #6118

Comments

@josephst
Copy link
Contributor

On latest version of llama.cpp, building from flake (ie nix build github:ggerganov/llama.cpp) produces error with latest commit (d01b3c4 at time of writing).

error: builder for '/nix/store/9qrdgaz8s1wfz9fwci01j2vi97y45cfy-llama-cpp-metalkit-0.0.0.drv' failed with exit code 1;
       last 25 log lines:
       > -- Generating done (0.0s)
       > CMake Warning:
       >   Manually-specified variables were not used by the project:
       >
       >     CMAKE_EXPORT_NO_PACKAGE_REGISTRY
       >     CMAKE_POLICY_DEFAULT_CMP0025
       >
       >
       > -- Build files have been written to: /tmp/nix-build-llama-cpp-metalkit-0.0.0.drv-0/source/build
       > cmake: enabled parallel building
       > cmake: enabled parallel installing
       > Running phase: buildPhase
       > build flags: -j8
       > [1/132] Compiling Metal kernels
       > FAILED: bin/default.metallib /tmp/nix-build-llama-cpp-metalkit-0.0.0.drv-0/source/build/bin/default.metallib
       > cd /tmp/nix-build-llama-cpp-metalkit-0.0.0.drv-0/source/build && xcrun -sdk macosx metal -O3 -c /tmp/nix-build-llama-cpp-metalkit-0.0.0.drv-0/source/build/bin/ggml-metal.metal -o /tmp/nix-build-llama-cpp-metalkit-0.0.0.drv-0/source/build/bin/ggml-metal.air && xcrun -sdk macosx metallib /tmp/nix-build-llama-cpp-metalkit-0.0.0.drv-0/source/build/bin/ggml-metal.air -o /tmp/nix-build-llama-cpp-metalkit-0.0.0.drv-0/source/build/bin/default.metallib && rm -f /tmp/nix-build-llama-cpp-metalkit-0.0.0.drv-0/source/build/bin/ggml-metal.air && rm -f /tmp/nix-build-llama-cpp-metalkit-0.0.0.drv-0/source/build/bin/ggml-common.h && rm -f /tmp/nix-build-llama-cpp-metalkit-0.0.0.drv-0/source/build/bin/ggml-metal.metal
       > /bin/sh: xcrun: command not found
       > [2/132] Building C object CMakeFiles/ggml.dir/ggml-alloc.c.o
       > [3/132] Building C object CMakeFiles/ggml.dir/ggml-backend.c.o
       > [4/132] Building C object CMakeFiles/ggml.dir/ggml-metal.m.o
       > [5/132] Building C object CMakeFiles/ggml.dir/ggml-quants.c.o
       > [6/132] Building C object CMakeFiles/ggml.dir/ggml.c.o
       > [7/132] Building CXX object CMakeFiles/llama.dir/unicode.cpp.o
       > [8/132] Building CXX object CMakeFiles/llama.dir/llama.cpp.o
       > ninja: build stopped: subcommand failed.
       For full logs, run 'nix log /nix/store/9qrdgaz8s1wfz9fwci01j2vi97y45cfy-llama-cpp-metalkit-0.0.0.drv'.

The key error is /bin/sh: xcrun: command not found -- Nix provides a clean $PATH to CMake which does not include /usr/bin and so Cmake is unable to locate or run /usr/bin/xcrun. This behavior is specific to the combination of MacOS and Nix.

This can be fixed by either manually adding /usr/bin to $PATH prior to configuration & build steps, or by using absolute path (/usr/bin/xcrun) and setting dontFixCmake = true; in package.nix.

System details:
Nix 2.21 (sandbox = off), MacOS 14.4 Sonoma

josephst added a commit to josephst/llama.cpp that referenced this issue Mar 17, 2024
@josephst
Copy link
Contributor Author

Suspect it's related to this change #6015

josephst added a commit to josephst/llama.cpp that referenced this issue Mar 17, 2024
josephst added a commit to josephst/llama.cpp that referenced this issue Mar 18, 2024
is usable during build (used for compiling Metal shaders)

Fixes ggerganov#6117
josephst added a commit to josephst/llama.cpp that referenced this issue Mar 18, 2024
is usable during build (used for compiling Metal shaders)

Fixes ggerganov#6117
josephst added a commit to josephst/llama.cpp that referenced this issue Mar 19, 2024
is usable during build (used for compiling Metal shaders)

Fixes ggerganov#6117
josephst added a commit to josephst/llama.cpp that referenced this issue Mar 19, 2024
is usable during build (used for compiling Metal shaders)

Fixes ggerganov#6117
josephst added a commit to josephst/llama.cpp that referenced this issue Mar 19, 2024
is usable during build (used for compiling Metal shaders)

Fixes ggerganov#6117
josephst added a commit to josephst/llama.cpp that referenced this issue Mar 21, 2024
is usable during build (used for compiling Metal shaders)

Fixes ggerganov#6117
josephst added a commit to josephst/llama.cpp that referenced this issue Mar 25, 2024
is usable during build (used for compiling Metal shaders)

Fixes ggerganov#6117
philiptaron pushed a commit that referenced this issue Mar 26, 2024
…rs (#6118)

* Symlink to /usr/bin/xcrun so that `xcrun` binary
is usable during build (used for compiling Metal shaders)

Fixes #6117

* cmake - copy default.metallib to install directory

When metal files are compiled to default.metallib, Cmake needs to add this to the install directory so that it's visible to llama-cpp

Also, update package.nix to use absolute path for default.metallib (it's not finding the bundle)

* add `precompileMetalShaders` flag (defaults to false) to disable precompilation of metal shader

Precompilation requires Xcode to be installed and requires disable sandbox on nix-darwin
github-actions bot pushed a commit to KerfuffleV2/ggml-sys-bleedingedge that referenced this issue Mar 26, 2024
== Relevant log messages from source repo:

commit e190f1fca6f60d80944f9e8709d343a025c4d245
Author: Joseph Stahl <1269177+josephst@users.noreply.github.com>
Date:   Mon Mar 25 20:51:46 2024 -0400

    nix: make `xcrun` visible in Nix sandbox for precompiling Metal shaders (#6118)

    * Symlink to /usr/bin/xcrun so that `xcrun` binary
    is usable during build (used for compiling Metal shaders)

    Fixes ggerganov/llama.cpp#6117

    * cmake - copy default.metallib to install directory

    When metal files are compiled to default.metallib, Cmake needs to add this to the install directory so that it's visible to llama-cpp

    Also, update package.nix to use absolute path for default.metallib (it's not finding the bundle)

    * add `precompileMetalShaders` flag (defaults to false) to disable precompilation of metal shader

    Precompilation requires Xcode to be installed and requires disable sandbox on nix-darwin

commit 280345968dabc00d212d43e31145f5c9961a7604
Author: slaren <slarengh@gmail.com>
Date:   Tue Mar 26 01:16:01 2024 +0100

    cuda : rename build flag to LLAMA_CUDA (#6299)
hodlen pushed a commit to hodlen/llama.cpp that referenced this issue Apr 1, 2024
…rs (ggerganov#6118)

* Symlink to /usr/bin/xcrun so that `xcrun` binary
is usable during build (used for compiling Metal shaders)

Fixes ggerganov#6117

* cmake - copy default.metallib to install directory

When metal files are compiled to default.metallib, Cmake needs to add this to the install directory so that it's visible to llama-cpp

Also, update package.nix to use absolute path for default.metallib (it's not finding the bundle)

* add `precompileMetalShaders` flag (defaults to false) to disable precompilation of metal shader

Precompilation requires Xcode to be installed and requires disable sandbox on nix-darwin
hodlen pushed a commit to hodlen/llama.cpp that referenced this issue Apr 3, 2024
…rs (ggerganov#6118)

* Symlink to /usr/bin/xcrun so that `xcrun` binary
is usable during build (used for compiling Metal shaders)

Fixes ggerganov#6117

* cmake - copy default.metallib to install directory

When metal files are compiled to default.metallib, Cmake needs to add this to the install directory so that it's visible to llama-cpp

Also, update package.nix to use absolute path for default.metallib (it's not finding the bundle)

* add `precompileMetalShaders` flag (defaults to false) to disable precompilation of metal shader

Precompilation requires Xcode to be installed and requires disable sandbox on nix-darwin
tybalex pushed a commit to tybalex/function.cpp that referenced this issue Apr 17, 2024
…rs (ggerganov#6118)

* Symlink to /usr/bin/xcrun so that `xcrun` binary
is usable during build (used for compiling Metal shaders)

Fixes ggerganov#6117

* cmake - copy default.metallib to install directory

When metal files are compiled to default.metallib, Cmake needs to add this to the install directory so that it's visible to llama-cpp

Also, update package.nix to use absolute path for default.metallib (it's not finding the bundle)

* add `precompileMetalShaders` flag (defaults to false) to disable precompilation of metal shader

Precompilation requires Xcode to be installed and requires disable sandbox on nix-darwin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant