user149408
user149408

Reputation: 5881

opam switch install in foreign chroot picks version for host architecture, not guest architecture

I am trying to set up OCaml on a bunch of systems, each with a different processor architecture. OS is Debian buster.

Edit: Architectures other than amd64 are foreign chroot environments on an amd64 host.

Edit 2: The goal is to build for any architecture on demand, just by supplying the target architecture as an argument. Therefore, toolchains should be as uniform as possible – regardless of whether they are 32 or 64-bit, or whether host and guest srchitecture are related.

From the install script:

opam init -y --disable-sandboxing
eval $(opam config env)
# switches are named after the OCaml version
opam switch create $OCAML_VERSION $OCAML_VERSION -y

I have tried this with OCaml version 4.14.1. This works on armhf as well as on amd64, but on i386 I get the following error:

#=== ERROR while compiling ocaml-base-compiler.4.14.1 =========================#
# context              2.0.3 | linux/x86_64 |  | https://opam.ocaml.org#6830df55
# path                 ~/.opam/4.14.1/.opam-switch/build/ocaml-base-compiler.4.14.1
# command              /usr/bin/make -j1
# exit-code            2
# env-file             ~/.opam/log/ocaml-base-compiler-13962-b76d46.env
# output-file          ~/.opam/log/ocaml-base-compiler-13962-b76d46.out
### output ###
# signals_osdep.h:33:57: error: ‘REG_R15’ undeclared (first use in this function); did you mean ‘REG_SS’?
# [...]
#                                                          ^~~~~~~
# signals_nat.c:228:39: note: in expansion of macro ‘CONTEXT_YOUNG_PTR’
#      Caml_state->young_ptr = (value *) CONTEXT_YOUNG_PTR;
#                                        ^~~~~~~~~~~~~~~~~

I get the same error on 4.14.0 and 4.08.1; 4.13.1 and 4.12.1 throw an error for a different identifier (REG_RIP) in the same file. At least one of these versions works, however, on arm64, armhf, ppc64el and s390x (all in foreign chroots).

According to https://github.com/ocaml/ocaml/pull/11904, 32-bit support for OCaml is being pulled, but that goes for both arm and x86 (while armhf still seems to work), and I’m not sure what the first 64-bit-ony version is (5.x is mentioned) – all the way back from 4.14.x to 4.08.x seems a bit long.

Edit: As pointed out in comments, I see that opam is mis-identifying the system as x86_64. Around line 21 of the output file I see:

echo '#define HOST "x86_64-pc-linux-gnu"' >> build_config.h

but no indication how this was obtained. The value is identical to $MACHTYPE on the host system, but $MACHTYPE on the chroot reports i686-pc-linux-gnu. Foreign chroots for other platforms do not seem to have this issue.

Why does opam think it is running on a 64-bit platform, and how can I force it to install the 32-bit version?

Upvotes: 0

Views: 110

Answers (1)

octachron
octachron

Reputation: 18902

Since the issue is that the host architecture is being leaked, the easiest workaround might be to explicit request a 32bit compiler with ocaml-option-32bit option:

opam switch create 4.14.1+32bit ocaml-variants.4.14.1+options ocaml-option-32bit

EDIT: With older version of opam (<2.1?) the CLI invocation is

opam switch create 4.14.1+32bit --packages=ocaml-variants.4.14.1+options,ocaml-option-32bit

Upvotes: 1

Related Questions