Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VIPSHOME misused/unsupported on Windows #232

Open
uuf6429 opened this issue Feb 3, 2024 · 3 comments
Open

VIPSHOME misused/unsupported on Windows #232

uuf6429 opened this issue Feb 3, 2024 · 3 comments

Comments

@uuf6429
Copy link
Contributor

uuf6429 commented Feb 3, 2024

        $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');
              }
              …
@kleisauke
Copy link
Member

kleisauke commented Feb 14, 2024

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.

@uuf6429
Copy link
Contributor Author

uuf6429 commented Feb 14, 2024

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.

@CodeWithKyrian
Copy link

  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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants