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

[skip ci] Drop ZIP_STATIC hack #15963

Closed
wants to merge 1 commit into from
Closed

Conversation

cmb69
Copy link
Member

@cmb69 cmb69 commented Sep 20, 2024

Old versions of libzip didn't export the ZIP_STATIC macro, even if they had been built as static libraries. This hack in config.w32 is supposed to counteract that, since the macro is used in zip.h. However, PHP has no business in defining macros belonging to external libraries; instead the winlibs builds should have been fixed to set this macro in zip.h. Furthermore, as of libzip there is zipconf.h, where this macro is defined as appropriate, if libzip was build with the proper configuration options. Unfortunately, that has not been done so far, but assuming that new properly configured builds of libzip will be rolled out, we need to drop this hack to avoid conflicting macro definitions, since we define the macro to 1, but libzip only defines it (without further hackery).


This falls in the category "things that should not have happened, and either we apply the painful fix now, or never". The fix is painful, because with the currently shipped winlib libzip builds, ext/zip can no longer be built on Windows (thus [skip ci]), while properly configured static builds of libzip (-DBUILD_SHARED_LIBS=OFF) won't work without this fix (or additional hacks in zipconf.h). Now, the simple fix of using #cmakedefine01 instead of #cmakedefine would work for static libzip builds (even with this patch), but not for shared builds of libzip.

Besides that ext/zip should never have used this hack in the first place, the problem appears to be that CMake either uses #define/#undef, or #define 1/#define 0, while our AC_DEFINE does not support #define/#undef at all.

And this is even more painful, because pecl/zip also defines ZIP_STATIC for static libzip builds, and does not even allow to build against shared libzip. Considering this, it might be best to stick with the hack forever, and patch libzip respectively to suit ext/zip; and to back away from dreaming that PHP on Windows can ever be built against unpatched dependency libraries.

Alternatives include to ignore the C4005 warning, not to build with /WX, to undefine the macro prior to the collsion, or to add support for #define to our AC_DEFINE.

cc @petk, @remicollet and @shivammathur

Old versions of libzip didn't export the `ZIP_STATIC` macro, even if
they had been built as static libraries.  This hack in config.w32 is
supposed to counteract that, since the macro is used in zip.h.
However, PHP has no business in defining macros belonging to external
libraries; instead the winlibs builds should have been fixed to set
this macro in zip.h.  Furthermore, as of libzip there is zipconf.h,
where this macro is defined as appropriate, if libzip was build with
the proper configuration options.  Unfortunately, that has not been
done so far, but assuming that new properly configured builds of libzip
will be rolled out, we need to drop this hack to avoid conflicting
macro definitions, since we define the macro to 1, but libzip only
defines it (without further hackery).
@petk
Copy link
Member

petk commented Sep 20, 2024

ZIP_STATIC became internal as of libzip version 1.4.0 and was used when building with static libzip on Windows since libzip 1.0 to 1.3.2. Sure, it can be removed then here, yes since winlibs are using 1.7.1 version.

For the PHP version after PHP 8.4, it would be also good to bump libzip to something like 1.4.0 as minimum version (released in december 2017 which makes it pretty adopted everywhere by now). Because the 1.4.0 version became a bit simpler to use (it has version defined and this static macro resolved internally by its build system).

But, I'm not sure I fully understand the pecl/zip issue here. Patch can be sent also to https://github.com/pierrejoye/php_zip/blob/master/config.w32 and a new release done and it's good to go. I'm not even sure anymore why is there still zip extension on PECL when the zip extension is located in the php-src. @remicollet please see also this #15575 when you have some time.

The libzip version is available since 1.4.0 in zip.conf file. So there could be done something like this for the PECL zip extension when using newer libzip versions to reduce this issue a bit:

if (GREP_HEADER("zipconf.h", "#define\\s+LIBZIP_VERSION_MAJOR\\s+(\\d+)", PHP_PHP_BUILD + "\\include") &&
  +RegExp.$1 >= 1 &&
  GREP_HEADER("zipconf.h", "#define\\s+LIBZIP_VERSION_MINOR\\s+(\\d+)", PHP_PHP_BUILD + "\\include") &&
  +RegExp.$1 >= 4
) {} else {
  if (get_define("LIBS_ZIP").match("libzip_a(?:_debug)?\.lib")) {
    /* Using static dependency lib. */
    AC_DEFINE("ZIP_STATIC", 1);
  }
}

(this code should be adapted and fined tune more of course)

Copy link
Member

@petk petk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems good to go into php-src from my PoV.

@cmb69
Copy link
Member Author

cmb69 commented Sep 21, 2024

ZIP_STATIC became internal as of libzip version 1.4.0 and was used when building with static libzip on Windows since libzip 1.0 to 1.3.2.

No.

@cmb69 cmb69 closed this Sep 21, 2024
@cmb69 cmb69 deleted the cmb/zip-static branch September 21, 2024 12:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants