Skip to content

Commit bd0e954

Browse files
committed
fix: Windows build
1 parent 19eb89b commit bd0e954

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

src/bindings/utils/compileLLamaCpp.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import os from "os";
55
import fs from "fs-extra";
66
import chalk from "chalk";
77
import which from "which";
8+
import filenamify from "filenamify";
89
import {
910
buildMetadataFileName, documentationPageUrls, llamaCppDirectory, llamaDirectory, llamaLocalBuildBinsDirectory,
1011
llamaPrebuiltBinsDirectory, llamaToolchainsDirectory
@@ -190,25 +191,24 @@ export async function compileLlamaCpp(buildOptions: BuildOptions, compileOptions
190191

191192
// perform a separate MSVC build and combine the compiled backends into the final build
192193
if (useWindowsLlvm && windowsSeparateMsvcCmakeOptions.size > 0) {
193-
const llvmResultDir = path.join(outDirectory, "_llvm" + buildConfigType);
194-
await fs.move(compiledResultDirPath, llvmResultDir);
195-
196194
for (const [targetFlag, targetValue] of windowsSeparateMsvcCmakeOptions) {
197195
const targetName = windowsMsvcOnlyBuildFlagsToTargets.get(targetFlag);
198196
if (targetName == null)
199197
continue;
200198

201-
console.info(getConsoleLogPrefix(true, false), "Building specialized GPU backends using MSVC: " + targetName);
199+
console.info(getConsoleLogPrefix(true, false), "Building specialized GPU backend using MSVC: " + targetName);
200+
201+
const targetOutDir = path.join(outDirectory, "target-" + filenamify(targetName));
202202

203-
await fs.remove(compiledResultDirPath);
203+
await fs.remove(targetOutDir);
204204
await spawnCommand(
205205
"npm",
206206
[
207207
"run", "-s", "cmake-js-llama", "--", "compile",
208208
"--log-level", "warn",
209209
"--config", buildConfigType,
210210
"--arch=" + buildOptions.arch,
211-
"--out", path.relative(llamaDirectory, outDirectory),
211+
"--out", path.relative(llamaDirectory, targetOutDir),
212212
"--runtime-version=" + runtimeVersion,
213213
"--parallel=" + parallelBuildThreads,
214214
"--target", targetName,
@@ -224,12 +224,9 @@ export async function compileLlamaCpp(buildOptions: BuildOptions, compileOptions
224224
envVars,
225225
buildOptions.progressLogs
226226
);
227-
const targetCompileResultDir = await moveBuildFilesToResultDir(outDirectory);
227+
const targetCompileResultDir = await moveBuildFilesToResultDir(targetOutDir);
228228
await mergeDirWithoutOverrides(targetCompileResultDir, compiledResultDirPath);
229229
}
230-
231-
await fs.remove(compiledResultDirPath);
232-
await fs.move(llvmResultDir, compiledResultDirPath);
233230
}
234231

235232
await fs.writeFile(path.join(compiledResultDirPath, buildMetadataFileName), JSON.stringify({

0 commit comments

Comments
 (0)