Skip to content

Commit

Permalink
env2mfile: Base cpu on DEB_HOST_GNU_CPU unless DEB_HOST_ARCH is special
Browse files Browse the repository at this point in the history
`DEB_HOST_ARCH` encodes both the CPU family and the OS, so using it to
get the CPU type gives the wrong answer for non-Linux ports.

However, `DEB_HOST_GNU_CPU` gives less detailed information about the
CPU: it's `arm` for all 32-bit ARM CPUs, and doesn't distinguish between
the differing baselines of `armel` (ARMv5 softfloat) and `armhf`
(ARMv7 hardfloat).

When cross-compiling for x86_64 Linux, this changes the `cpu()` from
`amd64` to `x86_64`, which is consistent with the answer we get during
native builds on that architecture.

When cross-compiling for `ppc64el`, this changes the `cpu()` from
`ppc64el` to `ppc64`, which is a reasonable change but is still not
consistent with what we see during native builds (which is `ppc64le`):
see #13741 for that.

Resolves: #13742
Signed-off-by: Simon McVittie <[email protected]>
  • Loading branch information
smcv committed Oct 2, 2024
1 parent 2bf3082 commit fc87950
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
13 changes: 10 additions & 3 deletions mesonbuild/scripts/env2mfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,20 @@ def get_args_from_envvars(infos: MachineInfo) -> None:
if objcpp_link_args:
infos.link_args['objcpp'] = objcpp_link_args

# map from DEB_HOST_GNU_CPU to Meson machine.cpu_family()
deb_cpu_family_map = {
'mips64el': 'mips64',
'i686': 'x86',
'powerpc64le': 'ppc64',
}

deb_cpu_map = {
# map from DEB_HOST_ARCH to Meson machine.cpu()
deb_arch_cpu_map = {
'armhf': 'arm7hlf',
}

# map from DEB_HOST_GNU_CPU to Meson machine.cpu()
deb_cpu_map = {
'mips64el': 'mips64',
'powerpc64le': 'ppc64',
}
Expand Down Expand Up @@ -241,8 +247,9 @@ def dpkg_architecture_to_machine_info(output: str, options: T.Any) -> MachineInf
data['DEB_HOST_ARCH_OS'])
host_cpu_family = deb_cpu_family_map.get(data['DEB_HOST_GNU_CPU'],
data['DEB_HOST_GNU_CPU'])
host_cpu = deb_cpu_map.get(data['DEB_HOST_ARCH'],
data['DEB_HOST_ARCH'])
host_cpu = deb_arch_cpu_map.get(data['DEB_HOST_ARCH'],
deb_cpu_map.get(data['DEB_HOST_GNU_CPU'],
data['DEB_HOST_GNU_CPU']))
host_endian = data['DEB_HOST_ARCH_ENDIAN']

compilerstems = [('c', 'gcc'),
Expand Down
13 changes: 4 additions & 9 deletions unittests/internaltests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1846,9 +1846,7 @@ def locate_path(program: str) -> T.List[str]:
system='linux',
subsystem='linux',
kernel='linux',
# TODO: In native builds we get x86_64, but in
# cross-builds it's amd64
cpu='TODO',
cpu='x86_64',
cpu_family='x86_64',
endian='little',
),
Expand Down Expand Up @@ -1981,8 +1979,7 @@ def locate_path(program: str) -> T.List[str]:
# fail when kernel() is called.
# https://github.com/mesonbuild/meson/issues/13740
kernel='TODO',
# TODO: Currently hurd-i386, but should be i686
cpu='TODO',
cpu='i686',
cpu_family='x86',
endian='little',
),
Expand Down Expand Up @@ -2037,8 +2034,7 @@ def locate_path(program: str) -> T.List[str]:
system='kfreebsd',
subsystem='kfreebsd',
kernel='freebsd',
# TODO: Currently kfreebsd-amd64 but should be x86_64
cpu='TODO',
cpu='x86_64',
cpu_family='x86_64',
endian='little',
),
Expand Down Expand Up @@ -2148,8 +2144,7 @@ def locate_path(program: str) -> T.List[str]:
system='linux',
subsystem='linux',
kernel='linux',
# TODO: Currently ppc64el, but native builds have ppc64le,
# and maybe it should be ppc64 in both cases?
# TODO: Currently ppc64, but native builds have ppc64le
# https://github.com/mesonbuild/meson/issues/13741
cpu='TODO',
cpu_family='ppc64',
Expand Down

0 comments on commit fc87950

Please sign in to comment.