Skip to content

Commit

Permalink
Install system packages required by OCaml 5.1+ in the ocaml stage
Browse files Browse the repository at this point in the history
OCaml 5.1+ can optionally use libzstd for compressing marshalled data.
Install this package in the ocaml image. It's not needed in the opam
stage.

Future work might remove uneeded packages from the opam image, like
libx11 that the graphics library depends on, for OCaml 4.09+.
  • Loading branch information
MisterDA committed Mar 23, 2023
1 parent b86e5e6 commit 6a6d0fa
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
25 changes: 25 additions & 0 deletions src-opam/linux.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
20 changes: 20 additions & 0 deletions src-opam/linux.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
18 changes: 18 additions & 0 deletions src-opam/opam.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src-opam/opam.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6a6d0fa

Please sign in to comment.