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

Fix the compilation of opam on Windows with OCaml >= 5.0 (again) #6216

Merged
merged 5 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 0 additions & 42 deletions .github/scripts/main/create-ocaml-cache.sh

This file was deleted.

4 changes: 0 additions & 4 deletions .github/scripts/main/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ case "$1" in
CONFIGURE_PREFIX="$PREFIX";;
esac

if [ -e "$OCAML_LOCAL/_build" ]; then
cp -a "$OCAML_LOCAL/_build" .
fi

./configure --prefix $CONFIGURE_PREFIX --with-vendored-deps --with-mccs
if [ "$OPAM_TEST" != "1" ]; then
echo 'DUNE_PROFILE=dev' >> Makefile.config
Expand Down
12 changes: 7 additions & 5 deletions .github/scripts/main/ocaml-cache.sh
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,10 @@ EOF
chmod +x "$OCAML_LOCAL/bin/ocamldoc"
fi

# Hand-over control to a separate script in case the branch being tested
# updates this script, which will fail on Windows (since the script is "open"
# and can't be overwritten)
cp -pf .github/scripts/main/create-ocaml-cache.sh ../create-ocaml-cache.sh
exec ../create-ocaml-cache.sh "$OCAML_BRANCH" "$PREFIX" "$EXE" "$OCAML_LOCAL" "$PLATFORM"
make -C src_ext dune-local.stamp
cd src_ext/dune-local
ocaml boot/bootstrap.ml
cp _boot/dune.exe "$PREFIX/bin/dune$EXE"
cd ../..

git clean -dfX
50 changes: 37 additions & 13 deletions .github/workflows/ci.ml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,17 @@

open Lib

let latest_ocaml4 = "4.14.2"
let latest_ocaml5 = "5.2.0" (* Add this number to ocamls below when the next version comes out *)
let ocamls = [
(* Fully supported versions *)
"4.08.1"; "4.09.1"; "4.10.2"; "4.11.2"; "4.12.1"; "4.13.1"; "5.0.0"; "5.1.1"; "4.14.1";
"4.08.1"; "4.09.1"; "4.10.2"; "4.11.2"; "4.12.1"; "4.13.1";
"5.0.0"; "5.1.1";

(* The last elements of the list after 4.14 will be used as default versions *)
latest_ocaml4; latest_ocaml5;
]
let start_latests_ocaml = (4, 14)

(* Entry point for the workflow. Workflows are specified as continuations where
each job is passed as a continuation to the [workflow], terminated with
Expand Down Expand Up @@ -65,8 +72,6 @@ let end_workflow ~oc:_ ~workflow:_ = ()
let ocamls =
List.map (fun v -> Scanf.sscanf v "%u.%u.%u" (fun major minor _ -> ((major, minor), v))) ocamls

let latest_ocaml = List.fold_left (fun _ (v, _) -> v) (0, 0) ocamls

let platform_ocaml_matrix ?(dir=List.drop_while) ~fail_fast start_version =
(fail_fast,
[("ocamlv", List.map snd (dir (fun ocaml -> fst ocaml <> start_version) ocamls))],
Expand Down Expand Up @@ -296,13 +301,32 @@ let main_build_job ~analyse_job ~cygwin_job ?section runner start_version ~oc ~w
(* Intentionally fail fast, no need to run all build if there is a
* problem in a given version; usually it is functions not defined in lower
* versions of OCaml. *)
let (_fail_fast, matrix, _) = platform_ocaml_matrix ~fail_fast:true start_version in
let (matrix, includes) =
if platform = Windows then
(("host", ["x86_64-pc-cygwin"; "i686-w64-mingw32"; "x86_64-w64-mingw32"; "i686-pc-windows"; "x86_64-pc-windows"]) ::
("build", ["x86_64-pc-cygwin"]) ::
matrix, [])
let matrix =
let ocaml4 = [
"x86_64-pc-cygwin";
"i686-w64-mingw32";
"x86_64-w64-mingw32";
"i686-pc-windows";
"x86_64-pc-windows"
] in
let ocaml5 = [
"x86_64-w64-mingw32";
(* "x86_64-pc-windows"; 5.3 needed *)
] in
let matrix_elem ocamlv hosts =
let elem ocaml host =
[("host", host); ("build", "x86_64-pc-cygwin"); ("ocamlv", ocaml)]
in
List.map (elem ocamlv) hosts
in
matrix_elem latest_ocaml4 ocaml4
@ matrix_elem latest_ocaml5 ocaml5
in
([], matrix)
else
let (_fail_fast, matrix, _) = platform_ocaml_matrix ~fail_fast:true start_version in
(matrix, []) in
let matrix = ((platform <> Windows), matrix, includes) in
let needs = if platform = Windows then [analyse_job; cygwin_job] else [analyse_job] in
Expand Down Expand Up @@ -351,7 +375,7 @@ let main_test_job ~analyse_job ~build_linux_job ~build_windows_job:_ ~build_macO
| MacOS -> [analyse_job] (* This isn't gated on build_macOS_job for speed *)
| Linux -> [analyse_job; build_linux_job]
in
let matrix = platform_ocaml_matrix ~fail_fast:false latest_ocaml in
let matrix = platform_ocaml_matrix ~fail_fast:false start_latests_ocaml in
let host = host_of_platform platform in
let ocamlv = "${{ matrix.ocamlv }}" in
job ~oc ~workflow ?section ~runs_on:(Runner [runner]) ~env:[("OPAM_TEST", "1")] ~matrix ~needs ("Test-" ^ name_of_platform platform)
Expand Down Expand Up @@ -391,7 +415,7 @@ let solvers_job ~analyse_job ~build_linux_job ~build_windows_job ~build_macOS_jo
let only_on target = only_on platform target in
let needs = [analyse_job; (match platform with Linux -> build_linux_job | Windows -> build_windows_job | MacOS -> build_macOS_job)] in
let env = [("SOLVER", "${{ matrix.solver }}"); ("OPAMBSROOT", "~/.cache/opam.${{ matrix.solver }}.cached")] in
let (fail_fast, matrix, _) = platform_ocaml_matrix ~fail_fast:false latest_ocaml in
let (fail_fast, matrix, _) = platform_ocaml_matrix ~fail_fast:false start_latests_ocaml in
let matrix =
(fail_fast, ("solver", ["z3"; "0install"])::matrix, [])
in
Expand All @@ -413,7 +437,7 @@ let upgrade_job ~analyse_job ~build_linux_job ~build_windows_job ~build_macOS_jo
let host = host_of_platform platform in
let only_on target = only_on platform target in
let needs = [analyse_job; (match platform with Linux -> build_linux_job | Windows -> build_windows_job | MacOS -> build_macOS_job)] in
let matrix = platform_ocaml_matrix ~fail_fast:false latest_ocaml in
let matrix = platform_ocaml_matrix ~fail_fast:false start_latests_ocaml in
let ocamlv = "${{ matrix.ocamlv }}" in
job ~oc ~workflow ?section ~runs_on:(Runner [runner]) ~needs ~matrix ("Upgrade-" ^ name_of_platform platform)
++ only_on Linux (run "Install bubblewrap" ["sudo apt install bubblewrap"])
Expand Down Expand Up @@ -482,16 +506,16 @@ let main oc : unit =
] in
let keys = [
("archives", "archives-1-${{ hashFiles('src_ext/Makefile.dune', 'src_ext/Makefile.sources', 'src_ext/Makefile', '.github/scripts/common/preamble.sh', '.github/scripts/main/preamble.sh', '.github/scripts/main/archives-cache.sh') }}-${{ env.OPAM_REPO_SHA }}");
("ocaml-cache", "${{ hashFiles('src_ext/Makefile.dune', '.github/scripts/main/ocaml-cache.sh', '.github/scripts/main/preamble.sh', '.github/scripts/main/create-ocaml-cache.sh') }}");
("ocaml-cache", "${{ hashFiles('src_ext/Makefile.dune', '.github/scripts/main/ocaml-cache.sh', '.github/scripts/main/preamble.sh') }}");
("cygwin", "${{ hashFiles('.github/scripts/cygwin.cmd') }}-${{ env.CYGWIN_EPOCH }}");
("opam-bs-cache", "${{ hashFiles('.github/scripts/main/opam-bs-cache.sh', '*.opam', '.github/scripts/main/preamble.sh') }}");
] in
workflow ~oc ~env "Builds, tests & co"
++ analyse_job ~keys ~platforms:[Linux]
@@ fun analyse_job -> cygwin_job ~analyse_job
@@ fun cygwin_job -> main_build_job ~analyse_job ~cygwin_job ~section:"Build" Linux (4, 08)
@@ fun build_linux_job -> main_build_job ~analyse_job ~cygwin_job Windows latest_ocaml
@@ fun build_windows_job -> main_build_job ~analyse_job ~cygwin_job MacOS latest_ocaml
@@ fun build_linux_job -> main_build_job ~analyse_job ~cygwin_job Windows start_latests_ocaml
@@ fun build_windows_job -> main_build_job ~analyse_job ~cygwin_job MacOS start_latests_ocaml
@@ fun build_macOS_job -> main_test_job ~analyse_job ~build_linux_job ~build_windows_job ~build_macOS_job ~section:"Opam tests" Linux
@@ fun _ -> main_test_job ~analyse_job ~build_linux_job ~build_windows_job ~build_macOS_job MacOS
@@ fun _ -> cold_job ~analyse_job ~build_linux_job ~build_windows_job ~build_macOS_job ~section:"Opam cold" Linux
Expand Down
42 changes: 29 additions & 13 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ jobs:
run: |
echo archives=archives-1-${{ hashFiles('src_ext/Makefile.dune', 'src_ext/Makefile.sources', 'src_ext/Makefile', '.github/scripts/common/preamble.sh', '.github/scripts/main/preamble.sh', '.github/scripts/main/archives-cache.sh') }}-${{ env.OPAM_REPO_SHA }}
echo archives=archives-1-${{ hashFiles('src_ext/Makefile.dune', 'src_ext/Makefile.sources', 'src_ext/Makefile', '.github/scripts/common/preamble.sh', '.github/scripts/main/preamble.sh', '.github/scripts/main/archives-cache.sh') }}-${{ env.OPAM_REPO_SHA }} >> $GITHUB_OUTPUT
echo ocaml-cache=${{ hashFiles('src_ext/Makefile.dune', '.github/scripts/main/ocaml-cache.sh', '.github/scripts/main/preamble.sh', '.github/scripts/main/create-ocaml-cache.sh') }}
echo ocaml-cache=${{ hashFiles('src_ext/Makefile.dune', '.github/scripts/main/ocaml-cache.sh', '.github/scripts/main/preamble.sh', '.github/scripts/main/create-ocaml-cache.sh') }} >> $GITHUB_OUTPUT
echo ocaml-cache=${{ hashFiles('src_ext/Makefile.dune', '.github/scripts/main/ocaml-cache.sh', '.github/scripts/main/preamble.sh') }}
echo ocaml-cache=${{ hashFiles('src_ext/Makefile.dune', '.github/scripts/main/ocaml-cache.sh', '.github/scripts/main/preamble.sh') }} >> $GITHUB_OUTPUT
echo cygwin=${{ hashFiles('.github/scripts/cygwin.cmd') }}-${{ env.CYGWIN_EPOCH }}
echo cygwin=${{ hashFiles('.github/scripts/cygwin.cmd') }}-${{ env.CYGWIN_EPOCH }} >> $GITHUB_OUTPUT
echo opam-bs-cache=${{ hashFiles('.github/scripts/main/opam-bs-cache.sh', '*.opam', '.github/scripts/main/preamble.sh') }}
Expand Down Expand Up @@ -106,7 +106,7 @@ jobs:
needs: Analyse
strategy:
matrix:
ocamlv: [ 4.08.1, 4.09.1, 4.10.2, 4.11.2, 4.12.1, 4.13.1, 5.0.0, 5.1.1, 4.14.1 ]
ocamlv: [ 4.08.1, 4.09.1, 4.10.2, 4.11.2, 4.12.1, 4.13.1, 5.0.0, 5.1.1, 4.14.2, 5.2.0 ]
fail-fast: true
steps:
- name: Install bubblewrap
Expand Down Expand Up @@ -141,9 +141,25 @@ jobs:
needs: [ Analyse, Cygwin ]
strategy:
matrix:
host: [ x86_64-pc-cygwin, i686-w64-mingw32, x86_64-w64-mingw32, i686-pc-windows, x86_64-pc-windows ]
build: [ x86_64-pc-cygwin ]
ocamlv: [ 4.14.1 ]
include:
- host: x86_64-pc-cygwin
build: x86_64-pc-cygwin
ocamlv: 4.14.2
- host: i686-w64-mingw32
build: x86_64-pc-cygwin
ocamlv: 4.14.2
- host: x86_64-w64-mingw32
build: x86_64-pc-cygwin
ocamlv: 4.14.2
- host: i686-pc-windows
build: x86_64-pc-cygwin
ocamlv: 4.14.2
- host: x86_64-pc-windows
build: x86_64-pc-cygwin
ocamlv: 4.14.2
- host: x86_64-w64-mingw32
build: x86_64-pc-cygwin
ocamlv: 5.2.0
fail-fast: false
defaults:
run:
Expand Down Expand Up @@ -226,7 +242,7 @@ jobs:
needs: Analyse
strategy:
matrix:
ocamlv: [ 4.14.1 ]
ocamlv: [ 4.14.2, 5.2.0 ]
fail-fast: true
steps:
- name: Checkout tree
Expand Down Expand Up @@ -262,7 +278,7 @@ jobs:
needs: [ Analyse, Build-Linux ]
strategy:
matrix:
ocamlv: [ 4.14.1 ]
ocamlv: [ 4.14.2, 5.2.0 ]
fail-fast: false
env:
OPAM_TEST: 1
Expand Down Expand Up @@ -316,7 +332,7 @@ jobs:
needs: Analyse
strategy:
matrix:
ocamlv: [ 4.14.1 ]
ocamlv: [ 4.14.2, 5.2.0 ]
fail-fast: false
env:
OPAM_TEST: 1
Expand Down Expand Up @@ -403,7 +419,7 @@ jobs:
strategy:
matrix:
solver: [ z3, 0install ]
ocamlv: [ 4.14.1 ]
ocamlv: [ 4.14.2, 5.2.0 ]
fail-fast: false
env:
SOLVER: ${{ matrix.solver }}
Expand Down Expand Up @@ -451,7 +467,7 @@ jobs:
strategy:
matrix:
solver: [ z3, 0install ]
ocamlv: [ 4.14.1 ]
ocamlv: [ 4.14.2, 5.2.0 ]
fail-fast: false
env:
SOLVER: ${{ matrix.solver }}
Expand Down Expand Up @@ -499,7 +515,7 @@ jobs:
needs: [ Analyse, Build-Linux ]
strategy:
matrix:
ocamlv: [ 4.14.1 ]
ocamlv: [ 4.14.2, 5.2.0 ]
fail-fast: false
steps:
- name: Install bubblewrap
Expand Down Expand Up @@ -532,7 +548,7 @@ jobs:
needs: [ Analyse, Build-macOS ]
strategy:
matrix:
ocamlv: [ 4.14.1 ]
ocamlv: [ 4.14.2, 5.2.0 ]
fail-fast: false
steps:
- name: Checkout tree
Expand Down
4 changes: 4 additions & 0 deletions master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ users)
* Bump the requirement for dune to 2.8 [#6204 @kit-ty-kate]
* Bump the vendored version of dune to 3.16.0, cppo to 1.7.0 and extlib to 1.8.0 [#6223 @kit-ty-kate]
* Fix compilation with OCaml 5.3 when using the vendored extlib by updating to the 5.3 compatible version (e.g. `make cold` or `./configure --with-vendored-deps`) [#6223 @kit-ty-kate]
* Fix the compilation of opam on Windows with OCaml >= 5.0 again [#6216 @kit-ty-kate]

## Infrastructure

Expand Down Expand Up @@ -117,6 +118,9 @@ users)
### Engine

## Github Actions
* Add OCaml 5.2.0 to the build matrix [#6216 @kit-ty-kate]
* Allow to have more than one OCaml default version to run all jobs and add 5.2 to the list of default versions together with 4.14 [#6216 @kit-ty-kate]
* Bump 4.14 to the latest patch version (4.14.2) [#6216 @kit-ty-kate]

## Doc
* Update the command to install opam to point to the new simplified url on opam.ocaml.org [#6226 @kit-ty-kate]
Expand Down
4 changes: 4 additions & 0 deletions src/core/dune
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
(enabled_if (<> %{os_type} "Win32"))
(action (copy# opamStubs.unix.ml opamStubs.ml)))

(rule
(enabled_if (= %{os_type} "Win32"))
(action (copy# opamWin32Stubs.win32.ml opamWin32Stubs.ml)))

(rule
(enabled_if (and (= %{os_type} "Win32") (< %{ocaml_version} "5.0")))
(action (copy# opamStubs.ocaml4.ml opamStubs.ml)))
Expand Down
39 changes: 1 addition & 38 deletions src/core/opamStubs.ocaml4.ml
Original file line number Diff line number Diff line change
Expand Up @@ -8,45 +8,8 @@
(* *)
(**************************************************************************)

include OpamStubsTypes
include OpamWin32Stubs

external getCurrentProcessID : unit -> int32 = "OPAMW_GetCurrentProcessID"
let getpid () = Int32.to_int (getCurrentProcessID ())
(* Polymorphic parameters below are used as placeholders for types in
* OpamStubsTypes - it's not worth the effort of propagating the types here,
* even if it does result in some ugly-looking primitives!
*)
external getStdHandle : 'a -> 'b = "OPAMW_GetStdHandle"
external getConsoleScreenBufferInfo : 'a -> 'b = "OPAMW_GetConsoleScreenBufferInfo"
external setConsoleTextAttribute : 'a -> int -> unit = "OPAMW_SetConsoleTextAttribute"
external fillConsoleOutputCharacter : 'a -> char -> int -> int * int -> bool = "OPAMW_FillConsoleOutputCharacter"
external getConsoleMode : 'a -> int = "OPAMW_GetConsoleMode"
external setConsoleMode : 'a -> int -> bool = "OPAMW_SetConsoleMode"
external getWindowsVersion : unit -> int * int * int * int = "OPAMW_GetWindowsVersion"
external getArchitecture : unit -> 'a = "OPAMW_GetArchitecture"
external waitpids : int list -> int -> int * Unix.process_status = "OPAMW_waitpids"
external readRegistry : 'a -> string -> string -> 'b -> 'c option = "OPAMW_ReadRegistry"
external enumRegistry : 'a -> string -> 'b -> (string * 'c) list = "OPAMW_RegEnumValue"
external writeRegistry : 'a -> string -> string -> 'b -> 'c -> unit = "OPAMW_WriteRegistry"
external getConsoleOutputCP : unit -> int = "OPAMW_GetConsoleOutputCP"
external getCurrentConsoleFontEx : 'a -> bool -> 'b = "OPAMW_GetCurrentConsoleFontEx"
external create_glyph_checker : string -> 'a * 'a = "OPAMW_CreateGlyphChecker"
external delete_glyph_checker : 'a * 'a -> unit = "OPAMW_DeleteGlyphChecker"
external has_glyph : 'a * 'a -> Uchar.t -> bool = "OPAMW_HasGlyph"
external getProcessArchitecture : int32 option -> 'a = "OPAMW_GetProcessArchitecture"
external process_putenv : int32 -> string -> string -> bool = "OPAMW_process_putenv"
external getPathToHome : unit -> string = "OPAMW_GetPathToHome"
external getPathToSystem : unit -> string = "OPAMW_GetPathToSystem"
external getPathToLocalAppData : unit -> string = "OPAMW_GetPathToLocalAppData"
external sendMessageTimeout : nativeint -> int -> int -> 'a -> 'b -> 'c -> int * 'd = "OPAMW_SendMessageTimeout_byte" "OPAMW_SendMessageTimeout"
external getProcessAncestry : unit -> (int32 * string) list = "OPAMW_GetProcessAncestry"
external getConsoleAlias : string -> string -> string = "OPAMW_GetConsoleAlias"
external getConsoleWindowClass : unit -> string option = "OPAMW_GetConsoleWindowClass"
external setErrorMode : int -> int = "OPAMW_SetErrorMode"
external getErrorMode : unit -> int = "OPAMW_GetErrorMode"
external setConsoleToUTF8 : unit -> unit = "OPAMW_SetConsoleToUTF8"
external getVersionInfo : string -> 'a option = "OPAMW_GetVersionInfo"
external get_initial_environment : unit -> string list = "OPAMW_CreateEnvironmentBlock"
external win_create_process : string -> string -> string option ->
Unix.file_descr -> Unix.file_descr -> Unix.file_descr -> int
= "win_create_process" "win_create_process_native"
2 changes: 0 additions & 2 deletions src/core/opamStubs.ocaml5.ml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
(* *)
(**************************************************************************)

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
Expand Down
Loading
Loading