php-vips icon indicating copy to clipboard operation
php-vips copied to clipboard

VIPSHOME misused/unsupported on Windows

Open uuf6429 opened this issue 1 year ago • 3 comments

        $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 in C:\vips\lib - the path exists, but the library doesn't
  • when VIPSHOME=C:\vips\bin, the library will be searched in C:\vips\bin\lib, which doesn't exist

I see the following options:

  1. 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 . '/';
              …
    
  2. 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/";
              }
          }
    
  3. show an error on Windows:
          if ($vipshome) {
              if (PHP_OS_FAMILY === "Windows") {
                  throw new RuntimeException('VIPSHOME is not supported on Windows');
              }
              …
    

uuf6429 avatar Feb 03 '24 19:02 uuf6429

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.

kleisauke avatar Feb 14 '24 08:02 kleisauke

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 with DYLD_ or LD_, making the use of VIPSHOME 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.

uuf6429 avatar Feb 14 '24 19:02 uuf6429

  1. 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

CodeWithKyrian avatar Aug 24 '24 04:08 CodeWithKyrian