diff --git a/CHANGES.md b/CHANGES.md index 7bec0223..b5ca79ec 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,9 @@ unreleased ---------- +- Install system packages required by OCaml in the ocaml stage, + starting with OCaml 5.1 and libzstd. + (@MisterDA #149, review by @kit-ty-kate) - Add OracleLinux 9. (@MisterDA #155) - Optimize and fix Linux package install. (@MisterDA #147, #151, #153, #154, review by @kit-ty-kate) diff --git a/src-opam/linux.ml b/src-opam/linux.ml index d8985bfb..2e6b86f2 100644 --- a/src-opam/linux.ml +++ b/src-opam/linux.ml @@ -45,6 +45,11 @@ module RPM = struct libX11-devel which m4 diffutils findutils%s" (match extra with None -> "" | Some x -> " " ^ x) + let ocaml_depexts v = + if Ocaml_version.compare v Ocaml_version.Releases.v5_1_0 >= 0 then + Some "zstd" + else None + let add_user ?uid ?gid ?(sudo = false) username = let uid = match uid with Some u -> sprintf "-u %d " u | None -> "" in let gid = match gid with Some g -> sprintf "-g %d " g | None -> "" in @@ -90,6 +95,11 @@ module Apt = struct libx11-dev%s" (match extra with None -> "" | Some x -> " " ^ x) + let ocaml_depexts v = + if Ocaml_version.compare v Ocaml_version.Releases.v5_1_0 >= 0 then + Some "libzstd-dev" + else None + let add_user ?uid ?gid ?(sudo = false) username = let uid = match uid with Some u -> sprintf "--uid %d " u | None -> "" in let gid = match gid with Some g -> sprintf "--gid %d " g | None -> "" in @@ -125,6 +135,11 @@ module Apk = struct libx11-dev nano coreutils xz ncurses-dev%s" (match extra with None -> "" | Some x -> " " ^ x) + let ocaml_depexts v = + if Ocaml_version.compare v Ocaml_version.Releases.v5_1_0 >= 0 then + Some "zstd" + else None + let add_user ?uid ?gid ?(sudo = false) username = let home = "/home/" ^ username in (match gid with @@ -180,6 +195,11 @@ module Zypper = struct rsync gzip%s" (match extra with None -> "" | Some x -> " " ^ x) + let ocaml_depexts v = + if Ocaml_version.compare v Ocaml_version.Releases.v5_1_0 >= 0 then + Some "zstd" + else None + let add_user ?uid ?gid ?(sudo = false) username = let home = "/home/" ^ username in run "useradd %s%s -d %s -m --user-group %s" @@ -216,6 +236,11 @@ module Pacman = struct coreutils xz ncurses diffutils unzip%s" (match extra with None -> "" | Some x -> " " ^ x) + let ocaml_depexts v = + if Ocaml_version.compare v Ocaml_version.Releases.v5_1_0 >= 0 then + Some "zstd" + else None + let add_user ?uid ?gid ?(sudo = false) username = let home = "/home/" ^ username in run "useradd %s%s -d %s -m --user-group %s" diff --git a/src-opam/linux.mli b/src-opam/linux.mli index 0f96437d..ed9b87db 100644 --- a/src-opam/linux.mli +++ b/src-opam/linux.mli @@ -48,6 +48,10 @@ module RPM : sig (** [dev_packages ?extra ()] will install the base development tools and [sudo], [passwd] and [git]. Extra packages may also be optionally supplied via [extra]. *) + val ocaml_depexts : Ocaml_version.t -> string option + (** [ocaml_depexts v] returns packages that are required by the + OCaml distribution at version [v]. *) + val install_system_ocaml : t (** Install the system OCaml packages via Yum *) end @@ -69,6 +73,10 @@ module Apt : sig (** [dev_packages ?extra ()] will install the base development tools and [sudo], [passwd] and [git] and X11. Extra packages may also be optionally supplied via [extra]. *) + val ocaml_depexts : Ocaml_version.t -> string option + (** [ocaml_depexts v] returns packages that are required by the + OCaml distribution at version [v]. *) + val install_system_ocaml : t (** Install the system OCaml packages via [apt-get] *) end @@ -85,6 +93,10 @@ module Apk : sig (** [dev_packages ?extra ()] will install the base development tools and [sudo], [passwd] and [git]. Extra packages may also be optionally supplied via [extra]. *) + val ocaml_depexts : Ocaml_version.t -> string option + (** [ocaml_depexts v] returns packages that are required by the + OCaml distribution at version [v]. *) + val add_user : ?uid:int -> ?gid:int -> ?sudo:bool -> string -> t (** [add_user username] will install a new user with name [username] and a locked password. If [sudo] is true then root access with no password will also be @@ -117,6 +129,10 @@ module Zypper : sig (** [dev_packages ?extra ()] will install the base development tools and [sudo], [passwd] and [git]. Extra packages may also be optionally supplied via [extra]. *) + val ocaml_depexts : Ocaml_version.t -> string option + (** [ocaml_depexts v] returns packages that are required by the + OCaml distribution at version [v]. *) + val install_system_ocaml : t (** Install the system OCaml packages via [zypper] *) end @@ -138,6 +154,10 @@ module Pacman : sig (** [dev_packages ?extra ()] will install the base development tools and [sudo], [passwd] and [git]. Extra packages may also be optionally supplied via [extra]. *) + val ocaml_depexts : Ocaml_version.t -> string option + (** [ocaml_depexts v] returns packages that are required by the + OCaml distribution at version [v]. *) + val install_system_ocaml : t (** Install the system OCaml packages via [pacman] *) end diff --git a/src-opam/opam.ml b/src-opam/opam.ml index 04c52ada..912b8b7b 100644 --- a/src-opam/opam.ml +++ b/src-opam/opam.ml @@ -507,6 +507,24 @@ let gen_opam2_distro ?win10_revision ?winget ?(clone_opam_repo = true) ?arch in (D.tag_of_distro d, fn @@ clone @@ pers) +let ocaml_depexts distro v = + let open Linux in + match D.package_manager distro with + | `Apk -> + Option.fold ~none:empty ~some:(Apk.install "%s") (Apk.ocaml_depexts v) + | `Apt -> + Option.fold ~none:empty ~some:(Apt.install "%s") (Apt.ocaml_depexts v) + | `Yum -> + Option.fold ~none:empty ~some:(RPM.install "%s") (RPM.ocaml_depexts v) + | `Zypper -> + Option.fold ~none:empty ~some:(Zypper.install "%s") + (Zypper.ocaml_depexts v) + | `Pacman -> + Option.fold ~none:empty ~some:(Pacman.install "%s") + (Pacman.ocaml_depexts v) + | `Windows -> empty + | `Cygwin -> empty + let create_switch ~arch distro t = let create_switch switch pkg = run "opam switch create %s %s" (OV.to_string switch) pkg diff --git a/src-opam/opam.mli b/src-opam/opam.mli index 6b80cc8f..4188b78d 100644 --- a/src-opam/opam.mli +++ b/src-opam/opam.mli @@ -68,6 +68,11 @@ val gen_opam2_distro : will be build in an prepended build stage. If specified, then winget will be pulled from the [winget] external image. *) +val ocaml_depexts : Distro.t -> Ocaml_version.t -> Dockerfile.t +(** [ocaml_depexts distro version] returns packages that are + required under [distro] by the OCaml distribution at version + [version]. *) + val all_ocaml_compilers : string -> Ocaml_version.arch -> Distro.t -> string * Dockerfile.t (** [all_ocaml_compilers hub_id arch distro] will generate an opam2