@@ -141,18 +141,20 @@ export async function compileLlamaCpp(buildOptions: BuildOptions, compileOptions
141
141
142
142
for ( const binFilesDirPath of binFilesDirPaths ) {
143
143
if ( await fs . pathExists ( binFilesDirPath ) ) {
144
- const files = await fs . readdir ( binFilesDirPath ) ;
144
+ const itemNames = await fs . readdir ( binFilesDirPath ) ;
145
145
146
146
await Promise . all (
147
- files . map ( ( fileName ) => (
148
- fs . copy ( path . join ( binFilesDirPath , fileName ) , path . join ( compiledResultDirPath , fileName ) , {
147
+ itemNames . map ( ( itemName ) => (
148
+ fs . copy ( path . join ( binFilesDirPath , itemName ) , path . join ( compiledResultDirPath , itemName ) , {
149
149
overwrite : false
150
150
} )
151
151
) )
152
152
) ;
153
153
}
154
154
}
155
155
156
+ await applyResultDirFixes ( compiledResultDirPath , path . join ( outDirectory , "_temp" ) ) ;
157
+
156
158
await fs . writeFile ( path . join ( compiledResultDirPath , buildMetadataFileName ) , JSON . stringify ( {
157
159
buildOptions : convertBuildOptionsToBuildOptionsJSON ( buildOptions )
158
160
} satisfies BuildMetadataFile ) , "utf8" ) ;
@@ -282,7 +284,11 @@ export async function getPrebuiltBinaryPath(buildOptions: BuildOptions, folderNa
282
284
const binaryPath = await resolvePrebuiltBinaryPath ( localPrebuiltBinaryDirectoryPath ) ;
283
285
284
286
if ( binaryPath != null )
285
- return binaryPath ;
287
+ return {
288
+ binaryPath,
289
+ folderName,
290
+ folderPath : localPrebuiltBinaryDirectoryPath
291
+ } ;
286
292
287
293
const packagePrebuiltBinariesDirectoryPath = await getPrebuiltBinariesPackageDirectoryForBuildOptions ( buildOptions ) ;
288
294
if ( packagePrebuiltBinariesDirectoryPath == null )
@@ -292,13 +298,17 @@ export async function getPrebuiltBinaryPath(buildOptions: BuildOptions, folderNa
292
298
const binaryPathFromPackage = await resolvePrebuiltBinaryPath ( packagePrebuiltBinaryDirectoryPath ) ;
293
299
294
300
if ( binaryPathFromPackage != null )
295
- return binaryPathFromPackage ;
301
+ return {
302
+ binaryPath : binaryPathFromPackage ,
303
+ folderName,
304
+ folderPath : packagePrebuiltBinaryDirectoryPath
305
+ } ;
296
306
297
307
return null ;
298
308
}
299
309
300
- export async function getPrebuiltBinaryBuildMetadata ( folderName : string ) {
301
- const buildMetadataFilePath = path . join ( llamaPrebuiltBinsDirectory , folderName , buildMetadataFileName ) ;
310
+ export async function getPrebuiltBinaryBuildMetadata ( folderPath : string , folderName : string ) {
311
+ const buildMetadataFilePath = path . join ( folderPath , buildMetadataFileName ) ;
302
312
303
313
if ( ! ( await fs . pathExists ( buildMetadataFilePath ) ) )
304
314
throw new Error ( `Could not find build metadata file for prebuilt build "${ folderName } "` ) ;
@@ -307,6 +317,28 @@ export async function getPrebuiltBinaryBuildMetadata(folderName: string) {
307
317
return buildMetadata ;
308
318
}
309
319
320
+ async function applyResultDirFixes ( resultDirPath : string , tempDirPath : string ) {
321
+ const releaseDirPath = path . join ( resultDirPath , "Release" ) ;
322
+
323
+ if ( await fs . pathExists ( releaseDirPath ) ) {
324
+ await fs . remove ( tempDirPath ) ;
325
+ await fs . ensureDir ( tempDirPath ) ;
326
+ await fs . move ( releaseDirPath , tempDirPath ) ;
327
+
328
+ const itemNames = await fs . readdir ( tempDirPath ) ;
329
+
330
+ await Promise . all (
331
+ itemNames . map ( ( itemName ) => (
332
+ fs . move ( path . join ( tempDirPath , itemName ) , path . join ( resultDirPath , itemName ) , {
333
+ overwrite : true
334
+ } )
335
+ ) )
336
+ ) ;
337
+
338
+ await fs . remove ( tempDirPath ) ;
339
+ }
340
+ }
341
+
310
342
async function resolvePrebuiltBinaryPath ( prebuiltBinaryDirectoryPath : string ) {
311
343
const binaryPath = path . join ( prebuiltBinaryDirectoryPath , "llama-addon.node" ) ;
312
344
const buildMetadataFilePath = path . join ( prebuiltBinaryDirectoryPath , buildMetadataFileName ) ;
0 commit comments