diff options
-rw-r--r-- | docs/markdown/Cross-compilation.md | 12 | ||||
-rw-r--r-- | docs/markdown/Reference-tables.md | 36 | ||||
-rw-r--r-- | docs/markdown/snippets/moremachinedata.md | 12 | ||||
-rw-r--r-- | mesonbuild/envconfig.py | 8 | ||||
-rw-r--r-- | mesonbuild/environment.py | 30 | ||||
-rw-r--r-- | mesonbuild/interpreter/interpreterobjects.py | 17 |
6 files changed, 109 insertions, 6 deletions
diff --git a/docs/markdown/Cross-compilation.md b/docs/markdown/Cross-compilation.md index fb222220e..159d0ab49 100644 --- a/docs/markdown/Cross-compilation.md +++ b/docs/markdown/Cross-compilation.md @@ -212,6 +212,8 @@ target machines look the same. Here is a sample for host machine. ```ini [host_machine] system = 'windows' +userland = 'windows' +kernel = 'windows' cpu_family = 'x86' cpu = 'i686' 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 have `target_machine` in the header. These values are available in your Meson scripts. There are three predefined variables called, -surprisingly, [[@build_machine]], [[@host_machine]] and [[@target_machine]]. -Determining the operating system of your host machine is simply a -matter of calling `host_machine.system()`. +surprisingly, [[@build_machine]], [[@host_machine]] and +[[@target_machine]]. Determining the operating system of your host +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 `.userland()` 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 `cpu_family`. It is a general type of the CPU. This should have a diff --git a/docs/markdown/Reference-tables.md b/docs/markdown/Reference-tables.md index fb7deda8a..dbbb92dac 100644 --- a/docs/markdown/Reference-tables.md +++ b/docs/markdown/Reference-tables.md @@ -161,6 +161,42 @@ These are provided by the `.system()` method call. Any string not listed above is not guaranteed to remain stable in future releases. +## Kernel names (since 1.2.0) + +Native names as returned by the `.kernel()` method. + +| Value | Comment | +| ----- | ------- | +| linux | | +| freebsd | | +| openbsd | | +| windows | | +| xnu | Kernel of various Apple OSes | + + +## Userland names (since 1.2.0) + +Native names as returned by the `.userland()` method. + +| Value | Comment | +| ----- | ------- | +| gnu | Linux or Hurd | +| musl | Linux using Musl libc | +| macos | The OS formerly known as Mac OSX | +| freebsd | | +| openbsd | | +| windows | | + +Recommended cross build names for systems that can not run Meson +natively. + +| Value | Comment | +| ----- | ------- | +| ios | Apple iOS | +| tvos | Apple tvOS | +| watchos | Apple watchOS | +| ipados | Apple iPadOS | + ## Language arguments parameter names These are the parameter names for passing language specific arguments to your build target. diff --git a/docs/markdown/snippets/moremachinedata.md b/docs/markdown/snippets/moremachinedata.md new file mode 100644 index 000000000..27d9a7eb2 --- /dev/null +++ b/docs/markdown/snippets/moremachinedata.md @@ -0,0 +1,12 @@ +## Machine objects get `kernel` and `userland` 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 `userland` have been added to make +this configuration doable. + +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. diff --git a/mesonbuild/envconfig.py b/mesonbuild/envconfig.py index 50c974bd1..964e352a2 100644 --- a/mesonbuild/envconfig.py +++ b/mesonbuild/envconfig.py @@ -260,6 +260,8 @@ class MachineInfo(HoldableObject): cpu_family: str cpu: str endian: str + kernel: T.Optional[str] + userland: T.Optional[str] def __post_init__(self) -> None: 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'): mlog.warning(f'Unknown endian {endian}') - return cls(literal['system'], cpu_family, literal['cpu'], endian) + system = literal['system'] + kernel = literal.get('kernel', None) + userland = literal.get('userland', None) + + return cls(system, cpu_family, literal['cpu'], endian, kernel, userland) def is_windows(self) -> bool: """ diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py index ccd31ebaa..d67f3d89c 100644 --- a/mesonbuild/environment.py +++ b/mesonbuild/environment.py @@ -387,6 +387,29 @@ def detect_cpu(compilers: CompilersDict) -> str: # detect_cpu_family() above. return trial +kernel_mappings = {'freebsd': 'freebsd', + 'openbsd': 'openbsd', + 'windows': 'windows', + 'android': 'linux', + 'cygwin': 'windows', + 'darwin': 'xnu', + } + +userland_mappings = {'freebsd': 'freebsd', + 'openbsd': 'openbsd', + 'windows': 'windows', + 'darwin': 'macos', + 'gnu': 'gnu', + } + +def detect_kernel(system: str) -> T.Optional[str]: + return kernel_mappings.get(system, None) + +def detect_userland(system: str) -> T.Optional[str]: + if system == 'linux': + return 'gnu' # Fixme, check whether we are on a glibc system. + return userland_mappings.get(system, None) + def detect_system() -> str: if sys.platform == 'cygwin': return 'cygwin' @@ -403,11 +426,14 @@ def detect_machine_info(compilers: T.Optional[CompilersDict] = None) -> MachineI underlying ''detect_*'' method can be called to explicitly use the partial information. """ + system = detect_system() return MachineInfo( - detect_system(), + system, detect_cpu_family(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_userland(system)) # TODO make this compare two `MachineInfo`s purely. How important is the # `detect_cpu_family({})` distinction? It is the one impediment to that. diff --git a/mesonbuild/interpreter/interpreterobjects.py b/mesonbuild/interpreter/interpreterobjects.py index fa9171485..680732102 100644 --- a/mesonbuild/interpreter/interpreterobjects.py +++ b/mesonbuild/interpreter/interpreterobjects.py @@ -639,6 +639,8 @@ class MachineHolder(ObjectHolder['MachineInfo']): 'cpu': self.cpu_method, 'cpu_family': self.cpu_family_method, 'endian': self.endian_method, + 'kernel': self.kernel_method, + 'userland': self.userland_method, }) @noPosargs @@ -661,6 +663,21 @@ class MachineHolder(ObjectHolder['MachineInfo']): def endian_method(self, args: T.List[TYPE_var], kwargs: TYPE_kwargs) -> str: 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 userland_method(self, args: T.List[TYPE_var], kwargs: TYPE_kwargs) -> str: + if self.held_object.userland is not None: + return self.held_object.userland + raise InterpreterException('Userland not defined or could not be autodetected.') + + class IncludeDirsHolder(ObjectHolder[build.IncludeDirs]): pass |