My long standing problem of OCaml on Alpine…
I have the following Dockerfile:
FROM alpine:edge AS builder
# Install the build dependencies
RUN apk add --no-cache make m4 which patch sudo wget git pkgconfig \
gcc g++ musl-dev linux-headers libffi libffi-dev pcre perl python3 \
gmp-dev pcre-dev xz-dev gmp xz coreutils \
ocaml ocaml-compiler-libs ocaml-ocamldoc opam ocaml-findlib
RUN chmod +s `which bwrap`
RUN addgroup -g 1000 -S user && adduser -u 1000 -D -S user -G user
USER user
WORKDIR /home/user
RUN opam init --auto-setup --disable-sandboxing --yes && \
eval `opam env` && opam install --yes ocamlfind
RUN eval `opam env` && CC=musl-gcc \
opam switch create 4.10.0+musl+static+flambda && \
opam switch 4.10.0+musl+static+flambda
But while compiling it gives an error:
STEP 10: RUN eval `opam env` && CC=musl-gcc opam switch create 4.10.0+musl+static+flambda && opam switch 4.10.0+musl+static+flambda
<><> Gathering sources ><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
[ocaml-variants.4.10.0+musl+static+flambda] downloaded from cache at https://opam.ocaml.org/cache
<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
-> installed base-bigarray.base
-> installed base-threads.base
-> installed base-unix.base
[ERROR] The compilation of ocaml-variants failed at "/home/user/.opam/4.10.0+musl+static+flambda/.opam-switch/build/ocaml-variants.4.10.0+musl+static+flambda/./configure --prefix=/home/user/.opam/4.10.0+musl+static+flambda CC=musl-gcc
CFLAGS=-Os ASPP=musl-gcc -c --enable-flambda LIBS=-static".
#=== ERROR while compiling ocaml-variants.4.10.0+musl+static+flambda ==========#
# context 2.0.5 | linux/x86_64 | | https://opam.ocaml.org#91fe1ae0
# path ~/.opam/4.10.0+musl+static+flambda/.opam-switch/build/ocaml-variants.4.10.0+musl+static+flambda
# command ~/.opam/4.10.0+musl+static+flambda/.opam-switch/build/ocaml-variants.4.10.0+musl+static+flambda/./configure --prefix=/home/user/.opam/4.10.0+musl+static+flambda CC=musl-gcc CFLAGS=-Os ASPP=musl-gcc -c --enable-flambda LIBS=-static
# exit-code 77
# env-file ~/.opam/log/ocaml-variants-3-d0f245.env
# output-file ~/.opam/log/ocaml-variants-3-d0f245.out
### output ###
# configure: Configuring OCaml version 4.10.0
# checking build system type... x86_64-pc-linux-musl
# checking host system type... x86_64-pc-linux-musl
# checking target system type... x86_64-pc-linux-musl
# checking for ld... ld
# checking how to print strings... printf
# checking for gcc... musl-gcc
# checking whether the C compiler works... no
# configure: error: in `/home/user/.opam/4.10.0+musl+static+flambda/.opam-switch/build/ocaml-variants.4.10.0+musl+static+flambda':
# configure: error: C compiler cannot create executables
# See `config.log' for more details
<><> Error report <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
+- The following actions failed
| - build ocaml-variants 4.10.0+musl+static+flambda
+-
+- The following changes have been performed (the rest was aborted)
| - install base-bigarray base
| - install base-threads base
| - install base-unix base
+-
Here is the exact reason - it says "musl-gcc
not found" (there is indeed no such binary in Alpine, even with musl-dev
package installed):
Same result with and without CC=musl-gcc
.
Not sure if a bug or I did something wrong.