Skip to content

Commit

Permalink
Read LIBC environment value
Browse files Browse the repository at this point in the history
  • Loading branch information
joonamo committed Apr 22, 2022
1 parent d396a4e commit 94b50c3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
17 changes: 13 additions & 4 deletions docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,28 @@ The target platform and/or architecture can be manually selected using the follo
npm install --platform=... --arch=... --arm-version=... sharp
```

* `--platform`: one of `linux`, `linuxmusl`, `darwin` or `win32`.
* `--platform`: one of `linux`, `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`. This option only works with platform `linux`, defaults to `glibc`
* `--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
Expand Down Expand Up @@ -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.
Expand Down
7 changes: 4 additions & 3 deletions lib/platform.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ 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 ||
(detectLibc.isNonGlibcLinuxSync() ? detectLibc.familySync() : '');
const libcId = platform !== 'linux' || libc === detectLibc.GLIBC ? '' : libc;

const platformId = [`${platform}${libc}`];
const platformId = [`${platform}${libcId}`];

if (arch === 'arm') {
const fallback = process.versions.electron ? '7' : '6';
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
"color": "^4.2.3",
"detect-libc": "^2.0.1",
"node-addon-api": "^4.3.0",
"prebuild-install": "^7.0.1",
"prebuild-install": "^7.1.0",
"semver": "^7.3.7",
"simple-get": "^4.0.1",
"tar-fs": "^2.1.1",
Expand Down

0 comments on commit 94b50c3

Please sign in to comment.