Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract arch and os from machine triplet when available, add machine triplet variable. #5587

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

toots
Copy link

@toots toots commented Jun 27, 2023

This PR is the opam counter part of the problems discussed in ocaml/ocaml#12326.

In some situations, the runtime environment used to build the compiler is not the same as the kernel architecture. I have seen two cases of this lately:

  • Raspberry pi version 4 ships by default with a 64 bit kernel and 32 bit runtime. Please don't ask me why.
  • Docker can run images from an architecture that is not the kernel's architecture, for instance 32 bit arm runtime with a 64 bit kernel. This is a much more likely use-case.

In situations like these, the configure script picks up the architecture from the kernel.

The opam binary is also impacted by this issue as it queries the architecture using uname which returns the host processor architecture, not the runtime architecture. Here's an example from inside a docker debian/armhf image:

$ opam var

<><> Global opam variables ><><><><><><><><><><><><><><><><><><><><><><><><><><>
arch              arm64            # Inferred from system
exe                                # Suffix needed for executable filenames (Windows)
jobs              3                # The number of parallel jobs set up in opam configuration
make              make             # The 'make' command to use
opam-version      2.1.5            # The currently running opam version
os                linux            # Inferred from system
os-distribution   debian           # Inferred from system
os-family         debian           # Inferred from system
os-version        12               # Inferred from system
root              /home/opam/.opam # The current opam root directory
switch            4.14.1           # The identifier of the current switch
sys-ocaml-arch    arm              # Target architecture of the OCaml compiler present on your system
sys-ocaml-cc      cc               # Host C Compiler type of the OCaml compiler present on your system
sys-ocaml-libc    libc             # Host C Runtime Library type of the OCaml compiler present on your system
sys-ocaml-version 4.13.1           # OCaml version present on your system independently of opam, if any

With these changes, the returned architecture is as we expect:

$ dune exec ./src/client/opamMain.exe var

<><> Global opam variables ><><><><><><><><><><><><><><><><><><><><><><><><><><>
arch              arm                 # Inferred from system
exe                                   # Suffix needed for executable filenames (Windows)
jobs              3                   # The number of parallel jobs set up in opam configuration
machine-triplet   arm-linux-gnueabihf # Inferred from system
make              make                # The 'make' command to use
opam-version      2.2.0~alpha~dev     # The currently running opam version
os                linux               # Inferred from system
os-distribution   debian              # Inferred from system
os-family         debian              # Inferred from system
os-version        12                  # Inferred from system
root              /home/opam/.opam    # The current opam root directory
switch            4.14.1              # The identifier of the current switch
sys-ocaml-arch    arm                 # Target architecture of the OCaml compiler present on your system
sys-ocaml-cc      cc                  # Host C Compiler type of the OCaml compiler present on your system
sys-ocaml-libc    libc                # Host C Runtime Library type of the OCaml compiler present on your system
sys-ocaml-version 4.13.1              # OCaml version present on your system independently of opam, if any

The opam binary is making all sort of assumptions about the system it runs on, os, distribution, package manager etc. Thus, it make sense that it should also be more accurate about the runtime's architecture.

With these changes, it should be possible to have opam invoke the OCaml's configure script with the --build parameter that matches the machine triplet.

This solution is more desirable than the proposed changes in the OCaml compiler configure script in that the compiler has less assumptions to make about the system and leaves the user in charge of dealing with corner-cases.

@toots toots force-pushed the guess-machine-triplet branch from f2b16d6 to a107b30 Compare June 27, 2023 22:04
src/state/opamSysPoll.ml Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants