Skip to content

Commit d6c95b0

Browse files
authored
metal : fix default.metallib build (#12224)
This commit updates the custom command to build the default.metallib file to use the correct path to ../ggml-common.h by using the variable METALLIB_COMMON. The motivation for this change is that currently when building and specifying GGML_METAL_EMBED_LIBRARY=OFF the following error is generated: ```console [ 11%] Linking CXX shared library ../../bin/libggml.dylib [ 11%] Built target ggml make[2]: *** No rule to make target `ggml/src/ggml-metal/ggml-common.h', needed by `bin/default.metallib'. Stop. make[1]: *** [ggml/src/ggml-metal/CMakeFiles/ggml-metal-lib.dir/all] Error 2 ``` With the above change the build could progress but there was a follow on error about not being able to find the ggml-common.h file in ggml-metal.metal where is was included as a relative path: ```console [ 11%] Compiling Metal kernels /Users/danbev/work/llama.cpp/build/bin/ggml-metal.metal:6:10: error: '../ggml-common.h' file not found, did you mean 'ggml-common.h'? ^~~~~~~~~~~~~~~~~~ "ggml-common.h" 1 error generated. ``` Removing the relative path then allowed the build to complete successfully.
1 parent d76a86d commit d6c95b0

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

ggml/src/ggml-metal/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ configure_file(../ggml-common.h ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ggml-common.h
2727
configure_file(ggml-metal.metal ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ggml-metal.metal COPYONLY)
2828
configure_file(ggml-metal-impl.h ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ggml-metal-impl.h COPYONLY)
2929

30+
set(METALLIB_COMMON "${CMAKE_CURRENT_SOURCE_DIR}/../ggml-common.h")
3031
if (GGML_METAL_EMBED_LIBRARY)
3132
enable_language(ASM)
3233

3334
add_compile_definitions(GGML_METAL_EMBED_LIBRARY)
3435

35-
set(METALLIB_COMMON "${CMAKE_CURRENT_SOURCE_DIR}/../ggml-common.h")
3636
set(METALLIB_SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/ggml-metal.metal")
3737
set(METALLIB_IMPL "${CMAKE_CURRENT_SOURCE_DIR}/ggml-metal-impl.h")
3838

@@ -93,7 +93,7 @@ else()
9393
COMMAND rm -f ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ggml-metal.air
9494
COMMAND rm -f ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ggml-common.h
9595
COMMAND rm -f ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ggml-metal.metal
96-
DEPENDS ggml-metal.metal ggml-common.h
96+
DEPENDS ggml-metal.metal ${METALLIB_COMMON}
9797
COMMENT "Compiling Metal kernels"
9898
)
9999

ggml/src/ggml-metal/ggml-metal.metal

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
#if defined(GGML_METAL_EMBED_LIBRARY)
44
__embed_ggml-common.h__
55
#else
6-
// TODO: this should not be a relative path, but can't figure out how to set Metal include paths in Package.swift
7-
#include "../ggml-common.h"
6+
#include "ggml-common.h"
87
#endif
98
#include "ggml-metal-impl.h"
109

0 commit comments

Comments
 (0)