Skip to content

gh-162319: Add OpenHarmony platform identifiers - #162322

Draft
hqzing wants to merge 3 commits into
python:mainfrom
hqzing:ohos
Draft

hqzing wants to merge 3 commits into
python:mainfrom
hqzing:ohos

Conversation

@hqzing

@hqzing hqzing commented Nov 20, 2026 •

Copy link
Copy Markdown

Closes #162319.

Background

This PR adds basic build support for the OpenHarmony platform.

The OpenHarmony standard system uses a Linux kernel (or a Linux-compatible kernel) but not the GNU userland. This architecture is similar to Android, so this PR follows CPython's existing Android platform handling where applicable:

  • *-*-linux-android* is identified as Linux-android, with MACHDEP=android.
  • *-*-linux-ohos* is identified as Linux-ohos, with MACHDEP=ohos.

This preserves the existing Linux platform logic while providing the platform identity required for OpenHarmony, including its wheel platform tags.

The linux-ohos identifier is not an arbitrary name introduced by this PR. It follows the target triple assigned to OpenHarmony by the LLVM toolchain: <arch>-unknown-linux-ohos (shorthand: <arch>-linux-ohos).

Changes

  • Detect OpenHarmony through __OHOS__ and *-*-linux-ohos* in native and cross-compilation paths, resulting in sys.platform == "ohos".
  • Update CPython's bundled config.sub to accept linux-ohos. This change was backported from GNU config commit 5d8be4275fe9066e3322386213120e1d93af6020.
  • Detect the build API level from the SDK's documented oh-uni-package.json metadata and record it as OHOS_API_LEVEL, since OpenHarmony does not provide an API-level compiler macro like Android's __ANDROID_API__.
  • Include the build API level in the sysconfig platform string (for example, ohos-26-aarch64) and the corresponding wheel tag (for example, ohos_26_aarch64).
  • Add platform.ohos_ver() to report the OS release and runtime API level.
  • Regenerate the configure-related files.

No existing branches for other platforms are changed.

Scope

This PR targets the three architectures supported by the OpenHarmony SDK: aarch64, arm, and x86_64.

Native compilation is detected automatically by config.guess, so no explicit target triple is required:

./configure

# Equivalent to:
# ./configure \
# --build=aarch64-unknown-linux-ohos \
# --host=aarch64-unknown-linux-ohos

For cross-compilation, explicitly specify the target triple and provide the build machine's triple and --with-build-python as required by CPython:

./configure \
 --build=<build-triple> \
 --host=aarch64-unknown-linux-ohos \
 --with-build-python=<build-python>

Testing

I validated CPython's main branch using both native compilation on aarch64 OpenHarmony and cross-compilation from x86_64 Linux with the official OpenHarmony SDK. I ran the resulting interpreters on aarch64 OpenHarmony and verified:

  • sys.platform == "ohos".
  • sysconfig.get_platform() == "ohos-26-aarch64".
  • sysconfig.get_config_var("OHOS_API_LEVEL") == 26.
  • build-details.json contains "platform": "ohos-26-aarch64".
  • platform.ohos_ver() returns OhosVer(release='7.0.0.109', api_level=26).

I also ran the full test suite for both configurations:

  • Native compilation: 447 test modules passed and 15 failed.
  • Cross-compilation: 448 test modules passed and 14 failed.

The remaining failures involve platform and libc differences and are outside the scope of this PR. Tests for unavailable optional modules are skipped.

@python-cla-bot

python-cla-bot Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@bedevere-app bedevere-app Bot added the type-feature A feature request or enhancement label Nov 20, 2026
@read-the-docs-community

read-the-docs-community Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #36080702 | 📁 Comparing 7f94b90 against main (a3ea5d2)

  🔍 Preview build  

7 files changed · ± 7 modified

± Modified

@hqzing hqzing changed the title gh-162319: Add OpenHarmony platform identifiers gh-162319: Add OpenHarmony platform identifiers and API level support Nov 22, 2026
@hqzing hqzing changed the title gh-162319: Add OpenHarmony platform identifiers and API level support gh-162319: Add OpenHarmony platform identifiers Nov 22, 2026

@StanFromIreland StanFromIreland left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A new sys.platform value, wheel tag and public platform.ohos_ver() API are more than a minor feature, e.g., Android and iOS got theirs through PEPs (738 and 730), so I think those parts need at minimum a Discourse discussion first. Could this PR be reduced to the config.sub/config.guess sync and the platform_triplet.c block, leaving sys.platform as "linux" like we do for musl?

@bedevere-app

bedevere-app Bot commented Nov 24, 2026

Copy link
Copy Markdown

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@liangqi

liangqi commented Nov 25, 2026

Copy link
Copy Markdown

How to distinguish OpenHarmony and HarmonyOS(the commercial one from Huawei)? Thanks.

Comment thread Lib/sysconfig/__init__.py Outdated
"x86_64": "x86_64",
}[machine]
elif sys.platform == "ohos":
return f"ohos-{machine}"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should follow "android" case.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see, it's fixed in 2b84f7e .

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

self._set_uname(('Linux', 'localhost', '5.10.43', '#1 SMP', 'aarch64'))
self.assertEqual(get_platform(), 'ohos-aarch64')
self.assertEqual(get_platform(), 'ohos-26-aarch64')
sys.platform = 'linux'

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is needed.

@liangqi

liangqi commented Nov 25, 2026 •

Copy link
Copy Markdown

I am not very familiar with GitHub setup to comment in commits. Hope I have done the right thing.

After brief reading https://github.com/python/cpython/pull/162322/commits

leaving sys.platform as "linux"

I don't think that's the right idea, based on my experience of development on HarmonyOS.

I am generally fine with those two changes just to add a new platform ohos.

One more thing, OpenHarmony and HarmonyOS 7.0 SDK are not public available to developers outside of China(even with Huawei Developer ID). Then it's better also support 6.1 in some way.

@liangqi

liangqi commented Nov 25, 2026

Copy link
Copy Markdown

How to distinguish OpenHarmony and HarmonyOS(the commercial one from Huawei)? Thanks.

It's not a problem. HarmonyOS can continue to use ohos.

@hqzing

hqzing commented Nov 25, 2026

Copy link
Copy Markdown
Author

@liangqi You are not a community maintainer, I did not request a review from you, and this matter has absolutely nothing to do with you. Could you please remain silent for now and let the community maintainers complete the review? You have generated far too much activity. If you need to discuss anything, please do so with me through another channel.

@StanFromIreland

StanFromIreland commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Community members are welcome to review PRs, regardless of whether they are maintainers or were explicitly asked to do so. While in this case the review may have been a little excessive, people make mistakes, and we should assume good intentions. Asking someone to remain silent in this manner is unnecessarily dismissive. Please take a moment to read our Code of Conduct and keep interactions respectful and welcoming.

@hqzing

hqzing commented Nov 25, 2026

Copy link
Copy Markdown
Author

@StanFromIreland Got it.

@hqzing

hqzing commented Nov 25, 2026

Copy link
Copy Markdown
Author

@StanFromIreland Today, I learned that another developer is also working on adding support for OpenHarmony and is expected to start a discussion on Discourse in the next few days. Their goals align with my current objectives. Therefore, I would prefer to retain all of the feature support currently included rather than narrow the scope of the PR. Once the Discourse thread has been created, we can continue discussing this topic there.

@StanFromIreland
StanFromIreland marked this pull request as draft November 25, 2026 17:52
@StanFromIreland

Copy link
Copy Markdown
Member

Sure, then I'll convert this to a draft.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type-feature A feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add OpenHarmony platform identifiers

3 participants