Skip to content

HarmonyOS/OpenHarmony Port #13152

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 70 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
462476f
Harmony port: Workflows
Jack253-png May 30, 2025
a6ebc6a
Harmony port: Workflows (disable other plats)
Jack253-png May 30, 2025
15cbc26
Harmony port: Workflows (fix script error)
Jack253-png May 30, 2025
95ccfa6
Harmony port: Workflows (fix script error)
Jack253-png May 30, 2025
8f0b9c1
Harmony port: Workflows (fix script error)
Jack253-png May 30, 2025
1c48676
Harmony port: window fetching
Jack253-png May 30, 2025
addb748
Harmony port: disable lib version suffix
Jack253-png May 31, 2025
845ba7d
Harmony port: video vulkan library & disable version test
Jack253-png May 31, 2025
f25cbb1
Harmony port: video vulkan library & disable version test
Jack253-png May 31, 2025
4f5fcf6
Harmony port: video vulkan library & disable version test
Jack253-png May 31, 2025
e339bde
Harmony port: video vulkan library
Jack253-png May 31, 2025
1e75f1f
Harmony port: video vulkan library
Jack253-png May 31, 2025
cd0d25c
Harmony port: video library
Jack253-png May 31, 2025
8b6c78c
Harmony port: window creation
Jack253-png May 31, 2025
9e61fcb
Harmony port: egl/gles lib
Jack253-png May 31, 2025
dc28e96
Harmony port: keyboard event
Jack253-png May 31, 2025
2570e9a
Harmony port: video drv fix
Jack253-png May 31, 2025
af96018
Harmony port: napi callback shell
Jack253-png May 31, 2025
4a0d068
Harmony port: review changes
Jack253-png May 31, 2025
590509b
Harmony port: review changes
Jack253-png May 31, 2025
c99ae6e
Harmony port: review changes
Jack253-png May 31, 2025
298581d
Harmony port: review changes
Jack253-png May 31, 2025
231ed48
Harmony port: review changes
Jack253-png May 31, 2025
0f2b280
Harmony port: entrypoint
Jack253-png Jun 1, 2025
a910997
Harmony port: entrypoint
Jack253-png Jun 1, 2025
b182ae0
Harmony port: entrypoint
Jack253-png Jun 1, 2025
d031a49
Harmony port: entrypoint
Jack253-png Jun 1, 2025
04e8042
Harmony port: entrypoint
Jack253-png Jun 1, 2025
d4039d3
Harmony port: entrypoint
Jack253-png Jun 1, 2025
27df340
Harmony port: video device
Rwagsu Jun 1, 2025
cf3353a
Harmony port: call test
Jack253-png Jun 1, 2025
9605a66
Harmony port: fix
Jack253-png Jun 1, 2025
56ccf29
Harmony port: napi shell
Jack253-png Jun 1, 2025
c951070
Harmony port: touch event
Jack253-png Jun 1, 2025
e919066
Harmony port: fix
Jack253-png Jun 1, 2025
048a59b
Harmony port: fix
Jack253-png Jun 1, 2025
167fe8b
Harmony port: fix
Jack253-png Jun 1, 2025
01fed59
Harmony port: fix
Jack253-png Jun 1, 2025
a4b48d3
Harmony port: surface destroy
Jack253-png Jun 2, 2025
35ea914
Harmony port: fix
Jack253-png Jun 2, 2025
05f4fa7
Merge branch 'libsdl-org:main' into main
Jack253-png Jun 2, 2025
ec58846
Harmony port: fix napi call
Rwagsu Jun 2, 2025
a886df9
Merge branch 'main' of github.com:libsdl-org/SDL
Jack253-png Jun 6, 2025
9c3e5f2
Harmony port: pthread enable
Jack253-png Jun 6, 2025
cf69678
Update create-test-plan.py
Jack253-png Jun 7, 2025
4781c60
Update generic.yml
Jack253-png Jun 7, 2025
56cea28
Update CMakeLists.txt
Jack253-png Jun 7, 2025
0f4c8f5
Update create-test-plan.py
Jack253-png Jun 7, 2025
f6147e0
Update SDL_ohos.c
Jack253-png Jun 7, 2025
2b5815a
Update CMakeLists.txt
Jack253-png Jun 7, 2025
376aa5d
Update create-test-plan.py
Jack253-png Jun 7, 2025
29c6d18
Update create-test-plan.py
Jack253-png Jun 7, 2025
a649753
Harmony port: format
Jack253-png Jun 7, 2025
e7bcd9a
Harmony port: workflow fix [sdl-ci-filter harmony]
Jack253-png Jun 7, 2025
d7a01e6
Harmony port: workflow fix [sdl-ci-filter harmony]
Jack253-png Jun 7, 2025
b8f497f
Harmony port: workflow fix [sdl-ci-filter harmony]
Jack253-png Jun 8, 2025
38a7790
Harmony port: workflow fix [sdl-ci-filter harmony-*]
Jack253-png Jun 8, 2025
e7e0bd2
Harmony port: workflow fix [sdl-ci-filter harmony-*]
Jack253-png Jun 8, 2025
e7fdb9c
Harmony port: workflow
Jack253-png Jun 8, 2025
973260a
OpenHarmony Port (renderer)
Jack253-png Jun 21, 2025
69104d0
Harmony port: entrypoint multithread
Jack253-png Jun 28, 2025
44497fc
fix
Jack253-png Jun 28, 2025
56e42de
Harmony port: dialog
Jack253-png Jun 28, 2025
3e64c9e
Harmony port: locale
Jack253-png Jun 28, 2025
bc8a018
Harmony port: ohos project
Jack253-png Jun 28, 2025
3e14b2b
Harmony port: fix
Jack253-png Jun 28, 2025
9f185fa
Merge branch 'main' of github.com:libsdl-org/SDL
Jack253-png Jun 28, 2025
791e9b2
Merge branch 'main' of github.com:libsdl-org/SDL
Jack253-png Jul 3, 2025
ed283ad
Harmony port: main project
Jack253-png Jul 3, 2025
768c89c
Harmony port: doc v0
Jack253-png Jul 3, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/actions/setup-harmony-toolchain/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: 'Setup Harmony toolchain'
inputs:
version:
description: 'Harmony version'
default: '5.0.0-Release'
runs:
using: 'composite'
steps:
- uses: actions/cache/restore@v4
id: restore-cache
with:
path: /opt/native
key: harmony-${{ inputs.version }}

- name: Download Harmony toolchain
if: ${{ !steps.restore-cache.outputs.cache-hit }}
shell: bash
run: |
wget https://repo.huaweicloud.com/openharmony/os/${{ inputs.version }}/ohos-sdk-windows_linux-public.tar.gz
tar -zxvf ohos-sdk-windows_linux-public.tar.gz
mkdir -p /opt

unzip linux/native*.zip -d /opt
- uses: actions/cache/save@v4
if: ${{ !steps.restore-cache.outputs.cache-hit }}
with:
path: /opt/native
key: harmony-${{ inputs.version }}
- name: 'Set output vars'
id: final
shell: bash
run: |
echo "HARMONY_NATIVE_SDK=/opt/native" >> $GITHUB_OUTPUT
16 changes: 16 additions & 0 deletions .github/workflows/create-test-plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class SdlPlatform(Enum):
FreeBSD = "freebsd"
NetBSD = "netbsd"
NGage = "ngage"
Harmony = "harmony"


class Msys2Platform(Enum):
Expand Down Expand Up @@ -98,6 +99,7 @@ class JobSpec:
clang_cl: bool = False
gdk: bool = False
vita_gles: Optional[VitaGLES] = None
harmony_arch: Optional[str] = None


JOB_SPECS = {
Expand Down Expand Up @@ -141,6 +143,9 @@ class JobSpec:
"netbsd": JobSpec(name="NetBSD", os=JobOs.UbuntuLatest, platform=SdlPlatform.NetBSD, artifact="SDL-netbsd-x64", ),
"freebsd": JobSpec(name="FreeBSD", os=JobOs.UbuntuLatest, platform=SdlPlatform.FreeBSD, artifact="SDL-freebsd-x64", ),
"ngage": JobSpec(name="N-Gage", os=JobOs.WindowsLatest, platform=SdlPlatform.NGage, artifact="SDL-ngage", ),
"harmony-arm64": JobSpec(name="Harmony (Arm64)", os=JobOs.UbuntuLatest, platform=SdlPlatform.Harmony, artifact="SDL-harmony-arm64", harmony_arch="arm64-v8a"),
"harmony-arm32": JobSpec(name="Harmony (Arm32)", os=JobOs.UbuntuLatest, platform=SdlPlatform.Harmony, artifact="SDL-harmony-arm32", harmony_arch="armeabi-v7a"),
"harmony-x86_64": JobSpec(name="Harmony (x86-64)", os=JobOs.UbuntuLatest, platform=SdlPlatform.Harmony, artifact="SDL-harmony-x86_64", harmony_arch="x86_64"),
}


Expand Down Expand Up @@ -757,6 +762,17 @@ def spec_to_job(spec: JobSpec, key: str, trackmem_symbol_names: bool) -> JobDeta
job.setup_gage_sdk_path = "C:/ngagesdk"
job.cmake_toolchain_file = "C:/ngagesdk/cmake/ngage-toolchain.cmake"
job.test_pkg_config = False
case SdlPlatform.Harmony:
job.cmake_arguments.extend((
f"-DOHOS_ARCH={spec.harmony_arch}",
"-DCMAKE_TOOLCHAIN_FILE=/opt/native/build/cmake/ohos.toolchain.cmake",
"-DCMAKE_PLATFORM_NO_VERSIONED_SONAME=1"
))
job.shared_lib = SharedLibType.SO
job.static_lib = StaticLibType.A
job.run_tests = False
job.test_pkg_config = False
job.werror = False
case _:
raise ValueError(f"Unsupported platform={spec.platform}")

Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/generic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ jobs:
uses: ./.github/actions/setup-msvc-libusb
with:
arch: ${{ matrix.platform.setup-libusb-arch }}
- name: 'Set up Harmony toolchain'
if: ${{ matrix.platform.platform == 'harmony' }}
uses: ./.github/actions/setup-harmony-toolchain
- uses: mymindstorm/setup-emsdk@v14
if: ${{ matrix.platform.platform == 'emscripten' }}
with:
Expand Down
40 changes: 40 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1500,7 +1500,47 @@ if(ANDROID)
endif()
endif()
endif()
elseif(OHOS)
# disable warnings from the toolchain
sdl_compile_options(PRIVATE "-Wno-unused-command-line-argument")

sdl_link_dependency(ohos LIBS ace_napi.z hilog_ndk.z ace_ndk.z rawfile.z pixelmap_ndk.z)
sdl_glob_sources("${SDL3_SOURCE_DIR}/src/core/ohos/*.c")

if(SDL_VIDEO)
set(SDL_VIDEO_DRIVER_OHOS 1)
sdl_glob_sources("${SDL3_SOURCE_DIR}/src/video/ohos/*.c")
set(HAVE_SDL_VIDEO TRUE)
set(HAVE_VULKAN ON)
set(SDL_VIDEO_VULKAN ON)
set(SDL_VIDEO_RENDER_VULKAN 1)
set(HAVE_RENDER_VULKAN TRUE)

if(SDL_OPENGLES)
set(SDL_VIDEO_OPENGL_EGL 1)
set(HAVE_OPENGLES TRUE)
set(SDL_VIDEO_OPENGL_ES2 1)
set(SDL_VIDEO_RENDER_OGL_ES2 1)

sdl_link_dependency(opengles LIBS GLESv2)
endif()
endif()

set(SDL_LOADSO_DLOPEN 1)
sdl_glob_sources("${SDL3_SOURCE_DIR}/src/loadso/dlopen/*.c")
set(HAVE_SDL_LOADSO TRUE)

set(SDL_TIME_UNIX 1)
sdl_glob_sources("${SDL3_SOURCE_DIR}/src/time/unix/*.c")
set(HAVE_SDL_TIME TRUE)

set(SDL_TIMER_UNIX 1)
sdl_glob_sources("${SDL3_SOURCE_DIR}/src/timer/unix/*.c")
set(HAVE_SDL_TIMERS TRUE)

set(SDL_PTHREADS 1)

CheckPTHREAD()
elseif(EMSCRIPTEN)
# Hide noisy warnings that intend to aid mostly during initial stages of porting a new
# project. Uncomment at will for verbose cross-compiling -I/../ path info.
Expand Down
2 changes: 1 addition & 1 deletion cmake/macros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ function(SDL_PrintSummary)
message(STATUS "")
endif()

if(UNIX AND NOT (ANDROID OR APPLE OR EMSCRIPTEN OR HAIKU OR RISCOS))
if(UNIX AND NOT (ANDROID OR APPLE OR EMSCRIPTEN OR HAIKU OR RISCOS OR OHOS))
if(NOT (HAVE_X11 OR HAVE_WAYLAND))
if(NOT SDL_UNIX_CONSOLE_BUILD)
message(FATAL_ERROR
Expand Down
2 changes: 1 addition & 1 deletion cmake/sdlchecks.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ macro(CheckPTHREAD)
if(ANDROID OR SDL_PTHREADS_PRIVATE)
# the android libc provides built-in support for pthreads, so no
# additional linking or compile flags are necessary
elseif(LINUX)
elseif(LINUX OR OHOS)
set(PTHREAD_CFLAGS "-D_REENTRANT")
set(PTHREAD_LDFLAGS "-pthread")
elseif(BSDI)
Expand Down
28 changes: 28 additions & 0 deletions docs/README-ohos.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
OpenHarmony / HarmonyOS
================================================================================

Requirements
================================================================================

DevEco Studio 5.0.0 or later
https://developer.huawei.com/consumer/en/download

Harmony OS Development Toolchain 5.0.0 (API 12) or later (Bundled in the DevEco Studio)


How the port works
================================================================================

- OpenHarmony / Harmony OS apps are based on ArkTS/JS running on the Ark JS runtime, optionally with parts written in C
- We can use the napi and ndk provided by the Harmony SDK to fetch the app window, context and so on. We wrote a simple Harmony shell for SDL, simpily initialize the basic application and the context for SDL library, then runs your app in another thread. (Harmony JS apps only contains one thread, if we runs your app main loop directly in JS, the whole app just freezes)
- This produces a .hap or .app package which can be installed in OpenHarmony and HarmonyOS Emulators (you will need to apply for a certificate to sign the app before testing it on a real HarmonyOS machine)


Building the example app and test it (HarmonyOS Emulator)
================================================================================

Download the DevEco Studio, and open the ohos-project folder in this repo

Then, download a emulator in the Device Manager tab, and runs it.

Click the run button, the IDE will automatically build the app and run it for you, you can act with your app in the emulator window.
5 changes: 5 additions & 0 deletions include/SDL3/SDL_platform_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@
#undef SDL_PLATFORM_LINUX
#endif

#if defined(OHOS) || defined(__OHOS__)
#define SDL_PLATFORM_OHOS 1
#undef SDL_PLATFORM_LINUX
#endif

#if defined(__unix__) || defined(__unix) || defined(unix)

/**
Expand Down
2 changes: 2 additions & 0 deletions include/build_config/SDL_build_config.h.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@
#cmakedefine SDL_AUDIO_DRIVER_JACK 1
#cmakedefine SDL_AUDIO_DRIVER_JACK_DYNAMIC @SDL_AUDIO_DRIVER_JACK_DYNAMIC@
#cmakedefine SDL_AUDIO_DRIVER_NETBSD 1
#cmakedefine SDL_VIDEO_DRIVER_OHOS 1
#cmakedefine SDL_AUDIO_DRIVER_OSS 1
#cmakedefine SDL_AUDIO_DRIVER_PIPEWIRE 1
#cmakedefine SDL_AUDIO_DRIVER_PIPEWIRE_DYNAMIC @SDL_AUDIO_DRIVER_PIPEWIRE_DYNAMIC@
Expand Down Expand Up @@ -397,6 +398,7 @@
#cmakedefine SDL_VIDEO_DRIVER_N3DS 1
#cmakedefine SDL_VIDEO_DRIVER_NGAGE 1
#cmakedefine SDL_VIDEO_DRIVER_OFFSCREEN 1
#cmakedefine SDL_VIDEO_DRIVER_OHOS 1
#cmakedefine SDL_VIDEO_DRIVER_PS2 1
#cmakedefine SDL_VIDEO_DRIVER_PSP 1
#cmakedefine SDL_VIDEO_DRIVER_RISCOS 1
Expand Down
12 changes: 12 additions & 0 deletions ohos-project/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/node_modules
/oh_modules
/local.properties
/.idea
**/build
/.hvigor
.cxx
/.clangd
/.clang-format
/.clang-tidy
**/.test
/.appanalyzer
10 changes: 10 additions & 0 deletions ohos-project/AppScope/app.json5
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"app": {
"bundleName": "com.cpp.app",
"vendor": "example",
"versionCode": 1000000,
"versionName": "1.0.0",
"icon": "$media:layered_image",
"label": "$string:app_name"
}
}
8 changes: 8 additions & 0 deletions ohos-project/AppScope/resources/base/element/string.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"string": [
{
"name": "app_name",
"value": "MyApplication"
}
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions ohos-project/AppScope/resources/base/media/layered_image.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"layered-image":
{
"background" : "$media:background",
"foreground" : "$media:foreground"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 42 additions & 0 deletions ohos-project/build-profile.json5
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"app": {
"signingConfigs": [],
"products": [
{
"name": "default",
"signingConfig": "default",
"targetSdkVersion": "5.0.1(13)",
"compatibleSdkVersion": "5.0.1(13)",
"runtimeOS": "HarmonyOS",
"buildOption": {
"strictMode": {
"caseSensitiveCheck": true,
"useNormalizedOHMUrl": true
}
}
}
],
"buildModeSet": [
{
"name": "debug",
},
{
"name": "release"
}
]
},
"modules": [
{
"name": "entry",
"srcPath": "./entry",
"targets": [
{
"name": "default",
"applyToProducts": [
"default"
]
}
]
}
]
}
32 changes: 32 additions & 0 deletions ohos-project/code-linter.json5
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"files": [
"**/*.ets"
],
"ignore": [
"**/src/ohosTest/**/*",
"**/src/test/**/*",
"**/src/mock/**/*",
"**/node_modules/**/*",
"**/oh_modules/**/*",
"**/build/**/*",
"**/.preview/**/*"
],
"ruleSet": [
"plugin:@performance/recommended",
"plugin:@typescript-eslint/recommended"
],
"rules": {
"@security/no-unsafe-aes": "error",
"@security/no-unsafe-hash": "error",
"@security/no-unsafe-mac": "warn",
"@security/no-unsafe-dh": "error",
"@security/no-unsafe-dsa": "error",
"@security/no-unsafe-ecdsa": "error",
"@security/no-unsafe-rsa-encrypt": "error",
"@security/no-unsafe-rsa-sign": "error",
"@security/no-unsafe-rsa-key": "error",
"@security/no-unsafe-dsa-key": "error",
"@security/no-unsafe-dh-key": "error",
"@security/no-unsafe-3des": "error"
}
}
6 changes: 6 additions & 0 deletions ohos-project/entry/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/node_modules
/oh_modules
/.preview
/build
/.cxx
/.test
44 changes: 44 additions & 0 deletions ohos-project/entry/build-profile.json5
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"apiType": "stageMode",
"buildOption": {
"externalNativeOptions": {
"path": "./src/main/cpp/CMakeLists.txt",
"arguments": "-DCMAKE_PLATFORM_NO_VERSIONED_SONAME=1",
"cppFlags": "",
"abiFilters": [
"arm64-v8a",
"x86_64"
]
},

},
"buildOptionSet": [
{
"name": "release",
"arkOptions": {
"obfuscation": {
"ruleOptions": {
"enable": false,
"files": [
"./obfuscation-rules.txt"
]
}
}
},
"nativeLib": {
"debugSymbol": {
"strip": true,
"exclude": []
}
}
},
],
"targets": [
{
"name": "default"
},
{
"name": "ohosTest",
}
]
}
6 changes: 6 additions & 0 deletions ohos-project/entry/hvigorfile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { hapTasks } from '@ohos/hvigor-ohos-plugin';

export default {
system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */
plugins:[] /* Custom plugin to extend the functionality of Hvigor. */
}
Loading
Loading