php-vips
php-vips copied to clipboard
VIPSHOME misused/unsupported on Windows
$vipshome = getenv("VIPSHOME");
if ($vipshome) {
// lib<qual>/ predicates lib/
$libraryPaths[] = $vipshome . ($is_64bits ? "/lib64/" : "/lib32/");
// lib/ is always searched
$libraryPaths[] = $vipshome . "/lib/";
}
How should VIPSHOME
be configured on Windows?
The Windows download contains a bin
and a lib
subdirectory, however the library itself (libvips-42.dll
) is in the bin
.
Assuming I downloaded the package to C:\vips
,
- when
VIPSHOME=C:\vips
, the library will be searched inC:\vips\lib
- the path exists, but the library doesn't - when
VIPSHOME=C:\vips\bin
, the library will be searched inC:\vips\bin\lib
, which doesn't exist
I see the following options:
- simply add
VIPSHOME
as a potential library location (without a platform check; might be useful to other platforms, not just Window):if ($vipshome) { $libraryPaths[] = $vipshome . '/'; …
- make it support the Windows structure differently:
if ($vipshome) { if (PHP_OS_FAMILY === "Windows") { $libraryPaths[] = $vipshome . '/'; } else { // lib<qual>/ predicates lib/ $libraryPaths[] = $vipshome . ($is_64bits ? "/lib64/" : "/lib32/"); // lib/ is always searched $libraryPaths[] = $vipshome . "/lib/"; } }
- show an error on Windows:
if ($vipshome) { if (PHP_OS_FAMILY === "Windows") { throw new RuntimeException('VIPSHOME is not supported on Windows'); } …
AFAIK, VIPSHOME
is only useful for debugging purposes when libvips is configured with a non-standard prefix.
On Windows, it's probably more appropriate to add the directory containing the libvips binaries to the PATH
environment variable.
On Linux, configuring the LD_LIBRARY_PATH
environment variable is recommended if you've installed libvips on a non-standard path (anything other than /usr
or /usr/local
).
On macOS, although the DYLD_LIBRARY_PATH
environment variable can serve a similar purpose, it's important to note that System Integrity Protection (SIP) strips any environment variables prefixed with DYLD_
or LD_
, making the use of VIPSHOME
a viable alternative.
Hallo @kleisauke!
AFAIK,
VIPSHOME
is only useful for debugging purposes when libvips is configured with a non-standard prefix.
I haven't seen this documented anywhere, and since _HOME
env vars are a common (and cross-platform) idiom. I myself currently have NVM_HOME
and COMPOSER_HOME
on Windows, and have used JAVA_HOME
in the past too.
On Windows, it's probably more appropriate to add the directory containing the libvips binaries to the
PATH
environment variable.
I did that first, but it didn't work, due to something unrelated, so I thought about being more explicit by setting VIPSHOME
.
It seems I'm not the only one to think that.
On Linux, configuring the
LD_LIBRARY_PATH
environment variable is recommended if you've installed libvips on a non-standard path (anything other than/usr
or/usr/local
).
On macOS, although the
DYLD_LIBRARY_PATH
environment variable can serve a similar purpose, it's important to note that System Integrity Protection (SIP) strips any environment variables prefixed withDYLD_
orLD_
, making the use ofVIPSHOME
a viable alternative.
I had problems on macOS as well, this fixed it though (hopefully it works for others as well): https://github.com/libvips/php-vips/pull/230/files#diff-af517c8d5f9b563337e63a34642e704941719528e595a608cf93ced1c6609478R275
But my main point is that we shouldn't leave the behaviour on Windows as "broken" or "undefined" - I don't have a strong opinion on which option to take, but we should be explicit about it IMO.
- simply add
VIPSHOME
as a potential library location (without a platform check; might be useful to other platforms, not just Window):
+1 for this options. There are a few use cases where the library is in a specific folder, in my case, I have the portable precompiled binary from https://github.com/lovell/sharp-libvips