diff --git a/docs/markdown/Reference-tables.md b/docs/markdown/Reference-tables.md index 9c17ab35c..73573971f 100644 --- a/docs/markdown/Reference-tables.md +++ b/docs/markdown/Reference-tables.md @@ -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 diff --git a/docs/markdown/snippets/ohos-support.md b/docs/markdown/snippets/ohos-support.md new file mode 100644 index 000000000..4331a8709 --- /dev/null +++ b/docs/markdown/snippets/ohos-support.md @@ -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`. diff --git a/mesonbuild/cmake/toolchain.py b/mesonbuild/cmake/toolchain.py index 033fc8c4c..60b061557 100644 --- a/mesonbuild/cmake/toolchain.py +++ b/mesonbuild/cmake/toolchain.py @@ -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'] diff --git a/mesonbuild/envconfig.py b/mesonbuild/envconfig.py index 4d68c19d0..7c5aa8850 100644 --- a/mesonbuild/envconfig.py +++ b/mesonbuild/envconfig.py @@ -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? diff --git a/unittests/internaltests.py b/unittests/internaltests.py index 4229769b9..6c4663036 100644 --- a/unittests/internaltests.py +++ b/unittests/internaltests.py @@ -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')