Add kernel and subsystem properties to machine objects.
This commit is contained in:
parent
23efc1abea
commit
b0d2a92584
|
@ -25,6 +25,8 @@ has_function_hfkerhisadf = false
|
||||||
|
|
||||||
[host_machine]
|
[host_machine]
|
||||||
system = 'darwin'
|
system = 'darwin'
|
||||||
|
subsystem = 'ios'
|
||||||
|
kernel = 'xnu'
|
||||||
cpu_family = 'aarch64'
|
cpu_family = 'aarch64'
|
||||||
cpu = 'aarch64'
|
cpu = 'aarch64'
|
||||||
endian = 'little'
|
endian = 'little'
|
||||||
|
|
|
@ -22,6 +22,8 @@ has_function_hfkerhisadf = false
|
||||||
|
|
||||||
[host_machine]
|
[host_machine]
|
||||||
system = 'darwin'
|
system = 'darwin'
|
||||||
|
subsystem = 'tvos'
|
||||||
|
kernel = 'xnu'
|
||||||
cpu_family = 'arm'
|
cpu_family = 'arm'
|
||||||
cpu = 'arm64'
|
cpu = 'arm64'
|
||||||
endian = 'little'
|
endian = 'little'
|
||||||
|
|
|
@ -212,6 +212,8 @@ target machines look the same. Here is a sample for host machine.
|
||||||
```ini
|
```ini
|
||||||
[host_machine]
|
[host_machine]
|
||||||
system = 'windows'
|
system = 'windows'
|
||||||
|
subsystem = 'windows'
|
||||||
|
kernel = 'nt'
|
||||||
cpu_family = 'x86'
|
cpu_family = 'x86'
|
||||||
cpu = 'i686'
|
cpu = 'i686'
|
||||||
endian = 'little'
|
endian = 'little'
|
||||||
|
@ -221,9 +223,13 @@ These values define the machines sufficiently for cross compilation
|
||||||
purposes. The corresponding target definition would look the same but
|
purposes. The corresponding target definition would look the same but
|
||||||
have `target_machine` in the header. These values are available in
|
have `target_machine` in the header. These values are available in
|
||||||
your Meson scripts. There are three predefined variables called,
|
your Meson scripts. There are three predefined variables called,
|
||||||
surprisingly, [[@build_machine]], [[@host_machine]] and [[@target_machine]].
|
surprisingly, [[@build_machine]], [[@host_machine]] and
|
||||||
Determining the operating system of your host machine is simply a
|
[[@target_machine]]. Determining the operating system of your host
|
||||||
matter of calling `host_machine.system()`.
|
machine is simply a matter of calling `host_machine.system()`.
|
||||||
|
Starting from version 1.2.0 you can get more fine grained information
|
||||||
|
using the `.subsystem()` and `.kernel()` methods. The return values of
|
||||||
|
these functions are documented in [the reference table
|
||||||
|
page](Reference-tables.md).
|
||||||
|
|
||||||
There are two different values for the CPU. The first one is
|
There are two different values for the CPU. The first one is
|
||||||
`cpu_family`. It is a general type of the CPU. This should have a
|
`cpu_family`. It is a general type of the CPU. This should have a
|
||||||
|
|
|
@ -163,9 +163,44 @@ These are provided by the `.system()` method call.
|
||||||
Any string not listed above is not guaranteed to remain stable in
|
Any string not listed above is not guaranteed to remain stable in
|
||||||
future releases.
|
future releases.
|
||||||
|
|
||||||
|
## Kernel names (since 1.2.0)
|
||||||
|
|
||||||
|
Native names as returned by the `.kernel()` method.
|
||||||
|
|
||||||
|
| Value | Comment |
|
||||||
|
| ----- | ------- |
|
||||||
|
| linux | |
|
||||||
|
| freebsd | |
|
||||||
|
| openbsd | |
|
||||||
|
| netbsd | |
|
||||||
|
| nt | |
|
||||||
|
| xnu | Kernel of various Apple OSes |
|
||||||
|
| sunos | |
|
||||||
|
| dragonfly | |
|
||||||
|
| haiku| |
|
||||||
|
| none | For e.g. bare metal embedded |
|
||||||
|
|
||||||
|
|
||||||
|
## Subsystem names (since 1.2.0)
|
||||||
|
|
||||||
|
A more specific description of the system in question. Most values are
|
||||||
|
meant to be used in cross files only, as those platforms can not run
|
||||||
|
Meson natively.
|
||||||
|
|
||||||
|
| Value | Comment |
|
||||||
|
| ----- | ------- |
|
||||||
|
| macos | Apple macOS (formerly OSX) |
|
||||||
|
| ios | Apple iOS |
|
||||||
|
| ios-simulator | |
|
||||||
|
| tvos | Apple tvOS |
|
||||||
|
| tvos-simulator | |
|
||||||
|
| watchos | Apple watchOS |
|
||||||
|
| watchos-simulator | |
|
||||||
|
|
||||||
## Language arguments parameter names
|
## Language arguments parameter names
|
||||||
|
|
||||||
These are the parameter names for passing language specific arguments to your build target.
|
These are the parameter names for passing language specific arguments
|
||||||
|
to your build target.
|
||||||
|
|
||||||
| Language | compiler name | linker name |
|
| Language | compiler name | linker name |
|
||||||
| ------------- | ------------- | ----------------- |
|
| ------------- | ------------- | ----------------- |
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
## Machine objects get `kernel` and `subsystem` properties
|
||||||
|
|
||||||
|
Meson has traditionally provided a `system` property to detect the
|
||||||
|
system being run on. However this is not enough to reliably
|
||||||
|
differentiate between e.g. an iOS platform from a watchOS one. Two new
|
||||||
|
properties, namely `kernel` and `subsystem` have been added so these
|
||||||
|
setups can be reliably detected.
|
||||||
|
|
||||||
|
These new properties are not necessary in cross files for now, but if
|
||||||
|
they are not defined and a build file tries to access them, Meson will
|
||||||
|
exit with a hard error. It is expected that at some point in the
|
||||||
|
future defining the new properties will become mandatory.
|
|
@ -260,6 +260,8 @@ class MachineInfo(HoldableObject):
|
||||||
cpu_family: str
|
cpu_family: str
|
||||||
cpu: str
|
cpu: str
|
||||||
endian: str
|
endian: str
|
||||||
|
kernel: T.Optional[str]
|
||||||
|
subsystem: T.Optional[str]
|
||||||
|
|
||||||
def __post_init__(self) -> None:
|
def __post_init__(self) -> None:
|
||||||
self.is_64_bit: bool = self.cpu_family in CPU_FAMILIES_64_BIT
|
self.is_64_bit: bool = self.cpu_family in CPU_FAMILIES_64_BIT
|
||||||
|
@ -283,7 +285,11 @@ class MachineInfo(HoldableObject):
|
||||||
if endian not in ('little', 'big'):
|
if endian not in ('little', 'big'):
|
||||||
mlog.warning(f'Unknown endian {endian}')
|
mlog.warning(f'Unknown endian {endian}')
|
||||||
|
|
||||||
return cls(literal['system'], cpu_family, literal['cpu'], endian)
|
system = literal['system']
|
||||||
|
kernel = literal.get('kernel', None)
|
||||||
|
subsystem = literal.get('subsystem', None)
|
||||||
|
|
||||||
|
return cls(system, cpu_family, literal['cpu'], endian, kernel, subsystem)
|
||||||
|
|
||||||
def is_windows(self) -> bool:
|
def is_windows(self) -> bool:
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -395,6 +395,27 @@ def detect_cpu(compilers: CompilersDict) -> str:
|
||||||
# detect_cpu_family() above.
|
# detect_cpu_family() above.
|
||||||
return trial
|
return trial
|
||||||
|
|
||||||
|
KERNEL_MAPPINGS: T.Mapping[str, str] = {'freebsd': 'freebsd',
|
||||||
|
'openbsd': 'openbsd',
|
||||||
|
'netbsd': 'netbsd',
|
||||||
|
'windows': 'nt',
|
||||||
|
'android': 'linux',
|
||||||
|
'linux': 'linux',
|
||||||
|
'cygwin': 'nt',
|
||||||
|
'darwin': 'xnu',
|
||||||
|
'sunos': 'sunos',
|
||||||
|
'dragonfly': 'dragonfly',
|
||||||
|
'haiku': 'haiku',
|
||||||
|
}
|
||||||
|
|
||||||
|
def detect_kernel(system: str) -> T.Optional[str]:
|
||||||
|
return KERNEL_MAPPINGS.get(system, None)
|
||||||
|
|
||||||
|
def detect_subsystem(system: str) -> T.Optional[str]:
|
||||||
|
if system == 'darwin':
|
||||||
|
return 'macos'
|
||||||
|
return system
|
||||||
|
|
||||||
def detect_system() -> str:
|
def detect_system() -> str:
|
||||||
if sys.platform == 'cygwin':
|
if sys.platform == 'cygwin':
|
||||||
return 'cygwin'
|
return 'cygwin'
|
||||||
|
@ -411,11 +432,14 @@ def detect_machine_info(compilers: T.Optional[CompilersDict] = None) -> MachineI
|
||||||
underlying ''detect_*'' method can be called to explicitly use the
|
underlying ''detect_*'' method can be called to explicitly use the
|
||||||
partial information.
|
partial information.
|
||||||
"""
|
"""
|
||||||
|
system = detect_system()
|
||||||
return MachineInfo(
|
return MachineInfo(
|
||||||
detect_system(),
|
system,
|
||||||
detect_cpu_family(compilers) if compilers is not None else None,
|
detect_cpu_family(compilers) if compilers is not None else None,
|
||||||
detect_cpu(compilers) if compilers is not None else None,
|
detect_cpu(compilers) if compilers is not None else None,
|
||||||
sys.byteorder)
|
sys.byteorder,
|
||||||
|
detect_kernel(system),
|
||||||
|
detect_subsystem(system))
|
||||||
|
|
||||||
# TODO make this compare two `MachineInfo`s purely. How important is the
|
# TODO make this compare two `MachineInfo`s purely. How important is the
|
||||||
# `detect_cpu_family({})` distinction? It is the one impediment to that.
|
# `detect_cpu_family({})` distinction? It is the one impediment to that.
|
||||||
|
|
|
@ -639,6 +639,8 @@ class MachineHolder(ObjectHolder['MachineInfo']):
|
||||||
'cpu': self.cpu_method,
|
'cpu': self.cpu_method,
|
||||||
'cpu_family': self.cpu_family_method,
|
'cpu_family': self.cpu_family_method,
|
||||||
'endian': self.endian_method,
|
'endian': self.endian_method,
|
||||||
|
'kernel': self.kernel_method,
|
||||||
|
'subsystem': self.subsystem_method,
|
||||||
})
|
})
|
||||||
|
|
||||||
@noPosargs
|
@noPosargs
|
||||||
|
@ -661,6 +663,21 @@ class MachineHolder(ObjectHolder['MachineInfo']):
|
||||||
def endian_method(self, args: T.List[TYPE_var], kwargs: TYPE_kwargs) -> str:
|
def endian_method(self, args: T.List[TYPE_var], kwargs: TYPE_kwargs) -> str:
|
||||||
return self.held_object.endian
|
return self.held_object.endian
|
||||||
|
|
||||||
|
@noPosargs
|
||||||
|
@noKwargs
|
||||||
|
def kernel_method(self, args: T.List[TYPE_var], kwargs: TYPE_kwargs) -> str:
|
||||||
|
if self.held_object.kernel is not None:
|
||||||
|
return self.held_object.kernel
|
||||||
|
raise InterpreterException('Kernel not defined or could not be autodetected.')
|
||||||
|
|
||||||
|
@noPosargs
|
||||||
|
@noKwargs
|
||||||
|
def subsystem_method(self, args: T.List[TYPE_var], kwargs: TYPE_kwargs) -> str:
|
||||||
|
if self.held_object.subsystem is not None:
|
||||||
|
return self.held_object.subsystem
|
||||||
|
raise InterpreterException('Subsystem not defined or could not be autodetected.')
|
||||||
|
|
||||||
|
|
||||||
class IncludeDirsHolder(ObjectHolder[build.IncludeDirs]):
|
class IncludeDirsHolder(ObjectHolder[build.IncludeDirs]):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
@ -44,6 +44,10 @@ def add_arguments(parser: 'argparse.ArgumentParser') -> None:
|
||||||
help='Generate a native compilation file.')
|
help='Generate a native compilation file.')
|
||||||
parser.add_argument('--system', default=None,
|
parser.add_argument('--system', default=None,
|
||||||
help='Define system for cross compilation.')
|
help='Define system for cross compilation.')
|
||||||
|
parser.add_argument('--subsystem', default=None,
|
||||||
|
help='Define subsystem for cross compilation.')
|
||||||
|
parser.add_argument('--kernel', default=None,
|
||||||
|
help='Define kernel for cross compilation.')
|
||||||
parser.add_argument('--cpu', default=None,
|
parser.add_argument('--cpu', default=None,
|
||||||
help='Define cpu for cross compilation.')
|
help='Define cpu for cross compilation.')
|
||||||
parser.add_argument('--cpu-family', default=None,
|
parser.add_argument('--cpu-family', default=None,
|
||||||
|
@ -61,6 +65,8 @@ class MachineInfo:
|
||||||
self.cmake: T.Dict[str, T.Union[str, T.List[str]]] = {}
|
self.cmake: T.Dict[str, T.Union[str, T.List[str]]] = {}
|
||||||
|
|
||||||
self.system: T.Optional[str] = None
|
self.system: T.Optional[str] = None
|
||||||
|
self.subsystem: T.Optional[str] = None
|
||||||
|
self.kernel: T.Optional[str] = None
|
||||||
self.cpu: T.Optional[str] = None
|
self.cpu: T.Optional[str] = None
|
||||||
self.cpu_family: T.Optional[str] = None
|
self.cpu_family: T.Optional[str] = None
|
||||||
self.endian: T.Optional[str] = None
|
self.endian: T.Optional[str] = None
|
||||||
|
@ -181,6 +187,8 @@ def detect_cross_debianlike(options: T.Any) -> MachineInfo:
|
||||||
data[k] = v
|
data[k] = v
|
||||||
host_arch = data['DEB_HOST_GNU_TYPE']
|
host_arch = data['DEB_HOST_GNU_TYPE']
|
||||||
host_os = data['DEB_HOST_ARCH_OS']
|
host_os = data['DEB_HOST_ARCH_OS']
|
||||||
|
host_subsystem = host_os
|
||||||
|
host_kernel = 'linux'
|
||||||
host_cpu_family = deb_cpu_family_map.get(data['DEB_HOST_GNU_CPU'],
|
host_cpu_family = deb_cpu_family_map.get(data['DEB_HOST_GNU_CPU'],
|
||||||
data['DEB_HOST_GNU_CPU'])
|
data['DEB_HOST_GNU_CPU'])
|
||||||
host_cpu = deb_cpu_map.get(data['DEB_HOST_ARCH'],
|
host_cpu = deb_cpu_map.get(data['DEB_HOST_ARCH'],
|
||||||
|
@ -213,6 +221,8 @@ def detect_cross_debianlike(options: T.Any) -> MachineInfo:
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
infos.system = host_os
|
infos.system = host_os
|
||||||
|
infos.subsystem = host_subsystem
|
||||||
|
infos.kernel = host_kernel
|
||||||
infos.cpu_family = host_cpu_family
|
infos.cpu_family = host_cpu_family
|
||||||
infos.cpu = host_cpu
|
infos.cpu = host_cpu
|
||||||
infos.endian = host_endian
|
infos.endian = host_endian
|
||||||
|
@ -260,6 +270,11 @@ def write_machine_file(infos: MachineInfo, ofilename: str, write_system_info: bo
|
||||||
ofile.write(f"cpu_family = '{infos.cpu_family}'\n")
|
ofile.write(f"cpu_family = '{infos.cpu_family}'\n")
|
||||||
ofile.write(f"endian = '{infos.endian}'\n")
|
ofile.write(f"endian = '{infos.endian}'\n")
|
||||||
ofile.write(f"system = '{infos.system}'\n")
|
ofile.write(f"system = '{infos.system}'\n")
|
||||||
|
if infos.subsystem:
|
||||||
|
ofile.write(f"subsystem = '{infos.subsystem}'\n")
|
||||||
|
if infos.kernel:
|
||||||
|
ofile.write(f"kernel = '{infos.kernel}'\n")
|
||||||
|
|
||||||
os.replace(tmpfilename, ofilename)
|
os.replace(tmpfilename, ofilename)
|
||||||
|
|
||||||
def detect_language_args_from_envvars(langname: str, envvar_suffix: str = '') -> T.Tuple[T.List[str], T.List[str]]:
|
def detect_language_args_from_envvars(langname: str, envvar_suffix: str = '') -> T.Tuple[T.List[str], T.List[str]]:
|
||||||
|
@ -306,7 +321,7 @@ def detect_properties_from_envvars(infos: MachineInfo, envvar_suffix: str = '')
|
||||||
infos.properties['sys_root'] = var
|
infos.properties['sys_root'] = var
|
||||||
|
|
||||||
def detect_cross_system(infos: MachineInfo, options: T.Any) -> None:
|
def detect_cross_system(infos: MachineInfo, options: T.Any) -> None:
|
||||||
for optname in ('system', 'cpu', 'cpu_family', 'endian'):
|
for optname in ('system', 'subsystem', 'kernel', 'cpu', 'cpu_family', 'endian'):
|
||||||
v = getattr(options, optname)
|
v = getattr(options, optname)
|
||||||
if not v:
|
if not v:
|
||||||
mlog.error(f'Cross property "{optname}" missing, set it with --{optname.replace("_", "-")}.')
|
mlog.error(f'Cross property "{optname}" missing, set it with --{optname.replace("_", "-")}.')
|
||||||
|
|
Loading…
Reference in New Issue