Add OpenHarmony (OHOS) support as an Android subsystem

OHOS behaves like Android: applications are shared libraries and
shared libraries are not versioned. But it uses musl instead of
Bionic. Model it as an Android subsystem rather than a separate
system: machine files set system = 'android' and subsystem = 'ohos',
so is_android() applies and all Android handling (unversioned
libfoo.so, the zlib include exception, PIE, android_exe_type) is
inherited automatically.

Add a MachineInfo.is_ohos() predicate (is_android() and subsystem ==
'ohos') and use it to set CMAKE_SYSTEM_NAME = OHOS for CMake subprojects,
since CMake has a dedicated OHOS system name.
This commit is contained in:
Joerg Bornemann
2026-06-23 15:08:35 +02:00
committed by Paolo Bonzini
parent 32e2b6b9b5
commit d7ced03b42
5 changed files with 68 additions and 2 deletions

View File

@@ -162,7 +162,7 @@ These are provided by the `.system()` method call.
| Value | Comment |
| ----- | ------- |
| android | |
| android | Android or OpenHarmony / HarmonyOS (OHOS) |
| cygwin | Cygwin or MSYS2 environment on Windows |
| darwin | Either OSX or iOS |
| dragonfly | DragonFly BSD |
@@ -208,6 +208,10 @@ 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.
### `darwin` subsystems
Set when `system` is `darwin`.
| Value | Comment |
| ----- | ------- |
| macos | Apple macOS (formerly OSX) |
@@ -220,6 +224,15 @@ Meson natively.
| watchos | Apple watchOS |
| watchos-simulator | |
### `android` subsystems (since 1.12.0)
Set when `system` is `android`.
| Value | Comment |
| ----- | ------- |
| android | Android (Bionic libc) |
| ohos | OpenHarmony / HarmonyOS (OHOS) |
## Language arguments parameter names
These are the parameter names for passing language specific arguments

View File

@@ -0,0 +1,20 @@
## OpenHarmony (OHOS) is now recognized as an Android subsystem
Meson now recognizes OpenHarmony / HarmonyOS (OHOS). OHOS behaves like
Android -- applications are shared libraries, shared libraries are not
versioned, and so on -- but uses musl instead of Bionic. It is therefore
modelled as an Android subsystem rather than a separate system.
Machine files select it in the `[host_machine]` section with:
```ini
[host_machine]
system = 'android'
subsystem = 'ohos'
```
With this, `host_machine.system()` is `'android'` (so all Android handling
applies, including unversioned `libfoo.so` output) while
`host_machine.subsystem()` is `'ohos'`. When cross-compiling a CMake
subproject, the toolchain file generated by the CMake module sets
`CMAKE_SYSTEM_NAME = OHOS`.

View File

@@ -155,7 +155,13 @@ class CMakeToolchain:
# Only set these in a cross build. Otherwise CMake will trip up in native
# builds and thing they are cross (which causes TRY_RUN() to break)
if self.env.is_cross_build(when_building_for=self.for_machine):
defaults['CMAKE_SYSTEM_NAME'] = [SYSTEM_MAP.get(self.minfo.system, self.minfo.system)]
# OHOS is modelled as an Android subsystem in meson, but CMake has a
# dedicated OHOS system name, so map it explicitly.
if self.minfo.is_ohos():
system_name = 'OHOS'
else:
system_name = SYSTEM_MAP.get(self.minfo.system, self.minfo.system)
defaults['CMAKE_SYSTEM_NAME'] = [system_name]
defaults['CMAKE_SYSTEM_PROCESSOR'] = [self.minfo.cpu_family]
defaults['CMAKE_SIZEOF_VOID_P'] = ['8' if self.minfo.is_64_bit else '4']

View File

@@ -344,6 +344,17 @@ class MachineInfo(HoldableObject):
"""
return self.system == 'android'
def is_ohos(self) -> bool:
"""
Machine is OpenHarmony (OHOS)?
OHOS is modelled as an Android subsystem: it behaves like Android
(apps are shared libraries, no versioned sonames, ...) but uses musl
instead of Bionic. Machine files select it with system = 'android'
and subsystem = 'ohos'.
"""
return self.is_android() and self.subsystem == 'ohos'
def is_haiku(self) -> bool:
"""
Machine is Haiku?

View File

@@ -54,6 +54,22 @@ from .helpers import *
class InternalTests(unittest.TestCase):
def test_machine_info_is_ohos(self):
def machine(system: str, subsystem: str) -> mesonbuild.envconfig.MachineInfo:
return mesonbuild.envconfig.MachineInfo(
system=system, cpu_family='aarch64', cpu='aarch64',
endian='little', kernel='linux', subsystem=subsystem)
# OHOS is modelled as an Android subsystem.
ohos = machine('android', 'ohos')
self.assertTrue(ohos.is_ohos())
self.assertTrue(ohos.is_android())
# Plain Android is not OHOS.
self.assertFalse(machine('android', 'android').is_ohos())
# A non-Android system with an 'ohos' subsystem is not OHOS either.
self.assertFalse(machine('linux', 'ohos').is_ohos())
def test_version_number(self):
self.assertEqual(search_version('foobar 1.2.3'), '1.2.3')
self.assertEqual(search_version('1.2.3'), '1.2.3')