From cdacfb02408344e139df41d5205186e14eeadcb5 Mon Sep 17 00:00:00 2001 From: "Gilad S." Date: Fri, 26 Jul 2024 00:39:41 +0000 Subject: [PATCH] fix: prebuilt binaries --- llama/CMakeLists.txt | 10 ++++++++++ src/utils/compileLLamaCpp.ts | 23 +++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/llama/CMakeLists.txt b/llama/CMakeLists.txt index 8991cbbe..772424a3 100644 --- a/llama/CMakeLists.txt +++ b/llama/CMakeLists.txt @@ -24,6 +24,16 @@ include_directories("./llama.cpp/common") file(GLOB SOURCE_FILES "addon.cpp") +if(APPLE) + set(CMAKE_SKIP_BUILD_RPATH FALSE) + set(CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE) + set(CMAKE_BUILD_RPATH "@loader_path") + set(CMAKE_INSTALL_RPATH "@loader_path") + set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) +else() + set(CMAKE_BUILD_RPATH_USE_ORIGIN ON) +endif() + add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES} ${CMAKE_JS_SRC}) set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "" SUFFIX ".node") target_link_libraries(${PROJECT_NAME} ${CMAKE_JS_LIB}) diff --git a/src/utils/compileLLamaCpp.ts b/src/utils/compileLLamaCpp.ts index 886b8615..385a0442 100644 --- a/src/utils/compileLLamaCpp.ts +++ b/src/utils/compileLLamaCpp.ts @@ -88,6 +88,8 @@ export async function compileLlamaCpp({ } } + applyResultDirFixes(compiledResultDirPath, path.join(compiledResultDirPath, "__temp")); + if (setUsedBinFlagArg) { await setUsedBinFlag("localBuildFromSource"); } @@ -165,3 +167,24 @@ async function getToolchainFileForArch(targetArch: string) { return null; } + +async function applyResultDirFixes(resultDirPath: string, tempDirPath: string) { + const releaseDirPath = path.join(resultDirPath, "Release"); + + if (await fs.pathExists(releaseDirPath)) { + await fs.remove(tempDirPath); + await fs.move(releaseDirPath, tempDirPath); + + const itemNames = await fs.readdir(tempDirPath); + + await Promise.all( + itemNames.map((itemName) => ( + fs.move(path.join(tempDirPath, itemName), path.join(resultDirPath, itemName), { + overwrite: true + }) + )) + ); + + await fs.remove(tempDirPath); + } +}