diff --git a/lib/postinstall.js b/lib/postinstall.js index b2f43bd..b439905 100644 --- a/lib/postinstall.js +++ b/lib/postinstall.js @@ -5,11 +5,13 @@ const os = require('os'); const fs = require('fs'); const path = require('path'); const util = require('util'); +const child_process = require('child_process'); const download = require('./download'); const fsExists = util.promisify(fs.exists); const mkdir = util.promisify(fs.mkdir); +const exec = util.promisify(child_process.exec); const forceInstall = process.argv.includes('--force'); if (forceInstall) { @@ -23,7 +25,20 @@ process.on('unhandledRejection', (reason, promise) => { console.log('Unhandled rejection: ', promise, 'reason:', reason); }); -function getTarget() { +async function isMusl() { + let stderr; + try { + stderr = (await exec('ldd --version')).stderr; + } catch (err) { + stderr = err.stderr; + } + if(stderr.indexOf('musl') > -1) { + return true; + } + return false; +} + +async function getTarget() { const arch = process.env.npm_config_arch || os.arch(); switch (os.platform()) { @@ -38,7 +53,7 @@ function getTarget() { return arch === 'x64' ? 'x86_64-unknown-linux-musl' : arch === 'arm' ? 'arm-unknown-linux-gnueabihf' : arch === 'armv7l' ? 'arm-unknown-linux-gnueabihf' : - arch === 'arm64' ? 'aarch64-unknown-linux-gnu' : + arch === 'arm64' ? await isMusl() ? 'aarch64-unknown-linux-musl' : 'aarch64-unknown-linux-gnu' : arch === 'ppc64' ? 'powerpc64le-unknown-linux-gnu' : arch === 's390x' ? 's390x-unknown-linux-gnu' : 'i686-unknown-linux-musl' @@ -60,7 +75,7 @@ async function main() { const opts = { version: VERSION, token: process.env['GITHUB_TOKEN'], - target: getTarget(), + target: await getTarget(), destDir: BIN_PATH, force: forceInstall };