Skip to content

gh-162319: Add OpenHarmony platform identifiers - #162322

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

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: 446 test modules passed and 14 failed.
  • Cross-compilation: 440 test modules passed and 13 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review type-feature A feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add OpenHarmony platform identifiers

1 participant