Skip to content

Commit dfae36e

Browse files
authored
Fix OHOS define (#666)
* Fix OHOS define Signed-off-by: Jonathan Schwender <[email protected]> * Fix indentation Signed-off-by: Jonathan Schwender <[email protected]> * Avoid name collision by not importing header Assertions .h is also included in `c` files, so using namespaces is not an option to avoid the collision. js::LogLevel, collides with the hilog LogLevel enum. Signed-off-by: Jonathan Schwender <[email protected]> * Fix vprintf impl Signed-off-by: Jonathan Schwender <[email protected]> * Update patches Signed-off-by: Jonathan Schwender <[email protected]> * Bump mozjs version Signed-off-by: Jonathan Schwender <[email protected]> * Completely inline function declaration Signed-off-by: Jonathan Schwender <[email protected]> * ohos: Add debug-mozjs ci configuration Signed-off-by: Jonathan Schwender <[email protected]> --------- Signed-off-by: Jonathan Schwender <[email protected]>
1 parent 36e3c01 commit dfae36e

File tree

10 files changed

+121
-82
lines changed

10 files changed

+121
-82
lines changed

.github/workflows/build.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ jobs:
227227
strategy:
228228
matrix:
229229
target: ["aarch64-unknown-linux-ohos", "x86_64-unknown-linux-ohos"]
230+
features: [ "", "--features debugmozjs"]
230231
steps:
231232
- uses: actions/checkout@v4
232233
- name: Setup OpenHarmony SDK
@@ -245,15 +246,15 @@ jobs:
245246
env:
246247
OHOS_SDK_NATIVE: ${{ steps.setup_sdk.outputs.ohos_sdk_native }}
247248
run: |
248-
./ohos-build cargo +${{ steps.toolchain.outputs.name }} build --target="${{ matrix.target }}"
249+
./ohos-build cargo +${{ steps.toolchain.outputs.name }} build --target="${{ matrix.target }}" ${{ matrix.features }}
249250
- name: Generate artifact attestation
250251
uses: actions/attest-build-provenance@v1
251-
if: ${{ inputs.release }}
252+
if: ${{ inputs.release && matrix.features == '' }}
252253
with:
253254
subject-path: "./target/libmozjs-${{ matrix.target }}.tar.gz"
254255
- name: Upload artifact
255256
uses: actions/upload-artifact@v4
256-
if: ${{ env.NEW_RUST_CHECK == 'false' }}
257+
if: ${{ env.NEW_RUST_CHECK == 'false' && matrix.features == '' }}
257258
with:
258259
path: ./target/libmozjs-${{ matrix.target }}.tar.gz
259260
name: libmozjs-${{ matrix.target }}.tar.gz

mozjs-sys/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "mozjs_sys"
33
description = "System crate for the Mozilla SpiderMonkey JavaScript engine."
44
repository.workspace = true
5-
version = "0.140.5-3"
5+
version = "0.140.5-4"
66
authors = ["Mozilla", "The Servo Project Developers"]
77
links = "mozjs"
88
license.workspace = true

mozjs-sys/etc/patches/0034-build__Add_compile_definition_for_ohos.patch

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
diff --git a/build/moz.configure/init.configure b/build/moz.configure/init.configure
22
--- a/build/moz.configure/init.configure (revision dbffebd0937c14d3c73ce9be4798da15cb2f369d)
33
+++ b/build/moz.configure/init.configure (revision 8a1dbb7da45148151dbb0d05d969118103cfa8d0)
4-
@@ -950,6 +950,14 @@
4+
@@ -950,6 +950,16 @@
55
set_define("ANDROID", target_is_android)
66

77

88
+@depends(target)
99
+def target_is_ohos(target):
10-
+ return target.raw_os.endswith("-ohos")
10+
+ if target.raw_os.endswith("-ohos"):
11+
+ return True
12+
+ return None
1113
+
1214
+
1315
+set_define("XP_OHOS", target_is_ohos)

mozjs-sys/etc/patches/0036-Redirect_errors_to_hilog_on_OpenHarmony.patch

Lines changed: 59 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,15 @@ diff --git a/memory/mozalloc/mozalloc_abort.cpp b/memory/mozalloc/mozalloc_abort
3030
index 3cfc92533..9c487ac45 100644
3131
--- a/memory/mozalloc/mozalloc_abort.cpp
3232
+++ b/memory/mozalloc/mozalloc_abort.cpp
33-
@@ -9,6 +9,8 @@
33+
@@ -9,6 +9,11 @@
3434

3535
#ifdef ANDROID
3636
# include <android/log.h>
37-
+#elif defined(OHOS)
38-
+# include <hilog/log.h>
37+
+#elif defined(XP_OHOS)
38+
+ extern "C" {
39+
+ int OH_LOG_Print(unsigned int type, unsigned int level, unsigned int domain, const char *tag, const char *fmt, ...)
40+
+ __attribute__((__format__(os_log, 5, 6)));
41+
+ }
3942
#endif
4043
#ifdef MOZ_WIDGET_ANDROID
4144
# include "APKOpen.h"
@@ -46,8 +49,8 @@ index 3cfc92533..9c487ac45 100644
4649
-#ifndef ANDROID
4750
+#ifdef ANDROID
4851
+ __android_log_print(ANDROID_LOG_ERROR, "Gecko", "mozalloc_abort: %s", msg);
49-
+#elif defined(OHOS)
50-
+ (void) OH_LOG_Print(LOG_APP, LOG_ERROR, 0, "Gecko",
52+
+#elif defined(XP_OHOS)
53+
+ (void) OH_LOG_Print(0 /* LOG_APP */, 7 /* LOG_FATAL */, 0, "Gecko",
5154
+ "mozalloc_abort: %{public}s\n", msg);
5255
+#else
5356
fputs(msg, stderr);
@@ -61,50 +64,58 @@ diff --git a/mfbt/Assertions.h b/mfbt/Assertions.h
6164
index 0b7395177..e84d76aba 100644
6265
--- a/mfbt/Assertions.h
6366
+++ b/mfbt/Assertions.h
64-
@@ -88,6 +88,8 @@ MOZ_END_EXTERN_C
67+
@@ -88,6 +88,11 @@ MOZ_END_EXTERN_C
6568
#endif
6669
#ifdef ANDROID
6770
# include <android/log.h>
68-
+#elif defined(OHOS)
69-
+# include <hilog/log.h>
71+
+#elif defined(XP_OHOS)
72+
+MOZ_BEGIN_EXTERN_C
73+
+int OH_LOG_Print(unsigned int type, unsigned int level, unsigned int domain, const char *tag, const char *fmt, ...)
74+
+ __attribute__((__format__(os_log, 5, 6)));
75+
+MOZ_END_EXTERN_C
7076
#endif
7177

7278
MOZ_BEGIN_EXTERN_C
7379
@@ -120,6 +122,10 @@ MOZ_ReportAssertionFailure(const char* aStr, const char* aFilename,
7480
MozWalkTheStackWithWriter(MOZ_ReportAssertionFailurePrintFrame, CallerPC(),
7581
/* aMaxFrames */ 0);
7682
# endif
77-
+#elif defined(OHOS)
78-
+ (void) OH_LOG_Print(LOG_APP, LOG_FATAL, 0, "MOZ_Assert",
83+
+#elif defined(XP_OHOS)
84+
+ (void) OH_LOG_Print(0 /* LOG_APP */, 7 /* LOG_FATAL */, 0, "MOZ_Assert",
7985
+ "Assertion failure: %{public}s, at %{public}s:%{public}d\n",
8086
+ aStr, aFilename, aLine);
8187
#else
8288
# if defined(MOZ_BUFFER_STDERR)
8389
char msg[1024] = "";
84-
@@ -144,6 +150,10 @@ MOZ_MAYBE_UNUSED static MOZ_COLD MOZ_NEVER_INLINE void MOZ_ReportCrash(
90+
@@ -144,8 +150,12 @@ MOZ_MAYBE_UNUSED static MOZ_COLD MOZ_NEVER_INLINE void MOZ_ReportCrash(
8591
__android_log_print(ANDROID_LOG_FATAL, "MOZ_CRASH",
8692
"[%d] Hit MOZ_CRASH(%s) at %s:%d\n", MOZ_GET_PID(), aStr,
8793
aFilename, aLine);
88-
+#elif defined(OHOS)
89-
+ (void) OH_LOG_Print(LOG_APP, LOG_FATAL, 0, "MOZ_CRASH",
90-
+ "Hit MOZ_CRASH(%{public}s), at %{public}s:%{public}d\n",
91-
+ aStr, aFilename, aLine);
9294
# if defined(MOZ_DUMP_ASSERTION_STACK)
9395
MozWalkTheStackWithWriter(MOZ_CrashPrintFrame, CallerPC(),
9496
/* aMaxFrames */ 0);
97+
# endif
98+
+#elif defined(XP_OHOS)
99+
+ (void) OH_LOG_Print(0 /* LOG_APP */, 7 /* LOG_FATAL */, 0, "MOZ_CRASH",
100+
+ "Hit MOZ_CRASH(%{public}s), at %{public}s:%{public}d\n",
101+
+ aStr, aFilename, aLine);
102+
#else
95103
diff --git a/mfbt/DbgMacro.h b/mfbt/DbgMacro.h
96104
index 3247b993c..c7039d5f8 100644
97105
--- a/mfbt/DbgMacro.h
98106
+++ b/mfbt/DbgMacro.h
99-
@@ -18,8 +18,10 @@
107+
@@ -18,8 +18,13 @@
100108
template <typename T>
101109
class nsTSubstring;
102110

103111
-#ifdef ANDROID
104112
+#if defined(ANDROID)
105113
# include <android/log.h>
106-
+#elif defined(OHOS)
107-
+# include <hilog/log.h>
114+
+#elif defined(XP_OHOS)
115+
+ MOZ_BEGIN_EXTERN_C
116+
+ int OH_LOG_Print(unsigned int type, unsigned int level, unsigned int domain, const char *tag, const char *fmt, ...)
117+
+ __attribute__((__format__(os_log, 5, 6)));
118+
+ MOZ_END_EXTERN_C
108119
#endif
109120

110121
namespace mozilla {
@@ -115,35 +126,41 @@ index 3247b993c..c7039d5f8 100644
115126
-#ifdef ANDROID
116127
+#if defined(ANDROID)
117128
__android_log_print(ANDROID_LOG_INFO, "Gecko", "%s", s.str().c_str());
118-
+#elif defined(OHOS)
119-
+ (void) OH_LOG_Print(LOG_APP, LOG_INFO, 0, "Gecko", "%{public}s\n", s.str().c_str());
129+
+#elif defined(XP_OHOS)
130+
+ (void) OH_LOG_Print(0 /* LOG_APP */, 4 /* LOG_INFO */, 0, "Gecko", "%{public}s\n", s.str().c_str());
120131
#else
121132
fputs(s.str().c_str(), stderr);
122133
#endif
123134
diff --git a/mozglue/misc/Debug.cpp b/mozglue/misc/Debug.cpp
124135
index c3a2ca89e..3fea33f4b 100644
125136
--- a/mozglue/misc/Debug.cpp
126137
+++ b/mozglue/misc/Debug.cpp
127-
@@ -18,9 +18,11 @@
138+
@@ -18,9 +18,14 @@
128139

129140
#ifdef ANDROID
130141
# include <android/log.h>
131-
+#elif defined(OHOS)
132-
+# include <hilog/log.h>
142+
+#elif defined(XP_OHOS)
143+
+ extern "C" {
144+
+ int OH_LOG_Print(unsigned int type, unsigned int level, unsigned int domain, const char *tag, const char *fmt, ...)
145+
+ __attribute__((__format__(os_log, 5, 6)));
146+
+ }
133147
#endif
134148

135149
-#ifndef ANDROID
136-
+#if ! (defined(ANDROID) || defined(OHOS))
150+
+#if ! (defined(ANDROID) || defined(XP_OHOS))
137151
static void vprintf_stderr_buffered(const char* aFmt, va_list aArgs) {
138152
// Avoid interleaving by writing to an on-stack buffer and then writing in one
139153
// go with fputs, as long as the output fits into the buffer.
140-
@@ -66,6 +68,10 @@ MFBT_API void vprintf_stderr(const char* aFmt, va_list aArgs) {
154+
@@ -66,6 +68,13 @@ MFBT_API void vprintf_stderr(const char* aFmt, va_list aArgs) {
141155
MFBT_API void vprintf_stderr(const char* aFmt, va_list aArgs) {
142156
__android_log_vprint(ANDROID_LOG_INFO, "Gecko", aFmt, aArgs);
143157
}
144-
+#elif defined(OHOS)
158+
+#elif defined(XP_OHOS)
145159
+MFBT_API void vprintf_stderr(const char* aFmt, va_list aArgs) {
146-
+ (void) OH_LOG_Print(LOG_APP, LOG_INFO, 0, "Gecko", aFmt, aArgs);
160+
+ // OH_LOG_VPrint is available with API-level 18 (19?) or higher.
161+
+ char buffer[1024];
162+
+ VsprintfBuf(buffer, 1024, aFmt, aArgs);
163+
+ (void) OH_LOG_Print(0 /* LOG_APP */, 4 /* LOG_INFO */, 0, "Gecko", "%{public}s", buffer);
147164
+}
148165
#elif defined(FUZZING_SNAPSHOT)
149166
MFBT_API void vprintf_stderr(const char* aFmt, va_list aArgs) {
@@ -153,15 +170,15 @@ index c3a2ca89e..3fea33f4b 100644
153170

154171
MFBT_API void print_stderr(std::stringstream& aStr) {
155172
-#if defined(ANDROID)
156-
+#if defined(ANDROID) || defined(OHOS)
173+
+#if defined(ANDROID) || defined(XP_OHOS)
157174
// On Android logcat output is truncated to 1024 chars per line, and
158175
// we usually use std::stringstream to build up giant multi-line gobs
159176
// of output. So to avoid the truncation we find the newlines and
160177
// print the lines individually.
161178
std::string line;
162179
while (std::getline(aStr, line)) {
163-
+# ifdef OHOS
164-
+ printf_stderr("%{public}s\n", line.c_str());
180+
+# ifdef XP_OHOS
181+
+ (void) OH_LOG_Print(0 /* LOG_APP */, 4 /* LOG_INFO */, 0, "Gecko", "%{public}s", line.c_str());
165182
+# else
166183
printf_stderr("%s\n", line.c_str());
167184
+# endif
@@ -172,30 +189,31 @@ diff --git a/nsprpub/pr/src/io/prlog.c b/nsprpub/pr/src/io/prlog.c
172189
index 52bd6abc5..781402d56 100644
173190
--- a/nsprpub/pr/src/io/prlog.c
174191
+++ b/nsprpub/pr/src/io/prlog.c
175-
@@ -8,8 +8,10 @@
192+
@@ -8,8 +8,11 @@
176193
#include "prenv.h"
177194
#include "prprf.h"
178195
#include <string.h>
179196
-#ifdef ANDROID
180197
+#if defined(ANDROID)
181198
# include <android/log.h>
182-
+#elif defined(OHOS)
183-
+# include <hilog/log.h>
199+
+#elif defined(XP_OHOS)
200+
+ int OH_LOG_Print(unsigned int type, unsigned int level, unsigned int domain, const char *tag, const char *fmt, ...)
201+
+ __attribute__((__format__(os_log, 5, 6)));
184202
#endif
185203

186204
/*
187205
@@ -108,6 +110,19 @@ static void OutputDebugStringA(const char* msg) {
188206
PR_Write(fd, buf, nb); \
189207
} \
190208
PR_END_MACRO
191-
+#elif defined(OHOS)
192-
+#define _PUT_LOG(fd, buf, nb) \
209+
+#elif defined(XP_OHOS)
210+
+# define _PUT_LOG(fd, buf, nb) \
193211
+ PR_BEGIN_MACRO \
194212
+ if (fd == _pr_stderr) { \
195213
+ char savebyte = buf[nb]; \
196214
+ buf[nb] = '\0'; \
197-
+ (void) OH_LOG_Print(LOG_APP, LOG_INFO, 0, "PRLog", \
198-
+ "%{public}s\n", buf); \
215+
+ (void) OH_LOG_Print(0 /* LOG_APP */, 4 /* LOG_INFO */, \
216+
+ 0, "PRLog", "%{public}s\n", buf); \
199217
+ buf[nb] = savebyte; \
200218
+ } else { \
201219
+ PR_Write(fd, buf, nb); \
@@ -208,17 +226,17 @@ index 52bd6abc5..781402d56 100644
208226
PR_LogPrint("Aborting");
209227
#ifdef ANDROID
210228
__android_log_write(ANDROID_LOG_ERROR, "PRLog", "Aborting");
211-
+#elif defined(OHOS)
212-
+ (void) OH_LOG_Print(LOG_APP, LOG_ERROR, 0, "PRLog", "Aborting\n");
229+
+#elif defined(XP_OHOS)
230+
+ (void) OH_LOG_Print(0 /* LOG_APP */, 7 /* LOG_FATAL */, 0, "PRLog", "Aborting\n");
213231
#endif
214232
abort();
215233
}
216234
@@ -567,6 +584,9 @@ PR_IMPLEMENT(void) PR_Assert(const char *s, const char *file, PRIntn ln)
217235
#elif defined(ANDROID)
218236
__android_log_assert(NULL, "PRLog", "Assertion failure: %s, at %s:%d\n", s,
219237
file, ln);
220-
+#elif defined(OHOS)
221-
+ (void) OH_LOG_Print(LOG_APP, LOG_ERROR, 0, "PRLog",
238+
+#elif defined(XP_OHOS)
239+
+ (void) OH_LOG_Print(0 /* LOG_APP */, 7 /* LOG_FATAL */, 0, "PRLog",
222240
+ "Assertion failure: %{public}s, at %{public}s:%{public}d\n",s, file, ln);
223241
#endif
224242
abort();

mozjs-sys/mozjs/build/moz.configure/init.configure

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mozjs-sys/mozjs/memory/mozalloc/mozalloc_abort.cpp

Lines changed: 7 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mozjs-sys/mozjs/mfbt/Assertions.h

Lines changed: 11 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mozjs-sys/mozjs/mfbt/DbgMacro.h

Lines changed: 7 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)