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

fix: prebuilt binaries #272

Merged
merged 1 commit into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions llama/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
23 changes: 23 additions & 0 deletions src/utils/compileLLamaCpp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ export async function compileLlamaCpp({
}
}

applyResultDirFixes(compiledResultDirPath, path.join(compiledResultDirPath, "__temp"));

if (setUsedBinFlagArg) {
await setUsedBinFlag("localBuildFromSource");
}
Expand Down Expand Up @@ -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);
}
}
Loading