Skip to content

Commit e539e5b

Browse files
authored
fix: prebuilt binaries (#272)
1 parent 7f15823 commit e539e5b

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

llama/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ include_directories("./llama.cpp/common")
2424

2525
file(GLOB SOURCE_FILES "addon.cpp")
2626

27+
if(APPLE)
28+
set(CMAKE_SKIP_BUILD_RPATH FALSE)
29+
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE)
30+
set(CMAKE_BUILD_RPATH "@loader_path")
31+
set(CMAKE_INSTALL_RPATH "@loader_path")
32+
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
33+
else()
34+
set(CMAKE_BUILD_RPATH_USE_ORIGIN ON)
35+
endif()
36+
2737
add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES} ${CMAKE_JS_SRC})
2838
set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "" SUFFIX ".node")
2939
target_link_libraries(${PROJECT_NAME} ${CMAKE_JS_LIB})

src/utils/compileLLamaCpp.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ export async function compileLlamaCpp({
8888
}
8989
}
9090

91+
applyResultDirFixes(compiledResultDirPath, path.join(compiledResultDirPath, "__temp"));
92+
9193
if (setUsedBinFlagArg) {
9294
await setUsedBinFlag("localBuildFromSource");
9395
}
@@ -165,3 +167,24 @@ async function getToolchainFileForArch(targetArch: string) {
165167

166168
return null;
167169
}
170+
171+
async function applyResultDirFixes(resultDirPath: string, tempDirPath: string) {
172+
const releaseDirPath = path.join(resultDirPath, "Release");
173+
174+
if (await fs.pathExists(releaseDirPath)) {
175+
await fs.remove(tempDirPath);
176+
await fs.move(releaseDirPath, tempDirPath);
177+
178+
const itemNames = await fs.readdir(tempDirPath);
179+
180+
await Promise.all(
181+
itemNames.map((itemName) => (
182+
fs.move(path.join(tempDirPath, itemName), path.join(resultDirPath, itemName), {
183+
overwrite: true
184+
})
185+
))
186+
);
187+
188+
await fs.remove(tempDirPath);
189+
}
190+
}

0 commit comments

Comments
 (0)