Skip to content

Commit 1e617cd

Browse files
authored
feat: only build one binary for all node versions (#50)
1 parent 9db72b0 commit 1e617cd

File tree

2 files changed

+29
-34
lines changed

2 files changed

+29
-34
lines changed

.github/workflows/build.yml

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ jobs:
149149
function getArches() {
150150
switch (process.env.ARTIFACT_NAME) {
151151
case "win":
152-
return ["x64"];
152+
return ["x64" /*, "arm64" */ ]; // disabled arm64 for now as compilation doesn't work
153153
case "linux":
154154
return ["x64", "arm64", "armv7l", "ppc64le"];
155155
case "mac":
@@ -159,32 +159,32 @@ jobs:
159159
return ["x64"];
160160
}
161161
162-
const {versions: latestNodeVersions, latestVersion: latestNodeVersion} = await getLatestNodeVersions(Date.now() - 1000 * 60 * 60 * 24 * 14);
162+
const {versions: latestNodeVersions} = await getLatestNodeVersions(Date.now() - 1000 * 60 * 60 * 24 * 14);
163163
164-
const minNodeVersion = latestNodeVersion - 4;
165-
166-
const nodeVersions = [...latestNodeVersions].reduce((acc, [majorVersion, version]) => {
167-
if (majorVersion >= minNodeVersion)
168-
acc.push(version);
169-
170-
return acc;
171-
}, []);
164+
const nodeVersion = latestNodeVersions.get(18);
165+
const windowsOnArmNodeVersion = latestNodeVersions.get(20);
172166
const arches = getArches();
173167
174-
console.log("Building for node versions", nodeVersions, "and archs", arches);
168+
if (nodeVersion == null || windowsOnArmNodeVersion == null) {
169+
throw new Error("Could not find node versions");
170+
}
171+
172+
console.log("Building for node version", nodeVersion, "and archs", arches);
175173
176174
await $`mkdir -p llamaBins`;
177175
178-
for (const nodeVersion of nodeVersions) {
179-
for (const arch of arches) {
180-
console.log(`Building ${arch} for node ${nodeVersion}`);
181-
182-
const majorNodeVersion = parseInt(nodeVersion.slice("v".length))
183-
184-
const binName = `${process.env.ARTIFACT_NAME}-${arch}-${majorNodeVersion}`;
185-
await $`node ./dist/cli/cli.js build --arch ${arch} --nodeTarget ${nodeVersion}`;
186-
await $`mv ./llama/build/Release ${"./llamaBins/" + binName}`;
176+
for (const arch of arches) {
177+
let buildNodeVersion = nodeVersion;
178+
179+
if (process.env.ARTIFACT_NAME === "win" && arch === "arm64") {
180+
buildNodeVersion = windowsOnArmNodeVersion;
187181
}
182+
183+
console.log(`Building ${arch} for node ${buildNodeVersion}`);
184+
185+
const binName = `${process.env.ARTIFACT_NAME}-${arch}`;
186+
await $`node ./dist/cli/cli.js build --arch ${arch} --nodeTarget ${buildNodeVersion}`;
187+
await $`mv ./llama/build/Release ${"./llamaBins/" + binName}`;
188188
}
189189
190190
await $`echo "Built binaries:"`;

src/utils/getBin.ts

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,15 @@ import {getCompiledLlamaCppBinaryPath} from "./compileLLamaCpp.js";
1414
const require = createRequire(import.meta.url);
1515

1616
export async function getPrebuildBinPath(): Promise<string | null> {
17-
const majorNodeVersion = parseInt(process.version.slice("v".length));
18-
const supportedVersions = [majorNodeVersion, majorNodeVersion - 1];
19-
20-
function createPath(platform: string, arch: string, nodeVersion: number) {
21-
return path.join(llamaBinsDirectory, `${platform}-${arch}-${nodeVersion}/llama-addon.node`);
17+
function createPath(platform: string, arch: string) {
18+
return path.join(llamaBinsDirectory, `${platform}-${arch}/llama-addon.node`);
2219
}
2320

24-
async function resolvePath(platform: string, arch: string, nodeVersions: number[]) {
25-
for (const nodeVersion of nodeVersions) {
26-
const binPath = createPath(platform, arch, nodeVersion);
21+
async function resolvePath(platform: string, arch: string) {
22+
const binPath = createPath(platform, arch);
2723

28-
if (await fs.pathExists(binPath))
29-
return binPath;
30-
}
24+
if (await fs.pathExists(binPath))
25+
return binPath;
3126

3227
return null;
3328
}
@@ -36,14 +31,14 @@ export async function getPrebuildBinPath(): Promise<string | null> {
3631
switch (process.platform) {
3732
case "win32":
3833
case "cygwin":
39-
return resolvePath("win", process.arch, supportedVersions);
34+
return resolvePath("win", process.arch);
4035

4136
case "linux":
4237
case "android":
43-
return resolvePath("linux", process.arch, supportedVersions);
38+
return resolvePath("linux", process.arch);
4439

4540
case "darwin":
46-
return resolvePath("mac", process.arch, supportedVersions);
41+
return resolvePath("mac", process.arch);
4742
}
4843

4944
return null;

0 commit comments

Comments
 (0)