Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: prebuilt binaries
Browse files Browse the repository at this point in the history
giladgd committed Jul 26, 2024
1 parent 7f15823 commit cdacfb0
Showing 2 changed files with 33 additions and 0 deletions.
10 changes: 10 additions & 0 deletions llama/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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})
23 changes: 23 additions & 0 deletions src/utils/compileLLamaCpp.ts
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit cdacfb0

Please sign in to comment.