From d35170cabe03c6c048d08a0dc4c366bbe6c6e807 Mon Sep 17 00:00:00 2001 From: Kate Date: Tue, 3 Sep 2024 17:34:12 +0100 Subject: [PATCH] Fix Windows builds with OCaml >= 5.0 --- configure | 42 ++++++++++++++++++- configure.ac | 7 +++- master_changes.md | 1 + opam-core.opam | 2 +- src/core/dune | 8 ++++ ...opamStubs.win32.ml => opamStubs.ocaml4.ml} | 0 src/core/opamStubs.ocaml5.ml | 17 ++++++++ 7 files changed, 74 insertions(+), 3 deletions(-) rename src/core/{opamStubs.win32.ml => opamStubs.ocaml4.ml} (100%) create mode 100644 src/core/opamStubs.ocaml5.ml diff --git a/configure b/configure index b4f27953b88..0f17f6b7206 100755 --- a/configure +++ b/configure @@ -6111,7 +6111,47 @@ esac if test "${enable_static}" = yes then : - echo "(-noautolink -cclib -lunix -cclib -lmccs_stubs -cclib -lmccs_glpk_stubs -cclib -lsha_stubs ${platform_dependent_stuff})" > src/client/linking.sexp + + + + # Used to indicate true or false condition + ax_compare_version=false + + # Convert the two version strings to be compared into a format that + # allows a simple string comparison. The end result is that a version + # string of the form 1.12.5-r617 will be converted to the form + # 0001001200050617. In other words, each number is zero padded to four + # digits, and non digits are removed. + + ax_compare_version_A=`echo "$OCAMLVERSION" | sed -e 's/\([0-9]*\)/Z\1Z/g' \ + -e 's/Z\([0-9]\)Z/Z0\1Z/g' \ + -e 's/Z\([0-9][0-9]\)Z/Z0\1Z/g' \ + -e 's/Z\([0-9][0-9][0-9]\)Z/Z0\1Z/g' \ + -e 's/[^0-9]//g'` + + + ax_compare_version_B=`echo "5.0.0" | sed -e 's/\([0-9]*\)/Z\1Z/g' \ + -e 's/Z\([0-9]\)Z/Z0\1Z/g' \ + -e 's/Z\([0-9][0-9]\)Z/Z0\1Z/g' \ + -e 's/Z\([0-9][0-9][0-9]\)Z/Z0\1Z/g' \ + -e 's/[^0-9]//g'` + + + ax_compare_version=`echo "x$ax_compare_version_A +x$ax_compare_version_B" | sed 's/^ *//' | sort -r | sed "s/x${ax_compare_version_A}/false/;s/x${ax_compare_version_B}/true/;1q"` + + + + if test "$ax_compare_version" = "true" ; then + + unix_lib_name=unix + + else + unix_lib_name=unixnat + + fi + + echo "(-noautolink -cclib -l${unix_lib_name} -cclib -lmccs_stubs -cclib -lmccs_glpk_stubs -cclib -lsha_stubs ${platform_dependent_stuff})" > src/client/linking.sexp { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: static" >&5 printf "%s\n" "static" >&6; } diff --git a/configure.ac b/configure.ac index b8eee9723cc..756bbfe74d2 100644 --- a/configure.ac +++ b/configure.ac @@ -357,7 +357,12 @@ AS_CASE([${support_static},${enable_static}], [no,yes],[AC_MSG_ERROR([--enable-static is not available on this platform (${TARGET}).])], [*,auto],[enable_static=${default_static}]) AS_IF([test "${enable_static}" = yes],[ - echo "(-noautolink -cclib -lunix -cclib -lmccs_stubs -cclib -lmccs_glpk_stubs -cclib -lsha_stubs ${platform_dependent_stuff})" > src/client/linking.sexp + AX_COMPARE_VERSION([$OCAMLVERSION], [lt], [5.0.0],[ + unix_lib_name=unix + ],[ + unix_lib_name=unixnat + ]) + echo "(-noautolink -cclib -l${unix_lib_name} -cclib -lmccs_stubs -cclib -lmccs_glpk_stubs -cclib -lsha_stubs ${platform_dependent_stuff})" > src/client/linking.sexp AC_MSG_RESULT([static]) ],[ AC_MSG_RESULT([shared]) diff --git a/master_changes.md b/master_changes.md index 6cd33df3de3..cb3f4168230 100644 --- a/master_changes.md +++ b/master_changes.md @@ -109,6 +109,7 @@ users) * Bump the vendored opam-0install-cudf to 0.5.0 [#6130 @kit-ty-kate] * Require opam-0install-cudf >= 0.5.0 [#6130 @kit-ty-kate] * Bump the vendored mccs to 1.1+18 [#6170 @kit-ty-kate] + * Fix Windows builds with OCaml >= 5.0 [#6189 @kit-ty-kate - fix #6148] ## Infrastructure diff --git a/opam-core.opam b/opam-core.opam index efca47dc6b5..4778b85c518 100644 --- a/opam-core.opam +++ b/opam-core.opam @@ -22,7 +22,7 @@ license: "LGPL-2.1-only WITH OCaml-LGPL-linking-exception" homepage: "https://opam.ocaml.org" bug-reports: "https://github.com/ocaml/opam/issues" depends: [ - "ocaml" {>= "4.08.0" & (os != "win32" | < "5.0")} + "ocaml" {>= "4.08.0"} "base-unix" "ocamlgraph" "re" {>= "1.9.0"} diff --git a/src/core/dune b/src/core/dune index 226611716d8..b6ee4edac57 100644 --- a/src/core/dune +++ b/src/core/dune @@ -19,6 +19,14 @@ (rule (copy opamStubsTypes.ml opamStubsTypes.mli)) +(rule + (enabled_if (< %{ocaml_version} "5.0")) + (action (copy# opamStubs.ocaml4.ml opamStubs.win32.ml))) + +(rule + (enabled_if (>= %{ocaml_version} "5.0")) + (action (copy# opamStubs.ocaml5.ml opamStubs.win32.ml))) + (rule (write-file opamCoreConfigDeveloper.ml "let value = \"%{read-strings:developer}\"")) diff --git a/src/core/opamStubs.win32.ml b/src/core/opamStubs.ocaml4.ml similarity index 100% rename from src/core/opamStubs.win32.ml rename to src/core/opamStubs.ocaml4.ml diff --git a/src/core/opamStubs.ocaml5.ml b/src/core/opamStubs.ocaml5.ml new file mode 100644 index 00000000000..74f6c9c8c13 --- /dev/null +++ b/src/core/opamStubs.ocaml5.ml @@ -0,0 +1,17 @@ +(**************************************************************************) +(* *) +(* Copyright 2018 MetaStack Solutions Ltd. *) +(* *) +(* All rights reserved. This file is distributed under the terms of the *) +(* GNU Lesser General Public License version 2.1, with the special *) +(* exception on linking described in the file LICENSE. *) +(* *) +(**************************************************************************) + +include OpamStubsTypes +include OpamWin32Stubs +let getpid () = Int32.to_int (getCurrentProcessID ()) + +external win_create_process : string -> string -> string option -> + Unix.file_descr -> Unix.file_descr -> Unix.file_descr -> int + = "caml_unix_create_process" "caml_unix_create_process_native"