diff --git a/src-opam/distro.ml b/src-opam/distro.ml index d0c44fc..d21b5c9 100644 --- a/src-opam/distro.ml +++ b/src-opam/distro.ml @@ -756,6 +756,7 @@ let distro_arches ov (d : t) = | `Windows (`Msvc, _), ov when OV.major ov >= 5 -> [] (* 2021-04-19: should be 4.03 but there's a linking failure until 4.06. *) | `Windows (`Msvc, _), ov when OV.(compare Releases.v4_06_0 ov) = 1 -> [] + | `Cygwin _, ov when OV.(compare Releases.v5_1_0 ov) = 1 -> [] | _ -> [ `X86_64 ] let distro_supported_on a ov (d : t) = List.mem a (distro_arches ov d) @@ -868,7 +869,7 @@ let builtin_ocaml_of_distro (d : t) : string option = | `OracleLinux `V7 -> Some "4.01.0" | `OracleLinux `V8 -> Some "4.07.0" | `OracleLinux `V9 -> Some "4.11.1" - | `Cygwin _ -> None + | `Cygwin _ -> Some "4.14.0" | `Windows _ -> None | `Debian (`Testing | `Unstable) -> assert false @@ -1257,7 +1258,7 @@ type package_manager = [ `Apt | `Yum | `Apk | `Zypper | `Pacman | `Cygwin | `Windows ] [@@deriving sexp] -let package_manager (t : t) = +let package_manager (t : t) : package_manager = match t with | `Ubuntu _ -> `Apt | `Debian _ -> `Apt diff --git a/src-opam/opam.ml b/src-opam/opam.ml index 2ee3f71..fb952ea 100644 --- a/src-opam/opam.ml +++ b/src-opam/opam.ml @@ -427,6 +427,22 @@ let pacman_opam2 ?(labels = []) ?arch ~opam_hashes distro () = @@ Linux.Pacman.add_user ~uid:1000 ~sudo:true "opam" @@ install_bubblewrap_wrappers @@ Linux.Git.init () +(* Cygwin based Dockerfile *) +let cygwin_opam2 ?win10_revision ?(labels = []) ?arch ~opam_hashes distro () = + let opam_master_hash, opam_branches = create_opam_branches opam_hashes in + parser_directive (`Escape '`') + @@ comment "Autogenerated by OCaml-Dockerfile scripts" + @@ header ?win10_revision ?arch distro + @@ label (("distro_style", "cygwin") :: labels) + @@ user "ContainerAdministrator" + @@ Windows.sanitize_reg_path () + @@ Windows.Cygwin.(install_cygwin ~extra:(cygwin_packages ()) ()) + @@ Windows.Cygwin.Git.init () + @@ install_opams opam_master_hash opam_branches + @@ from ?arch distro + @@ copy_opams ~src:"/usr/local/bin" ~dst:"/usr/bin" opam_branches + @@ Linux.Git.init () + let install_winget ?win10_revision ?winget version = match winget with | None when Windows.Winget.is_supported version -> @@ -550,9 +566,7 @@ let gen_opam2_distro ?win10_revision ?winget ?(clone_opam_repo = true) ?arch | `Windows (`Msvc, _) -> windows_msvc_opam2 ?win10_revision ?winget ?labels ~opam_hashes d () | _ -> assert false) - | `Cygwin -> - failwith - "OCaml/opam Docker images with the Cygwin port are not supported." + | `Cygwin -> cygwin_opam2 ?win10_revision ?labels ?arch ~opam_hashes d () in let clone = if clone_opam_repo then @@ -579,8 +593,12 @@ let ocaml_depexts distro v = | `Yum -> as_root (RPM.install "%s") (RPM.ocaml_depexts v) | `Zypper -> as_root (Zypper.install "%s") (Zypper.ocaml_depexts v) | `Pacman -> as_root (Pacman.install "%s") (Pacman.ocaml_depexts v) - | `Windows -> empty - | `Cygwin -> empty + | `Windows -> ( + match distro with + | `Windows (`Mingw, _) -> Windows.Cygwin.(install (mingw_depexts v)) + | `Windows (`Msvc, _) -> empty + | _ -> assert false) + | `Cygwin -> Windows.Cygwin.(install (cygwin_depexts v)) let create_switch ~arch distro t = let create_switch switch pkg = diff --git a/src-opam/windows.ml b/src-opam/windows.ml index 97eca39..38f4ed3 100644 --- a/src-opam/windows.ml +++ b/src-opam/windows.ml @@ -234,10 +234,12 @@ module Cygwin = struct (if upgrade then " --upgrade-also" else "")) fmt - let install ?(cyg = default) pkgs = - cygsetup ~cyg "--packages %s" - (pkgs |> List.sort_uniq String.compare |> String.concat ",") - |> cleanup + let install ?(cyg = default) = function + | [] -> empty + | pkgs -> + cygsetup ~cyg "--packages %s" + (pkgs |> List.sort_uniq String.compare |> String.concat ",") + |> cleanup let update ?(cyg = default) () = cygsetup ~cyg ~upgrade:true "" |> cleanup @@ -252,7 +254,7 @@ module Cygwin = struct ~dst:(cyg.root ^ {|\setup-x86_64.exe|}) () @@ install_cygsympathy_from_source cyg - @@ (if extra <> [] then install ~cyg extra else empty) + @@ install ~cyg extra @@ (if msvs_tools then install_msvs_tools_from_source cyg else empty) @@ run {|awk -i inplace "/(^#)|(^$)/{print;next}{$4=""noacl,""$4; print}" %s\etc\fstab|} @@ -266,8 +268,7 @@ module Cygwin = struct from @@ workdir {|%s\home\opam|} cyg.root - let cygwin_packages ?(flexdll_version = "0.39-1") () = - (* 2021-03-19: flexdll 0.39 is required, but is in Cygwin testing *) + let cygwin_packages ?flexdll_version () = [ "make"; "diffutils"; @@ -277,7 +278,9 @@ module Cygwin = struct "patch"; "m4"; "cygport"; - "flexdll=" ^ flexdll_version; + (match flexdll_version with + | Some v -> "flexdll=" ^ v + | None -> "flexdll"); ] let mingw_packages = @@ -285,6 +288,16 @@ module Cygwin = struct let msvc_packages = [ "make"; "diffutils"; "patch"; "git" ] + let cygwin_depexts v = + if Ocaml_version.compare v Ocaml_version.Releases.v5_1_0 >= 0 then + [ "libzstd-devel" ] + else [] + + let mingw_depexts v = + if Ocaml_version.compare v Ocaml_version.Releases.v5_1_0 >= 0 then + [ "mingw64-x86_64-zstd" ] + else [] + let install_ocaml_for_windows ?cyg ?(version = "0.0.0.2") () = let packages = [ diff --git a/src-opam/windows.mli b/src-opam/windows.mli index fa86a33..7aa24e3 100644 --- a/src-opam/windows.mli +++ b/src-opam/windows.mli @@ -108,8 +108,7 @@ module Cygwin : sig (** Setup Cygwin workdir, optionally copied from the [from] Docker image. *) val install : ?cyg:cyg -> string list -> Dockerfile.t - (** Install the supplied Cygwin package list. The packages should be - comma-separated. *) + (** Install the supplied Cygwin package list. *) val update : ?cyg:cyg -> unit -> t (** Update Cygwin packages. *) @@ -120,11 +119,19 @@ module Cygwin : sig val mingw_packages : string list (** [mingw_packages] is the list of base development tools for the - Caml mingw port. *) + OCaml mingw port. *) val msvc_packages : string list (** [msvc_packages] is the list of base development tools for the - Caml MSVC port. *) + OCaml MSVC port. *) + + val cygwin_depexts : Ocaml_version.t -> string list + (** [cygwin_depexts v] returns packages that are required by the + OCaml Cygwin distribution at version [v]. *) + + val mingw_depexts : Ocaml_version.t -> string list + (** [mingw_depexts v] returns packages that are required by the + OCaml mingw distribution at version [v]. *) val install_ocaml_for_windows : ?cyg:cyg -> ?version:string -> unit -> string list * t