How to automatically replace zlib with the new zlib-ng: I need help and user contributions to write a tutorial #31116
Replies: 3 comments 8 replies
-
Why this strange triplet magic? Why is an overlay port for |
Beta Was this translation helpful? Give feedback.
-
This tutorial leads into the same problems that were described in #31077 (reply in thread). |
Beta Was this translation helpful? Give feedback.
-
VCPKG toolchain integration issues
I had to manually set FREETYPE_DIR to get the above log and discover that zlib was the source of the issue. I'm afraid this happens because my overlay port depends on zlib-ng which doesn't provide any CMake targets. When I switched to the old zlib (which provides targets), configuration went smooth. |
Beta Was this translation helpful? Give feedback.
-
This is a tutorial on how to automatically force each packages which depends on the old
zlib
to use the newzlib-ng
(compiled withZLIB_COMPAT
flag) in order to take advantage of the next gen instructions. Runningzlib-ng
natively is still the preferred way, but requires changes to the source code and this is not something that all developers are willing to do (at the time of writing, there is no port that useszlib-ng
).I initially proposed two different implementations (#30918 and #30937), but unfortunately there are a couple of issues that cannot be solved. Although is not possible to get this into the upstream, it can still be done locally by the user and (hope) safely. This tutorial shows each step and is not production ready. Probably there are bugs I'm not aware of and needs improvements, suggestions and fixes by the experts.
This is for Windows x64 dynamic linkage (the default triplet on Windows). Other configurations requires adjustments.
Required user environment variables (paths can be adjusted to user preference):
VCPKG_OVERLAY_PORTS
C:\dev\vcpkg\overlay-ports\zlib
VCPKG_OVERLAY_TRIPLETS
C:\dev\vcpkg\overlay-triplets
VCPKG_DEFAULT_TRIPLET
x64-windows-custom
Required files:
C:\dev\vcpkg\overlay-ports\zlib\portfile.cmake (not sure if an empty one is still fine):
set(VCPKG_POLICY_EMPTY_PACKAGE enabled)
C:\dev\vcpkg\overlay-ports\zlib\vcpkg.json:
The only purpose of
zlib-ng
dependency is to kick off update (and rerun our overlay port each time a new version ofzlib-ng
is published in the repo).C:\dev\vcpkg\overlay-triplets\x64-windows-custom.cmake:
this is where all the processing happens. It is basically a copy of the original
x64-windows
triplet with an additionalif()
condition that runs all the code if the port name iszlib
Usage
Install a package that depends on
zlib
as usual:vcpkg install freetype
Considerations and concerns
As @dg0yt kindly made pointed me out, vcpkg track the input of a given port through ABI hashing and artifacts can share the same cache key. I'm not sure if this may, or may not generate side effects. During trials I experienced several times changes to code ignored, but I saw no impact on functioning. I will wait for suggestions from experts because I have not the required knowledge to handle such low level stuff.
In
x64-windows-custom.cmake
there is a commented section of code which shows an alternative implementation instead of a file copy. It uses a symbolic link. I'm not sure on what would be the better solution.I would have preferred to avoid a custom overlay, but I didn't found a solution. A custom triplet is where I can change build configuration options and copy the original port file into the overlay folder (and get my package automatically updated without manually touching the source). A symbolic link could work, but its creation would have required running a pre-configuration external script while my main goal was to keep everything inside vcpkg chain.
The main purpose is to replace each old
zlib
dependency with the newzlib-ng
. If a project needs to reference some specialzlib
version compiled outside the vcpkg ecosystem, then special handling is needed (just like any other external library that needs to coexist with an existing vcpkg package that provides its own vcpkg compiled version).An empty
portfile.cmake
for the overlay port seems needed in order to avoid error. If there is some policy (applicable within the custom triplet) to ignore such error, then this useless file could be avoided.Beta Was this translation helpful? Give feedback.
All reactions