Skip to content

Commit 435caa7

Browse files
committed
增加编译参数 --os openharmony
1 parent dc4d2cb commit 435caa7

16 files changed

+105
-36
lines changed

Directory.Build.props

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,8 @@
211211
<!-- Detect linux flavors using __PortableTargetOS from the native script. -->
212212
<_portableOS Condition="'$(_portableOS)' == 'linux' and '$(__PortableTargetOS)' == 'linux-musl'">linux-musl</_portableOS>
213213
<_portableOS Condition="'$(_portableOS)' == 'linux' and '$(__PortableTargetOS)' == 'linux-bionic'">linux-bionic</_portableOS>
214+
215+
<_portableOS Condition="'$(_portableOS)' == 'openharmony'">linux-musl</_portableOS>
214216

215217
<!-- On Windows, we can build for Windows and Mobile.
216218
For other TargetOSes, create a "win" build, built from TargetOS sources and "win" pre-built packages. -->
@@ -272,7 +274,7 @@
272274
<Targetsillumos Condition="'$(TargetOS)' == 'illumos'">true</Targetsillumos>
273275
<TargetsSolaris Condition="'$(TargetOS)' == 'solaris'">true</TargetsSolaris>
274276
<TargetsHaiku Condition="'$(TargetOS)' == 'haiku'">true</TargetsHaiku>
275-
<TargetsLinux Condition="'$(TargetOS)' == 'linux' or '$(TargetOS)' == 'android'">true</TargetsLinux>
277+
<TargetsLinux Condition="'$(TargetOS)' == 'linux' or '$(TargetOS)' == 'android' or '$(TargetOS)' == 'openharmony'">true</TargetsLinux>
276278
<TargetsLinuxBionic Condition="'$(_portableOS)' == 'linux-bionic'">true</TargetsLinuxBionic>
277279
<TargetsLinuxMusl Condition="'$(_portableOS)' == 'linux-musl'">true</TargetsLinuxMusl>
278280
<TargetsNetBSD Condition="'$(TargetOS)' == 'netbsd'">true</TargetsNetBSD>
@@ -283,10 +285,11 @@
283285
<TargetsiOSSimulator Condition="'$(TargetOS)' == 'iossimulator'">true</TargetsiOSSimulator>
284286
<TargetstvOSSimulator Condition="'$(TargetOS)' == 'tvossimulator'">true</TargetstvOSSimulator>
285287
<TargetsAndroid Condition="'$(TargetOS)' == 'android'">true</TargetsAndroid>
288+
<TargetsOpenHarmony Condition="'$(TargetOS)' == 'openharmony'">true</TargetsOpenHarmony>
286289
<TargetsBrowser Condition="'$(TargetOS)' == 'browser'">true</TargetsBrowser>
287290
<TargetsWasi Condition="'$(TargetOS)' == 'wasi'">true</TargetsWasi>
288291
<TargetsWindows Condition="'$(TargetOS)' == 'windows'">true</TargetsWindows>
289-
<TargetsUnix Condition="'$(TargetsFreeBSD)' == 'true' or '$(Targetsillumos)' == 'true' or '$(TargetsSolaris)' == 'true' or '$(TargetsHaiku)' == 'true' or '$(TargetsLinux)' == 'true' or '$(TargetsNetBSD)' == 'true' or '$(TargetsOSX)' == 'true' or '$(TargetsMacCatalyst)' == 'true' or '$(TargetstvOS)' == 'true' or '$(TargetsiOS)' == 'true' or '$(TargetsAndroid)' == 'true'">true</TargetsUnix>
292+
<TargetsUnix Condition="'$(TargetsFreeBSD)' == 'true' or '$(Targetsillumos)' == 'true' or '$(TargetsSolaris)' == 'true' or '$(TargetsHaiku)' == 'true' or '$(TargetsLinux)' == 'true' or '$(TargetsNetBSD)' == 'true' or '$(TargetsOSX)' == 'true' or '$(TargetsMacCatalyst)' == 'true' or '$(TargetstvOS)' == 'true' or '$(TargetsiOS)' == 'true' or '$(TargetsAndroid)' == 'true' or '$(TargetsOpenHarmony)' == 'true'">true</TargetsUnix>
290293
</PropertyGroup>
291294

292295
<PropertyGroup>

build-openharmony-arm.sh

Lines changed: 0 additions & 12 deletions
This file was deleted.

build-openharmony-arm64.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ docker run --rm \
44
-w /runtime \
55
-e ROOTFS_DIR="/crossrootfs/arm64" \
66
mcr.microsoft.com/dotnet-buildtools/prereqs:azurelinux-3.0-net9.0-cross-arm64-musl \
7-
bash -c "./build.sh --subset clr.aot+libs --configuration Release -arch arm64 --cross \
7+
bash -c "./build.sh --subset clr.aot+libs --configuration Release -arch arm64 --cross --os openharmony\
88
&& mkdir -p ./artifacts/openharmony/arm64/sdk/ \
99
&& mkdir -p ./artifacts/openharmony/arm64/framework/ \
10-
&& cp -p ./artifacts/bin/coreclr/linux.arm64.Release/aotsdk/* ./artifacts/openharmony/arm64/sdk/ \
11-
&& cp -p ./artifacts/bin/runtime/net9.0-linux-Release-arm64/*.a ./artifacts/openharmony/arm64/framework/ \
12-
&& cp -p ./artifacts/bin/runtime/net9.0-linux-Release-arm64/*.dbg ./artifacts/openharmony/arm64/framework/"
10+
&& cp -p ./artifacts/bin/coreclr/openharmony.arm64.Release/aotsdk/* ./artifacts/openharmony/arm64/sdk/ \
11+
&& cp -p ./artifacts/bin/runtime/net9.0-openharmony-Release-arm64/*.a ./artifacts/openharmony/arm64/framework/ \
12+
&& cp -p ./artifacts/bin/runtime/net9.0-openharmony-Release-arm64/*.dbg ./artifacts/openharmony/arm64/framework/"

build-openharmony-x64.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ docker run --rm \
44
-w /runtime \
55
-e ROOTFS_DIR="/crossrootfs/x64" \
66
mcr.microsoft.com/dotnet-buildtools/prereqs:azurelinux-3.0-net9.0-cross-amd64-musl \
7-
bash -c "./build.sh --subset clr.aot+libs --configuration Release -arch x64 --cross \
7+
bash -c "./build.sh --subset clr.aot+libs --configuration Release -arch x64 --cross --os openharmony\
88
&& mkdir -p ./artifacts/openharmony/x64/sdk/ \
99
&& mkdir -p ./artifacts/openharmony/x64/framework/ \
10-
&& cp -p ./artifacts/bin/coreclr/linux.x64.Release/aotsdk/* ./artifacts/openharmony/x64/sdk/ \
11-
&& cp -p ./artifacts/bin/runtime/net9.0-linux-Release-x64/*.a ./artifacts/openharmony/x64/framework/ \
12-
&& cp -p ./artifacts/bin/runtime/net9.0-linux-Release-x64/*.dbg ./artifacts/openharmony/x64/framework/"
10+
&& cp -p ./artifacts/bin/coreclr/openharmony.x64.Release/aotsdk/* ./artifacts/openharmony/x64/sdk/ \
11+
&& cp -p ./artifacts/bin/runtime/net9.0-openharmony-Release-x64/*.a ./artifacts/openharmony/x64/framework/ \
12+
&& cp -p ./artifacts/bin/runtime/net9.0-openharmony-Release-x64/*.dbg ./artifacts/openharmony/x64/framework/"

eng/Subsets.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@
119119

120120
<PropertyGroup>
121121
<!-- CLR NativeAot only builds in a subset of the matrix -->
122-
<_NativeAotSupportedOS Condition="'$(TargetOS)' == 'windows' or '$(TargetOS)' == 'linux' or '$(TargetOS)' == 'osx' or '$(TargetOS)' == 'maccatalyst' or '$(TargetOS)' == 'iossimulator' or '$(TargetOS)' == 'ios' or '$(TargetOS)' == 'tvossimulator' or '$(TargetOS)' == 'tvos' or '$(TargetOS)' == 'freebsd'">true</_NativeAotSupportedOS>
122+
<_NativeAotSupportedOS Condition="'$(TargetOS)' == 'windows' or '$(TargetOS)' == 'linux' or '$(TargetOS)' == 'osx' or '$(TargetOS)' == 'maccatalyst' or '$(TargetOS)' == 'iossimulator' or '$(TargetOS)' == 'ios' or '$(TargetOS)' == 'tvossimulator' or '$(TargetOS)' == 'tvos' or '$(TargetOS)' == 'freebsd' or '$(TargetOS)' == 'openharmony'">true</_NativeAotSupportedOS>
123123
<_NativeAotSupportedArch Condition="'$(TargetArchitecture)' == 'x64' or '$(TargetArchitecture)' == 'arm64' or '$(TargetArchitecture)' == 'arm' or '$(TargetArchitecture)' == 'loongarch64' or ('$(TargetOS)' == 'windows' and '$(TargetArchitecture)' == 'x86')">true</_NativeAotSupportedArch>
124124
<NativeAotSupported Condition="'$(_NativeAotSupportedOS)' == 'true' and '$(_NativeAotSupportedArch)' == 'true'">true</NativeAotSupported>
125125
<UseNativeAotForComponents Condition="'$(NativeAotSupported)' == 'true' and '$(TargetOS)' == '$(HostOS)' and '$(TargetsLinuxBionic)' != 'true' and ('$(TargetsLinuxMusl)' != 'true' or '$(TargetArchitecture)' != 'arm')">true</UseNativeAotForComponents>

eng/build.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,10 @@ while [[ $# > 0 ]]; do
298298
;;
299299
haiku)
300300
os="haiku" ;;
301+
openharmony)
302+
os="openharmony"
303+
__PortableTargetOS=linux-musl
304+
;;
301305
*)
302306
echo "Unsupported target OS '$2'."
303307
echo "Try 'build.sh --help' for values supported by '--os'."

eng/native/configurecompiler.cmake

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -722,8 +722,9 @@ if(CLR_CMAKE_TARGET_UNIX)
722722
add_compile_definitions($<$<NOT:$<BOOL:$<TARGET_PROPERTY:IGNORE_DEFAULT_TARGET_OS>>>:TARGET_LINUX>)
723723
if(CLR_CMAKE_TARGET_LINUX_MUSL)
724724
add_compile_definitions($<$<NOT:$<BOOL:$<TARGET_PROPERTY:IGNORE_DEFAULT_TARGET_OS>>>:TARGET_LINUX_MUSL>)
725-
# 为OpenHarmony平台做的临时修改
726-
add_compile_definitions($<$<NOT:$<BOOL:$<TARGET_PROPERTY:IGNORE_DEFAULT_TARGET_OS>>>:TARGET_OPENHARMONY>)
725+
endif()
726+
if (CLR_CMAKE_TARGET_OPENHARMONY)
727+
add_compile_definitions($<$<NOT:$<BOOL:$<TARGET_PROPERTY:IGNORE_DEFAULT_TARGET_OS>>>:TARGET_OPENHARMONY>)
727728
endif()
728729
elseif(CLR_CMAKE_TARGET_NETBSD)
729730
add_compile_definitions($<$<NOT:$<BOOL:$<TARGET_PROPERTY:IGNORE_DEFAULT_TARGET_OS>>>:TARGET_NETBSD>)

eng/native/configureplatform.cmake

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ set(PRERELEASE 0)
99
# - for non-windows build platform & architecture is detected using inbuilt CMAKE variables and cross target component configure
1010
# - for windows we use the passed in parameter to CMAKE to determine build arch
1111
#----------------------------------------
12+
13+
message("CLR_CMAKE_TARGET_OS${CLR_CMAKE_TARGET_OS}")
14+
1215
set(CLR_CMAKE_HOST_OS ${CMAKE_SYSTEM_NAME})
1316
string(TOLOWER ${CLR_CMAKE_HOST_OS} CLR_CMAKE_HOST_OS)
1417
if(CLR_CMAKE_HOST_OS STREQUAL linux)
@@ -230,6 +233,13 @@ if(CLR_CMAKE_TARGET_OS STREQUAL wasi)
230233
set(CLR_CMAKE_HOST_WASI 1)
231234
endif(CLR_CMAKE_TARGET_OS STREQUAL wasi)
232235

236+
if(CLR_CMAKE_TARGET_OS STREQUAL openharmony)
237+
set(CLR_CMAKE_TARGET_UNIX 1)
238+
set(CLR_CMAKE_TARGET_LINUX 1)
239+
set(CLR_CMAKE_TARGET_LINUX_MUSL 1)
240+
set(CLR_CMAKE_TARGET_OPENHARMONY 1)
241+
endif(CLR_CMAKE_TARGET_OS STREQUAL openharmony)
242+
233243
#--------------------------------------------
234244
# This repo builds two set of binaries
235245
# 1. binaries which execute on target arch machine
@@ -471,7 +481,7 @@ if(CLR_CMAKE_TARGET_OS STREQUAL windows)
471481
endif()
472482

473483
# check if host & target os/arch combination are valid
474-
if (NOT (CLR_CMAKE_TARGET_OS STREQUAL CLR_CMAKE_HOST_OS) AND NOT CLR_CMAKE_TARGET_WASI)
484+
if (NOT (CLR_CMAKE_TARGET_OS STREQUAL CLR_CMAKE_HOST_OS) AND NOT CLR_CMAKE_TARGET_WASI AND NOT CLR_CMAKE_TARGET_OPENHARMONY)
475485
if(NOT (CLR_CMAKE_HOST_OS STREQUAL windows))
476486
message(FATAL_ERROR "Invalid host and target os/arch combination. Host OS: ${CLR_CMAKE_HOST_OS}")
477487
endif()

eng/native/gen-buildsys.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ if [[ "$host_arch" == "wasm" ]]; then
106106
fi
107107
fi
108108

109+
if [[ "$target_os" == "openharmony" ]]; then
110+
echo "openharmony"
111+
cmake_extra_defines="$cmake_extra_defines -DCLR_CMAKE_TARGET_OS=openharmony"
112+
fi
113+
114+
DCMAKE_TOOLCHAIN_FILE
109115
$cmake_command \
110116
--no-warn-unused-cli \
111117
-G "$generator" \

src/coreclr/gc/unix/numasupport.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ static int GetNodeNum(const char* path, bool firstOnly)
5454
void NUMASupportInitialize()
5555
{
5656
#if defined(TARGET_LINUX) && !defined(TARGET_OPENHARMONY)
57-
111
5857
if (syscall(__NR_get_mempolicy, NULL, NULL, 0, 0, 0) < 0 && errno == ENOSYS)
5958
return;
6059

src/coreclr/nativeaot/Runtime/Full/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ project(Runtime)
66
# Include auto-generated files on include path
77
set(CMAKE_INCLUDE_CURRENT_DIR ON)
88

9-
if (CLR_CMAKE_TARGET_APPLE OR CLR_CMAKE_TARGET_LINUX_MUSL)
9+
if (CLR_CMAKE_TARGET_APPLE OR CLR_CMAKE_TARGET_OPENHARMONY)
1010
list(APPEND RUNTIME_SOURCES_ARCH_ASM
1111
${ARCH_SOURCES_DIR}/ThunkPoolThunks.${ASM_SUFFIX}
1212
)

src/coreclr/nativeaot/Runtime/ThunksMapping.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ EXTERN_C void* QCALLTYPE RhAllocateThunksMapping()
359359
int thunkBlockSize = RhpGetThunkBlockSize();
360360
int templateSize = thunkBlocksPerMapping * thunkBlockSize;
361361

362-
#ifndef TARGET_APPLE || TARGET_LINUX // Apple platforms cannot use the initial template
362+
#ifndef TARGET_APPLE || TARGET_OPENHARMONY // Apple platforms cannot use the initial template
363363
if (pThunksTemplateAddress == NULL)
364364
{
365365
// First, we use the thunks directly from the thunks template sections in the module until all
@@ -377,9 +377,8 @@ EXTERN_C void* QCALLTYPE RhAllocateThunksMapping()
377377
uint8_t* pModuleBase = (uint8_t*)PalGetModuleHandleFromPointer(RhpGetThunksBase());
378378
int templateRva = (int)((uint8_t*)RhpGetThunksBase() - pModuleBase);
379379

380-
if (!PalAllocateThunksFromTemplate((HANDLE)pModuleBase, templateRva, templateSize, &pThunkMap)){
380+
if (!PalAllocateThunksFromTemplate((HANDLE)pModuleBase, templateRva, templateSize, &pThunkMap))
381381
return NULL;
382-
}
383382
}
384383

385384
if (!PalMarkThunksAsValidCallTargets(

src/coreclr/nativeaot/Runtime/arm64/ThunkPoolThunks.S

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,26 @@
1212

1313
#define THUNKS_MAP_SIZE 0x8000
1414

15-
#ifdef TARGET_LINUX
15+
#ifdef TARGET_APPLE
16+
#define PAGE_SIZE 0x4000
17+
#define PAGE_SIZE_LOG2 14
18+
#elif TARGET_OPENHARMONY
1619
#define PAGE_SIZE 0x1000
1720
#define PAGE_SIZE_LOG2 12
1821
#else
1922
#error Unsupported OS
2023
#endif
2124

2225
// THUNK_POOL_NUM_THUNKS_PER_PAGE = min(PAGE_SIZE / THUNK_CODESIZE, (PAGE_SIZE - POINTER_SIZE) / THUNK_DATASIZE)
26+
#ifdef TARGET_APPLE
27+
#define THUNK_POOL_NUM_THUNKS_PER_PAGE 0x3ff
28+
#elif TARGET_OPENHARMONY
2329
#define THUNK_POOL_NUM_THUNKS_PER_PAGE 0xFF
30+
#else
31+
#error Unsupported OS
32+
#endif
2433

25-
#ifdef TARGET_LINUX
34+
//;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Thunk Pages ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2635

2736
.macro THUNKS_PAGE_BLOCK
2837
IN_PAGE_INDEX = 0
@@ -45,6 +54,17 @@
4554
.endr
4655
.endm
4756

57+
#ifdef TARGET_APPLE
58+
// Thunk pool
59+
.text
60+
.p2align PAGE_SIZE_LOG2
61+
PATCH_LABEL ThunkPool
62+
.rept (THUNKS_MAP_SIZE / PAGE_SIZE)
63+
.p2align PAGE_SIZE_LOG2
64+
THUNKS_PAGE_BLOCK
65+
.endr
66+
.p2align PAGE_SIZE_LOG2
67+
#elif TARGET_OPENHARMONY
4868
// Thunk pool
4969
.section .thunks ,"ax"
5070
.p2align PAGE_SIZE_LOG2
@@ -67,8 +87,13 @@ PATCH_LABEL ThunkPool
6787
//
6888
LEAF_ENTRY RhpGetThunksBase
6989
// Return the address of the first thunk pool to the caller (this is really the base address)
90+
#ifdef TARGET_APPLE
91+
adrp x0, C_FUNC(ThunkPool)@PAGE
92+
add x0, x0, C_FUNC(ThunkPool)@PAGEOFF
93+
#elif TARGET_OPENHARMONY
7094
adrp x0, C_FUNC(ThunkPool)
7195
add x0, x0, #:lo12:C_FUNC(ThunkPool)
96+
#endif
7297
ret
7398
LEAF_END RhpGetThunksBase
7499

src/coreclr/nativeaot/Runtime/unix/PalRedhawkUnix.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757

5858
#ifdef TARGET_APPLE
5959
#include <mach/mach.h>
60-
#elif defined(TARGET_LINUX)
60+
#elif defined(TARGET_OPENHARMONY)
6161
#include <unistd.h>
6262
#include <sys/mman.h>
6363
#include <string.h>
@@ -572,7 +572,7 @@ REDHAWK_PALEXPORT UInt32_BOOL REDHAWK_PALAPI PalAllocateThunksFromTemplate(HANDL
572572
*newThunksOut = (void*)addr;
573573

574574
return UInt32_TRUE;
575-
#elif defined(TARGET_LINUX)
575+
#elif defined(TARGET_OPENHARMONY)
576576
if (templateSize == 0)
577577
{
578578
return UInt32_FALSE;
@@ -627,7 +627,7 @@ REDHAWK_PALEXPORT UInt32_BOOL REDHAWK_PALAPI PalFreeThunksFromTemplate(void *pBa
627627
} while (ret == KERN_ABORTED);
628628

629629
return ret == KERN_SUCCESS ? UInt32_TRUE : UInt32_FALSE;
630-
#elif defined(TARGET_LINUX)
630+
#elif defined(TARGET_OPENHARMONY)
631631
if (pBaseAddress == NULL || templateSize == 0) {
632632
return UInt32_FALSE;
633633
}

src/libraries/Microsoft.NETCore.Platforms/src/PortableRuntimeIdentifierGraph.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,23 @@
476476
"#import": [
477477
"win"
478478
]
479+
},
480+
"openharmony": {
481+
"#import": [
482+
"linux-musl"
483+
]
484+
},
485+
"openharmony-arm64": {
486+
"#import": [
487+
"openharmony",
488+
"linux-musl-arm64"
489+
]
490+
},
491+
"openharmony-x64": {
492+
"#import": [
493+
"openharmony",
494+
"linux-musl-x64"
495+
]
479496
}
480497
}
481498
}

src/libraries/Microsoft.NETCore.Platforms/src/runtime.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4624,6 +4624,23 @@
46244624
"win81",
46254625
"win8-x86-aot"
46264626
]
4627+
},
4628+
"openharmony": {
4629+
"#import": [
4630+
"linux-musl"
4631+
]
4632+
},
4633+
"openharmony-arm64": {
4634+
"#import": [
4635+
"openharmony",
4636+
"linux-musl-arm64"
4637+
]
4638+
},
4639+
"openharmony-x64": {
4640+
"#import": [
4641+
"openharmony",
4642+
"linux-musl-x64"
4643+
]
46274644
}
46284645
}
46294646
}

0 commit comments

Comments
 (0)