Skip to content

Commit

Permalink
Install: advanced option to force global libvips #4060
Browse files Browse the repository at this point in the history
  • Loading branch information
lovell committed Apr 10, 2024
1 parent f67228e commit 579cf93
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 6 deletions.
3 changes: 3 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ Requires libvips v8.15.2
[#4048](https://github.com/lovell/sharp/pull/4048)
[@ike-gg](https://github.com/ike-gg)

* Install: add advanced option to force use of a globally-installed libvips.
[#4060](https://github.com/lovell/sharp/issues/4060)

* Expose `bilinear` resizing kernel (and interpolator).
[#4061](https://github.com/lovell/sharp/issues/4061)

Expand Down
7 changes: 6 additions & 1 deletion docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,14 @@ and on macOS when running Node.js under Rosetta.

This module will be compiled from source at `npm install` time when:

* a globally-installed libvips is detected (set the `SHARP_IGNORE_GLOBAL_LIBVIPS` environment variable to skip this), or
* a globally-installed libvips is detected, or
* when the `npm install --build-from-source` flag is used.

The logic to detect a globally-installed libvips can be skipped by setting the
`SHARP_IGNORE_GLOBAL_LIBVIPS` (never try to use it) or
`SHARP_FORCE_GLOBAL_LIBVIPS` (always try to use it, even when missing or outdated)
environment variables.

Building from source requires:

* C++11 compiler
Expand Down
2 changes: 1 addition & 1 deletion docs/search-index.json

Large diffs are not rendered by default.

14 changes: 10 additions & 4 deletions lib/libvips.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,21 @@ const pkgConfigPath = () => {
}
};

const skipSearch = (status, reason) => {
log(`Detected ${reason}, skipping search for globally-installed libvips`);
return status;
};

const useGlobalLibvips = () => {
if (Boolean(process.env.SHARP_IGNORE_GLOBAL_LIBVIPS) === true) {
log('Detected SHARP_IGNORE_GLOBAL_LIBVIPS, skipping search for globally-installed libvips');
return false;
return skipSearch(false, 'SHARP_IGNORE_GLOBAL_LIBVIPS');
}
if (Boolean(process.env.SHARP_FORCE_GLOBAL_LIBVIPS) === true) {
return skipSearch(true, 'SHARP_FORCE_GLOBAL_LIBVIPS');
}
/* istanbul ignore next */
if (isRosetta()) {
log('Detected Rosetta, skipping search for globally-installed libvips');
return false;
return skipSearch(false, 'Rosetta');
}
const globalVipsVersion = globalLibvipsVersion();
return !!globalVipsVersion && /* istanbul ignore next */
Expand Down
8 changes: 8 additions & 0 deletions test/unit/libvips.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ describe('libvips binaries', function () {

delete process.env.SHARP_IGNORE_GLOBAL_LIBVIPS;
});
it('useGlobalLibvips can be forced via an env var', function () {
process.env.SHARP_FORCE_GLOBAL_LIBVIPS = 1;

const useGlobalLibvips = libvips.useGlobalLibvips();
assert.strictEqual(true, useGlobalLibvips);

delete process.env.SHARP_FORCE_GLOBAL_LIBVIPS;
});
});

describe('Build time platform detection', () => {
Expand Down

0 comments on commit 579cf93

Please sign in to comment.