ocaml / ocaml

The core OCaml system: compilers, runtime system, base libraries
https://ocaml.org
Other
5.19k stars 1.06k forks source link

Fix detection of zstd when compiling with musl-gcc #13100

Closed dra27 closed 3 weeks ago

dra27 commented 1 month ago

This is hopefully a fix for #12564. There are configurations for musl which would allow OCaml to be configured with zstd support, so unconditionally disabling zstd in the opam package feels wrong. A simpler approach seems to be to co-opt part of the validation added in #13029 and just check that we can actually link a zstd-enabled program before enabling the support.

The first part of this PR fixes a benign error from #13029 (the revert is in order to have a single cherry-pickable commit with the fix, because the intent is to be able to reference it from opam packages). Although the detection is correct, it still results in -lzstd being added to Makefile.config on Windows. It doesn't matter because when it comes to linking ocamlrun, etc., zstd isn't used so -lzstd is ignored (--as-needed semantics from flexlink). This issue is not however benign when using this code to fix musl (since -lzstd itself doesn't work).

The next commit then simplifies the runtime check slightly - there was logic to determine when to actually run the program which can simply be reduced to our own $host_runnable check.

Finally, the entire check is split into two. On all systems, if we're about to enable zstd (whether by pkg-config detection or old-style symbol checking in autoconf), we link a trivial test program. On Windows, this program is then also run. So, on Windows, you get:

checking for x86_64-w64-mingw32-pkg-config... /usr/bin/x86_64-w64-mingw32-pkg-config
checking whether programs can be linked with zstd... yes
checking whether programs linked with zstd can execute... no
configure: WARNING: programs linked with zstd do not appear to be executable.
configure: WARNING: compressed compilation artefacts not supported

if the mingw-w64 zstd package is installed, but the sys-root bin directory is not in PATH. On Ubuntu, with musl-tools, pkg-config and libzstd-dev installed, you now get:

checking for pkg-config... /usr/bin/pkg-config
checking whether programs can be linked with zstd... no
configure: WARNING: zstd found, but programs cannot be linked with it.
configure: WARNING: compressed compilation artefacts not supported

and for a normal Ubuntu build you now get:

checking for pkg-config... /usr/bin/pkg-config
checking whether programs can be linked with zstd... yes
checking whether programs linked with zstd can execute... skipped
configure: compressed compilation artefacts supported
dra27 commented 3 weeks ago

Thank you, both!