Skip to content

Get the system variable to be consistent #10613

@kit-ty-kate

Description

@kit-ty-kate

Currently, in OCaml code in the wild, people use the output of ocamlc -config to detect the architecture and OS of the system they are on.

However while debugging janestreet/core#145 I discovered that the variable system, in particular, is not consistent and does not always return "linux" on linux systems for example.

This pattern of using the system variable to detect the OS is especially prevalent in dune where there is no other builtin way to get this information (see ocaml/dune#4895).

In addition of fixing dune and other build systems with similar issues (I believe oasis, back in the days, also used the system variable: https://github.com/ocaml/oasis/blob/master/setup.ml#L4133), I think it would be nice to make the variable more consistent. e.g.

  • regroup all the linux variants as linux
  • regroup bsd_elf and bsd as bsd
  • regroup all the openbsd variants as openbsd (currently it's split between bsd and openbsd depending on the architecture)
  • regroup win32 and win64 into one (not sure which name it should have, but having the system variable carry the same information as the architecture variable doesn't seem right to me)
  • same for mingw and mingw64 (cc @dra27 who probably has ideas about windows)

See

ocaml/configure.ac

Lines 1044 to 1132 in 1252351

AS_CASE([$host],
[[i[3456]86-*-linux*]],
[arch=i386; system=linux_elf],
[[i[3456]86-*-*bsd*]],
[arch=i386; system=bsd_elf],
[[i[3456]86-*-haiku*]],
[arch=i386; system=beos],
[[i[3456]86-*-cygwin]],
[arch=i386; system=cygwin],
[[i[3456]86-*-gnu*]],
[arch=i386; system=gnu],
[[i[3456]86-*-mingw32]],
[arch=i386; system=mingw],
[i686-pc-windows],
[arch=i386; system=win32],
[x86_64-pc-windows],
[arch=amd64; system=win64],
[[powerpc64le*-*-linux*]],
[arch=power; model=ppc64le; system=elf],
[[powerpc*-*-linux*]],
[arch=power; AS_IF([$arch64],[model=ppc64],[model=ppc]); system=elf],
[[s390x*-*-linux*]],
[arch=s390x; model=z10; system=elf],
# expected to match "gnueabihf" as well as "musleabihf"
[armv6*-*-linux-*eabihf],
[arch=arm; model=armv6; system=linux_eabihf],
[armv7*-*-linux-*eabihf],
[arch=arm; model=armv7; system=linux_eabihf],
[armv8*-*-linux-*eabihf],
[arch=arm; model=armv8; system=linux_eabihf],
[armv8*-*-linux-*eabi],
[arch=arm; model=armv8; system=linux_eabi],
[armv7*-*-linux-*eabi],
[arch=arm; model=armv7; system=linux_eabi],
[armv6t2*-*-linux-*eabi],
[arch=arm; model=armv6t2; system=linux_eabi],
[armv6*-*-linux-*eabi],
[arch=arm; model=armv6; system=linux_eabi],
[armv6*-*-freebsd*],
[arch=arm; model=armv6; system=freebsd],
[earmv6*-*-netbsd*],
[arch=arm; model=armv6; system=netbsd],
[earmv7*-*-netbsd*],
[arch=arm; model=armv7; system=netbsd],
[armv5te*-*-linux-*eabi],
[arch=arm; model=armv5te; system=linux_eabi],
[armv5*-*-linux-*eabi],
[arch=arm; model=armv5; system=linux_eabi],
[arm*-*-linux-*eabihf],
[arch=arm; system=linux_eabihf],
[arm*-*-linux-*eabi],
[arch=arm; system=linux_eabi],
[arm*-*-openbsd*],
[arch=arm; system=bsd],
[zaurus*-*-openbsd*],
[arch=arm; system=bsd],
[x86_64-*-linux*],
[arch=amd64; system=linux],
[x86_64-*-gnu*],
[arch=amd64; system=gnu],
[x86_64-*-dragonfly*],
[arch=amd64; system=dragonfly],
[x86_64-*-solaris*],
[arch=amd64; system=solaris],
[x86_64-*-freebsd*],
[arch=amd64; system=freebsd],
[x86_64-*-netbsd*],
[arch=amd64; system=netbsd],
[x86_64-*-openbsd*],
[arch=amd64; system=openbsd],
[x86_64-*-haiku*],
[arch=amd64; system=beos],
[arm64-*-darwin*],
[arch=arm64; system=macosx],
[aarch64-*-darwin*],
[arch=arm64; system=macosx],
[x86_64-*-darwin*],
[arch=amd64; system=macosx],
[x86_64-*-mingw32],
[arch=amd64; system=mingw64],
[aarch64-*-linux*],
[arch=arm64; system=linux],
[aarch64-*-freebsd*],
[arch=arm64; system=freebsd],
[x86_64-*-cygwin*],
[arch=amd64; system=cygwin],
[riscv64-*-linux*],
[arch=riscv; model=riscv64; system=linux]
)
for the list of current possible values of system

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions