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 42 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 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
Starcloudsea 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
Starcloudsea Jun 2, 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
90 changes: 51 additions & 39 deletions .github/workflows/create-test-plan.py

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion .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 Expand Up @@ -233,7 +236,7 @@ jobs:
${{ matrix.platform.source-cmd }}
cmake --build build --config ${{ matrix.platform.cmake-build-type }} --verbose -- ${{ matrix.platform.cmake-build-arguments }}
- name: 'Verify SDL_REVISION'
if: ${{ !matrix.platform.no-cmake }}
if: ${{ !matrix.platform.no-cmake && matrix.platform.platform != 'harmony' }}
run: |
echo "This should show us the SDL_REVISION"
echo "Shared library:"
Expand Down
43 changes: 43 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1502,7 +1502,48 @@ if(ANDROID)
endif()
endif()
endif()
elseif(OHOS)
# disable warnings from the toolchain
sdl_compile_options(PRIVATE "-Wno-unused-command-line-argument")

set(CMAKE_C_COMPILER_EXTERNAL_TOOLCHAIN "")
set(CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN "")

sdl_link_dependency(OHOS_LIBS 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(SDL_VULKAN ON)
set(HAVE_VULKAN ON)
set(SDL_VIDEO_VULKAN ON)
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)

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 Expand Up @@ -3532,6 +3573,8 @@ if(SDL_SHARED)
RESOURCE "${SDL_FRAMEWORK_RESOURCES}"
)
endif()
elseif(OHOS)
# disable libtool postfix
elseif(UNIX AND NOT ANDROID)
set_target_properties(SDL3-shared PROPERTIES
VERSION "${SDL_SO_VERSION}"
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
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 @@ -265,6 +265,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 @@ -391,6 +392,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
28 changes: 26 additions & 2 deletions src/SDL_log.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
#include <android/log.h>
#endif

#ifdef SDL_PLATFORM_OHOS
#include <hilog/log.h>
#endif

#include "stdlib/SDL_vacopy.h"

// The size of the stack buffer to use for rendering log messages.
Expand Down Expand Up @@ -120,6 +124,19 @@ static int SDL_android_priority[] = {
SDL_COMPILE_TIME_ASSERT(android_priority, SDL_arraysize(SDL_android_priority) == SDL_LOG_PRIORITY_COUNT);
#endif // SDL_PLATFORM_ANDROID

#ifdef SDL_PLATFORM_OHOS
static int SDL_ohos_priority[] = {
LOG_DEBUG,
LOG_DEBUG,
LOG_DEBUG,
LOG_DEBUG,
LOG_INFO,
LOG_WARN,
LOG_ERROR,
LOG_FATAL
};
#endif

static void SDLCALL SDL_LoggingChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
{
SDL_ResetLogPriorities();
Expand Down Expand Up @@ -556,7 +573,7 @@ void SDL_LogMessage(int category, SDL_LogPriority priority, SDL_PRINTF_FORMAT_ST
va_end(ap);
}

#ifdef SDL_PLATFORM_ANDROID
#if defined(SDL_PLATFORM_ANDROID) || defined(SDL_PLATFORM_OHOS)
static const char *GetCategoryPrefix(int category)
{
if (category < SDL_LOG_CATEGORY_RESERVED2) {
Expand All @@ -567,7 +584,7 @@ static const char *GetCategoryPrefix(int category)
}
return "CUSTOM";
}
#endif // SDL_PLATFORM_ANDROID
#endif

void SDL_LogMessageV(int category, SDL_LogPriority priority, SDL_PRINTF_FORMAT_STRING const char *fmt, va_list ap)
{
Expand Down Expand Up @@ -751,6 +768,13 @@ static void SDLCALL SDL_LogOutput(void *userdata, int category, SDL_LogPriority
SDL_snprintf(tag, SDL_arraysize(tag), "SDL/%s", GetCategoryPrefix(category));
__android_log_write(SDL_android_priority[priority], tag, message);
}
#elif defined(SDL_PLATFORM_OHOS)
{
char tag[32];

SDL_snprintf(tag, SDL_arraysize(tag), "SDL/%s", GetCategoryPrefix(category));
OH_LOG_Print(LOG_APP, SDL_ohos_priority[priority], 0, tag, "%{public}s", message);
}
#elif defined(SDL_PLATFORM_APPLE) && (defined(SDL_VIDEO_DRIVER_COCOA) || defined(SDL_VIDEO_DRIVER_UIKIT))
/* Technically we don't need Cocoa/UIKit, but that's where this function is defined for now.
*/
Expand Down
4 changes: 4 additions & 0 deletions src/audio/SDL_audiotypecvt.c
Original file line number Diff line number Diff line change
Expand Up @@ -536,9 +536,11 @@ static void SDL_TARGETING("ssse3") SDL_Convert_Swap32_SSSE3(Uint32* dst, const U
// be guarded by the STDC FENV_ACCESS pragma; otherwise, it's undefined
// behavior. However, the compiler support for this pragma is bad.
#if defined(__clang__)
#ifndef SDL_PLATFORM_OHOS
#if __clang_major__ >= 12
#pragma STDC FENV_ACCESS ON
#endif
#endif
#elif defined(_MSC_VER)
#pragma fenv_access (on)
#elif defined(__GNUC__)
Expand Down Expand Up @@ -813,9 +815,11 @@ static void SDL_Convert_Swap32_NEON(Uint32* dst, const Uint32* src, int num_samp
}

#if defined(__clang__)
#ifndef SDL_PLATFORM_OHOS
#if __clang_major__ >= 12
#pragma STDC FENV_ACCESS DEFAULT
#endif
#endif
#elif defined(_MSC_VER)
#pragma fenv_access (off)
#elif defined(__GNUC__)
Expand Down
Loading