diff --git a/src/core/opamStd.ml b/src/core/opamStd.ml index cc30d76f4fc..65f1b03b660 100644 --- a/src/core/opamStd.ml +++ b/src/core/opamStd.ml @@ -991,19 +991,22 @@ module OpamSys = struct let etc () = "/etc" - let uname = + let memo_command = let memo = Hashtbl.create 7 in - fun arg -> - try Hashtbl.find memo arg with Not_found -> + fun cmd arg -> + try Hashtbl.find memo (cmd, arg) with Not_found -> let r = try - with_process_in "uname" arg + with_process_in cmd arg (fun ic -> Some (OpamString.strip (input_line ic))) with Unix.Unix_error _ | Sys_error _ | Not_found -> None in - Hashtbl.add memo arg r; + Hashtbl.add memo (cmd, arg) r; r + let uname = memo_command "uname" + let getconf = memo_command "getconf" + let system = let system = Lazy.from_fun OpamStubs.getPathToSystem in fun () -> Lazy.force system diff --git a/src/core/opamStd.mli b/src/core/opamStd.mli index 71fc4220404..69995fd2e6d 100644 --- a/src/core/opamStd.mli +++ b/src/core/opamStd.mli @@ -507,6 +507,9 @@ module Sys : sig (** The output of the command "uname", with the given argument. Memoised. *) val uname: string -> string option + (** The output of the command "getconf", with the given argument. Memoised. *) + val getconf: string -> string option + (** Append .exe (only if missing) to executable filenames on Windows *) val executable_name : string -> string diff --git a/src/state/opamSysPoll.ml b/src/state/opamSysPoll.ml index 2930d973d77..fdca0434014 100644 --- a/src/state/opamSysPoll.ml +++ b/src/state/opamSysPoll.ml @@ -47,9 +47,23 @@ let poll_arch () = end | _ -> None in - match raw with - | None | Some "" -> None - | Some a -> Some (normalise_arch a) + let normalised = + match raw with + | None | Some "" -> None + | Some a -> Some (normalise_arch a) + in + match Sys.os_type with + | "Unix" | "Cygwin" -> + (match normalised with + | Some ("x86_64" | "arm64" | "ppc64" as arch) -> + (match OpamStd.Sys.getconf "LONG_BIT", arch with + | Some "32", "x86_64" -> Some "x86_32" + | Some "32", "arm64" -> Some "arm32" + | Some "32", "ppc64" -> Some "ppc32" + | _ -> normalised + | exception (Unix.Unix_error _ | Sys_error _ | Not_found) -> normalised) + | _ -> normalised) + | _ -> normalised let arch = Lazy.from_fun poll_arch let normalise_os raw =