mirror of
https://github.com/lovell/sharp.git
synced 2025-07-09 10:30:15 +02:00
Improve experience for those using Apple M1 devices #2460
- For Rosetta x64, prevent use of global ARM64 libvips - For ARM64, improve error message when global libvips not found
This commit is contained in:
parent
cc37b59309
commit
4264c0577e
@ -60,7 +60,13 @@ Check the output of running `npm install --verbose sharp` for useful error messa
|
|||||||
|
|
||||||
## Apple M1
|
## Apple M1
|
||||||
|
|
||||||
libvips must currently be installed via Homebrew before installing sharp.
|
If you are using ARM64 Node.js, which can be checked using:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
node -p "process.arch === 'arm64'"
|
||||||
|
```
|
||||||
|
|
||||||
|
then libvips must currently be installed via Homebrew before installing sharp.
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
brew install vips
|
brew install vips
|
||||||
|
@ -74,6 +74,9 @@ try {
|
|||||||
if (arch === 'ia32' && !platformAndArch.startsWith('win32')) {
|
if (arch === 'ia32' && !platformAndArch.startsWith('win32')) {
|
||||||
throw new Error(`Intel Architecture 32-bit systems require manual installation of libvips >= ${minimumLibvipsVersion}`);
|
throw new Error(`Intel Architecture 32-bit systems require manual installation of libvips >= ${minimumLibvipsVersion}`);
|
||||||
}
|
}
|
||||||
|
if (platformAndArch === 'darwin-arm64') {
|
||||||
|
throw new Error("Please run 'brew install vips' to install libvips on Apple M1 (ARM64) systems");
|
||||||
|
}
|
||||||
if (platformAndArch === 'freebsd-x64' || platformAndArch === 'openbsd-x64' || platformAndArch === 'sunos-x64') {
|
if (platformAndArch === 'freebsd-x64' || platformAndArch === 'openbsd-x64' || platformAndArch === 'sunos-x64') {
|
||||||
throw new Error(`BSD/SunOS systems require manual installation of libvips >= ${minimumLibvipsVersion}`);
|
throw new Error(`BSD/SunOS systems require manual installation of libvips >= ${minimumLibvipsVersion}`);
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,15 @@ const cachePath = function () {
|
|||||||
return libvipsCachePath;
|
return libvipsCachePath;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const isRosetta = function () {
|
||||||
|
/* istanbul ignore next */
|
||||||
|
if (process.platform === 'darwin' && process.arch === 'x64') {
|
||||||
|
const translated = spawnSync('sysctl sysctl.proc_translated', spawnSyncOptions).stdout;
|
||||||
|
return (translated || '').trim() === 'sysctl.proc_translated: 1';
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
const globalLibvipsVersion = function () {
|
const globalLibvipsVersion = function () {
|
||||||
if (process.platform !== 'win32') {
|
if (process.platform !== 'win32') {
|
||||||
const globalLibvipsVersion = spawnSync(`PKG_CONFIG_PATH="${pkgConfigPath()}" pkg-config --modversion vips-cpp`, spawnSyncOptions).stdout;
|
const globalLibvipsVersion = spawnSync(`PKG_CONFIG_PATH="${pkgConfigPath()}" pkg-config --modversion vips-cpp`, spawnSyncOptions).stdout;
|
||||||
@ -82,7 +91,10 @@ const useGlobalLibvips = function () {
|
|||||||
if (Boolean(env.SHARP_IGNORE_GLOBAL_LIBVIPS) === true) {
|
if (Boolean(env.SHARP_IGNORE_GLOBAL_LIBVIPS) === true) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
/* istanbul ignore next */
|
||||||
|
if (isRosetta()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
const globalVipsVersion = globalLibvipsVersion();
|
const globalVipsVersion = globalLibvipsVersion();
|
||||||
return !!globalVipsVersion && /* istanbul ignore next */
|
return !!globalVipsVersion && /* istanbul ignore next */
|
||||||
semver.gte(globalVipsVersion, minimumLibvipsVersion);
|
semver.gte(globalVipsVersion, minimumLibvipsVersion);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user