Skip to content

Commit

Permalink
Install system packages required by OCaml in the ocaml stage
Browse files Browse the repository at this point in the history
Different releases of OCaml require different system libraries: libX11
isn't needed since 4.09, when the Graphics library was moved from the
core distribution to a separate package. On the opposite side, OCaml
5.1 can optionally use libzstd for compressing marshalled
data. Install these packages accordingly in the ocaml image.
  • Loading branch information
MisterDA committed Mar 10, 2023
1 parent 64b9d46 commit 825fff1
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
unreleased
----------

- Install system packages required by OCaml in the ocaml stage. (@MisterDA #149)
- Optimize and fix Linux package install (@MisterDA #153)
- Various LCU Updates (@mtelvers #144 #136 #135)
- Support mounts, networks, and security parameters in RUN
Expand Down
50 changes: 41 additions & 9 deletions src-opam/linux.ml
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,18 @@ module RPM = struct

let dev_packages ?extra () =
install
"sudo passwd bzip2 patch rsync nano gcc-c++ git tar curl xz libX11-devel \
"sudo passwd bzip2 patch rsync nano gcc-c++ git tar curl xz \
which m4 diffutils findutils%s"
(match extra with None -> "" | Some x -> " " ^ x)
@@ groupinstall "\"Development Tools\""

let ocaml_dev_packages v =
if Ocaml_version.compare v Ocaml_version.Releases.v4_08 <= 0 then
Some "libX11-devel"
else 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 @@ -86,11 +93,16 @@ module Apt = struct
copy_heredoc
~src:[ heredoc ~strip:true "\tAcquire::Retries \"5\";" ]
~dst:"/etc/apt/apt.conf.d/mirror-retry" ()
@@ install
"build-essential curl git rsync sudo unzip nano libcap-dev \
libx11-dev%s"
@@ install "build-essential curl git rsync sudo unzip nano libcap-dev%s"
(match extra with None -> "" | Some x -> " " ^ x)

let ocaml_dev_packages v =
if Ocaml_version.compare v Ocaml_version.Releases.v4_08 <= 0 then
Some "libX11-dev"
else 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 @@ -122,10 +134,17 @@ module Apk = struct

let dev_packages ?extra () =
install
"build-base patch tar ca-certificates git rsync curl sudo bash \
libx11-dev nano coreutils xz ncurses-dev%s"
"build-base patch tar ca-certificates git rsync curl sudo bash nano \
coreutils xz ncurses-dev%s"
(match extra with None -> "" | Some x -> " " ^ x)

let ocaml_dev_packages v =
if Ocaml_version.compare v Ocaml_version.Releases.v4_08 <= 0 then
Some "libX11-dev"
else 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 @@ -177,10 +196,16 @@ module Zypper = struct
let dev_packages ?extra () =
install "-t pattern devel_C_C++"
@@ install
"sudo git unzip curl gcc-c++ libcap-devel xz libX11-devel bzip2 which \
rsync gzip%s"
"sudo git unzip curl gcc-c++ libcap-devel xz bzip2 which rsync gzip%s"
(match extra with None -> "" | Some x -> " " ^ x)

let ocaml_dev_packages v =
if Ocaml_version.compare v Ocaml_version.Releases.v4_08 <= 0 then
Some "libX11-devel"
else 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 @@ -213,10 +238,17 @@ module Pacman = struct

let dev_packages ?extra () =
install
"make gcc patch tar ca-certificates git rsync curl sudo bash libx11 nano \
"make gcc patch tar ca-certificates git rsync curl sudo bash nano \
coreutils xz ncurses diffutils unzip%s"
(match extra with None -> "" | Some x -> " " ^ x)

let ocaml_dev_packages v =
if Ocaml_version.compare v Ocaml_version.Releases.v4_08 <= 0 then
Some "libx11"
else 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_dev_packages : Ocaml_version.t -> string option
(** [ocaml_dev_packages 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_dev_packages : Ocaml_version.t -> string option
(** [ocaml_dev_packages 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_dev_packages : Ocaml_version.t -> string option
(** [ocaml_dev_packages 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_dev_packages : Ocaml_version.t -> string option
(** [ocaml_dev_packages 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_dev_packages : Ocaml_version.t -> string option
(** [ocaml_dev_packages 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
21 changes: 21 additions & 0 deletions src-opam/opam.ml
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,27 @@ let gen_opam2_distro ?win10_revision ?winget ?(clone_opam_repo = true) ?arch
in
(D.tag_of_distro d, fn @@ clone @@ pers)

let ocaml_dev_packages distro v =
let open Linux in
match D.package_manager distro with
| `Apk ->
Option.fold ~none:empty ~some:(Apk.install "%s")
(Apk.ocaml_dev_packages v)
| `Apt ->
Option.fold ~none:empty ~some:(Apt.install "%s")
(Apt.ocaml_dev_packages v)
| `Yum ->
Option.fold ~none:empty ~some:(RPM.install "%s")
(RPM.ocaml_dev_packages v)
| `Zypper ->
Option.fold ~none:empty ~some:(Zypper.install "%s")
(Zypper.ocaml_dev_packages v)
| `Pacman ->
Option.fold ~none:empty ~some:(Pacman.install "%s")
(Pacman.ocaml_dev_packages 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_dev_packages : Distro.t -> Ocaml_version.t -> Dockerfile.t
(** [ocaml_dev_packages 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 825fff1

Please sign in to comment.