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

Cygwin images and updates for OCaml 5.1 #186

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
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
5 changes: 3 additions & 2 deletions src-opam/distro.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
28 changes: 23 additions & 5 deletions src-opam/opam.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down Expand Up @@ -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
Expand All @@ -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 =
Expand Down
29 changes: 21 additions & 8 deletions src-opam/windows.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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|}
Expand All @@ -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";
Expand All @@ -277,14 +278,26 @@ module Cygwin = struct
"patch";
"m4";
"cygport";
"flexdll=" ^ flexdll_version;
(match flexdll_version with
| Some v -> "flexdll=" ^ v
| None -> "flexdll");
]

let mingw_packages =
[ "make"; "diffutils"; "patch"; "mingw64-x86_64-gcc-core"; "git" ]

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 =
[
Expand Down
15 changes: 11 additions & 4 deletions src-opam/windows.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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. *)
Expand All @@ -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
Expand Down