Skip to content

Commit

Permalink
fix!: Differentiate host arm versions
Browse files Browse the repository at this point in the history
The node `process.arch` variable doesn't differentiate between armv6 or
armv7. Therefore we need to additionally consult
`process.config.variables.arm_version` when computing the host triplet.

See nodejs/node#9491

BREAKING CHANGE: The library won't find arm prebuilts from previous
                 alphas unless the package is rebuilt.
  • Loading branch information
BurningEnlightenment committed May 10, 2023
1 parent 6085562 commit 1ccb1d3
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/triplet.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { arch, env, platform } from "node:process";
import { arch, config, env, platform } from "node:process";

import { familySync } from "detect-libc";

Expand Down Expand Up @@ -50,13 +50,26 @@ export interface Triplet {
libc: string | null;
}

function hasArmVersion(
vars: NodeJS.ProcessConfig["variables"],
): vars is NodeJS.ProcessConfig["variables"] & {
arm_version: string;
} {
return "arm_version" in vars;
}
// see https://github.com/nodejs/node/issues/9491
const sanitizedArch =
arch !== "arm" || !hasArmVersion(config.variables)
? arch
: `armv${config.variables.arm_version}`;

/**
* Returns the triplet of the currently executing process.
*/
export function hostTriplet(): Triplet {
return {
platform,
arch,
arch: sanitizedArch,
libc: familySync(),
};
}
Expand Down

0 comments on commit 1ccb1d3

Please sign in to comment.