From ace1350923cf62fcef2da7d67c5ceec05fd309e1 Mon Sep 17 00:00:00 2001 From: Joona Heinikoski Date: Fri, 18 Mar 2022 14:21:11 +0200 Subject: [PATCH] Read LIBC environment value --- docs/install.md | 15 ++++++++++++--- lib/platform.js | 9 ++++++--- package.json | 4 ++-- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/docs/install.md b/docs/install.md index 6bd79c09c..3305b0139 100644 --- a/docs/install.md +++ b/docs/install.md @@ -77,17 +77,25 @@ npm install --platform=... --arch=... --arm-version=... sharp * `--platform`: one of `linux`, `linuxmusl`, `darwin` or `win32`. * `--arch`: one of `x64`, `ia32`, `arm` or `arm64`. * `--arm-version`: one of `6`, `7` or `8` (`arm` defaults to `6`, `arm64` defaults to `8`). +* `--libc`: one of `glibc` or `musl`. When using this option, platform should be `linux` * `--sharp-install-force`: skip version compatibility and Subresource Integrity checks. These values can also be set via environment variables, -`npm_config_platform`, `npm_config_arch`, `npm_config_arm_version` +`npm_config_platform`, `npm_config_arch`, `npm_config_arm_version`, `npm_config_libc` and `SHARP_INSTALL_FORCE` respectively. For example, if the target machine has a 64-bit ARM CPU and is running Alpine Linux, use the following flags: ```sh -npm install --arch=arm64 --platform=linuxmusl sharp +npm install --arch=arm64 --platform=linux --libc=musl sharp +``` + +If the current machine is Alpine Linux and the target machine is Debian Linux on x64 cpu, +use the following flags: + +```sh +npm install --arch=x64 --platform=linux --libc=glibc sharp ``` ## Custom libvips @@ -207,7 +215,8 @@ run the following additional command after `npm install`: ```sh npm install -SHARP_IGNORE_GLOBAL_LIBVIPS=1 npm install --arch=x64 --platform=linux sharp +rm -rf node_modules/sharp +SHARP_IGNORE_GLOBAL_LIBVIPS=1 npm install --arch=x64 --platform=linux --libc=glibc sharp ``` To get the best performance select the largest memory available. diff --git a/lib/platform.js b/lib/platform.js index 185d7d778..225659e44 100644 --- a/lib/platform.js +++ b/lib/platform.js @@ -7,10 +7,13 @@ const env = process.env; module.exports = function () { const arch = env.npm_config_arch || process.arch; const platform = env.npm_config_platform || process.platform; - /* istanbul ignore next */ - const libc = (platform === 'linux' && detectLibc.isNonGlibcLinuxSync()) ? detectLibc.familySync() : ''; + const libc = process.env.LIBC || process.env.npm_config_libc || ( + /* istanbul ignore next */ + (platform === 'linux' && detectLibc.isNonGlibcLinuxSync()) ? detectLibc.familySync() : '' + ); + const libcId = libc === detectLibc.GLIBC ? '' : libc; - const platformId = [`${platform}${libc}`]; + const platformId = [`${platform}${libcId}`]; if (arch === 'arm') { const fallback = process.versions.electron ? '7' : '6'; diff --git a/package.json b/package.json index ec24a374c..e146b2c5a 100644 --- a/package.json +++ b/package.json @@ -84,7 +84,7 @@ "Ompal Singh " ], "scripts": { - "install": "(node install/libvips && node install/dll-copy && prebuild-install) || (node install/can-compile && node-gyp rebuild && node install/dll-copy)", + "install": "(node install/libvips && node install/dll-copy && prebuild-install --force) || (node install/can-compile && node-gyp rebuild && node install/dll-copy)", "clean": "rm -rf node_modules/ build/ vendor/ .nyc_output/ coverage/ test/fixtures/output.*", "test": "npm run test-lint && npm run test-unit && npm run test-licensing", "test-lint": "semistandard && cpplint", @@ -129,7 +129,7 @@ "color": "^4.2.1", "detect-libc": "^2.0.1", "node-addon-api": "^4.3.0", - "prebuild-install": "^7.0.1", + "prebuild-install": "https://github.com/joonamo/prebuild-install.git#glibc-on-non-glibc-machine", "semver": "^7.3.5", "simple-get": "^4.0.1", "tar-fs": "^2.1.1",