-
-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathglib-emscripten.patch
189 lines (160 loc) · 6.71 KB
/
glib-emscripten.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Kleis Auke Wolthuizen <[email protected]>
Date: Wed, 18 Sep 2019 15:00:00 +0200
Subject: [PATCH 1/8] Emscripten doesn't define
__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 either
https://bugs.llvm.org/show_bug.cgi?id=11174 might be relevant here.
Upstream-Status: Pending
diff --git a/meson.build b/meson.build
index 1111111..2222222 100644
--- a/meson.build
+++ b/meson.build
@@ -1893,8 +1893,8 @@ atomicdefine = '''
# We know that we can always use real ("lock free") atomic operations with MSVC
if cc.get_id() == 'msvc' or cc.get_id() == 'clang-cl' or cc.links(atomictest, name : 'atomic ops')
have_atomic_lock_free = true
- if cc.get_id() == 'gcc' and not cc.compiles(atomicdefine, name : 'atomic ops define')
- # Old gcc release may provide
+ if (cc.get_id() == 'gcc' or host_system == 'emscripten') and not cc.compiles(atomicdefine, name : 'atomic ops define')
+ # gcc (some old releases) or Emscripten provides
# __sync_bool_compare_and_swap but doesn't define
# __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
glib_conf.set('__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4', true)
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Kleis Auke Wolthuizen <[email protected]>
Date: Wed, 18 Sep 2019 15:20:00 +0200
Subject: [PATCH 2/8] posix_spawn isn't usable in WASM
Upstream-Status: Pending
diff --git a/meson.build b/meson.build
index 1111111..2222222 100644
--- a/meson.build
+++ b/meson.build
@@ -732,7 +732,7 @@ if host_system != 'windows' and cc.has_function('posix_memalign', prefix: '#incl
endif
# Check that posix_spawn() is usable; must use header
-if cc.has_function('posix_spawn', prefix : '#include <spawn.h>')
+if host_system != 'emscripten' and cc.has_function('posix_spawn', prefix : '#include <spawn.h>')
glib_conf.set('HAVE_POSIX_SPAWN', 1)
endif
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Kleis Auke Wolthuizen <[email protected]>
Date: Wed, 18 Sep 2019 15:40:00 +0200
Subject: [PATCH 3/8] Network libs are not available in WASM
Upstream-Status: Pending
diff --git a/gio/meson.build b/gio/meson.build
index 1111111..2222222 100644
--- a/gio/meson.build
+++ b/gio/meson.build
@@ -35,7 +35,7 @@ endif
network_libs = [ ]
network_args = [ ]
-if host_system != 'windows'
+if host_system not in ['windows', 'emscripten']
# res_query()
res_query_test = '''#include <resolv.h>
int main (int argc, char ** argv) {
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Kleis Auke Wolthuizen <[email protected]>
Date: Wed, 22 Apr 2020 12:11:28 +0200
Subject: [PATCH 4/8] Ensure separate checks are also done for Emscripten
Upstream-Status: Pending
diff --git a/meson.build b/meson.build
index 1111111..2222222 100644
--- a/meson.build
+++ b/meson.build
@@ -472,7 +472,7 @@ foreach m : struct_members
endforeach
# Compiler flags
-if cc.get_id() == 'gcc' or cc.get_id() == 'clang'
+if cc.get_id() == 'gcc' or cc.get_id() == 'clang' or cc.get_id() == 'emscripten'
warning_common_args = [
'-Wduplicated-branches',
'-Wimplicit-fallthrough',
@@ -1572,10 +1572,10 @@ g_sizet_compatibility = {
'long long': sizet_size == long_long_size,
}
-# Do separate checks for gcc/clang (and ignore other compilers for now), since
-# we need to explicitly pass -Werror to the compilers.
+# Do separate checks for gcc/clang/emscripten (and ignore other compilers for now),
+# since we need to explicitly pass -Werror to the compilers.
# FIXME: https://github.com/mesonbuild/meson/issues/5399
-if cc.get_id() == 'gcc' or cc.get_id() == 'clang'
+if cc.get_id() == 'gcc' or cc.get_id() == 'clang' or cc.get_id() == 'emscripten'
foreach type_name, size_compatibility : g_sizet_compatibility
g_sizet_compatibility += { type_name: size_compatibility and
cc.compiles(
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Kleis Auke Wolthuizen <[email protected]>
Date: Tue, 13 Apr 2021 15:30:00 +0200
Subject: [PATCH 5/8] Use vsnpintf/snprintf/printf from musl libc
The C99 semantics of these functions is well supported in musl libc.
Note: can also be set with these properties in the Meson cross file:
have_c99_vsnprintf = true
have_c99_snprintf = true
have_unix98_printf = true
Upstream-Status: Pending
diff --git a/meson.build b/meson.build
index 1111111..2222222 100644
--- a/meson.build
+++ b/meson.build
@@ -1045,9 +1045,9 @@ if host_system == 'windows' and (cc.get_id() == 'msvc' or cc.get_id() == 'clang-
glib_conf.set('HAVE_C99_SNPRINTF', false)
glib_conf.set('HAVE_C99_VSNPRINTF', false)
glib_conf.set('HAVE_UNIX98_PRINTF', false)
-elif not cc_can_run and host_system in ['ios', 'darwin']
- # All these are true when compiling natively on macOS, so we should use good
- # defaults when building for iOS and tvOS.
+elif not cc_can_run and host_system in ['ios', 'darwin', 'emscripten']
+ # All these are true when compiling natively on macOS, or when compiling with
+ # Emscripten (which uses musl libc internally).
glib_conf.set('HAVE_C99_SNPRINTF', true)
glib_conf.set('HAVE_C99_VSNPRINTF', true)
glib_conf.set('HAVE_UNIX98_PRINTF', true)
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Kleis Auke Wolthuizen <[email protected]>
Date: Fri, 15 Nov 2019 11:00:00 +0100
Subject: [PATCH 6/8] Implement g_get_num_processors for Emscripten
Upstream-Status: Pending
diff --git a/glib/gthread.c b/glib/gthread.c
index 1111111..2222222 100644
--- a/glib/gthread.c
+++ b/glib/gthread.c
@@ -56,6 +56,10 @@
#include <windows.h>
#endif /* G_OS_WIN32 */
+#ifdef __EMSCRIPTEN__
+#include <emscripten/threading.h>
+#endif /*__EMSCRIPTEN__*/
+
#include "gslice.h"
#include "gstrfuncs.h"
#include "gtestutils.h"
@@ -1070,7 +1074,9 @@ g_thread_self (void)
guint
g_get_num_processors (void)
{
-#ifdef G_OS_WIN32
+#ifdef __EMSCRIPTEN__
+ return emscripten_num_logical_cores();
+#elif defined G_OS_WIN32
unsigned int count;
SYSTEM_INFO sysinfo;
DWORD_PTR process_cpus;
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Kleis Auke Wolthuizen <[email protected]>
Date: Tue, 25 May 2021 11:00:00 +0200
Subject: [PATCH 7/8] Disable GModule implementation on Emscripten
Upstream-Status: Pending
diff --git a/gmodule/meson.build b/gmodule/meson.build
index 1111111..2222222 100644
--- a/gmodule/meson.build
+++ b/gmodule/meson.build
@@ -13,7 +13,8 @@ if host_system == 'windows'
# dlopen() filepath must be of the form /path/libname.a(libname.so)
elif host_system == 'aix'
g_module_impl = 'G_MODULE_IMPL_AR'
-elif have_dlopen_dlsym
+# Static linking should be preferred on Emscripten whenever possible
+elif have_dlopen_dlsym and host_system != 'emscripten'
g_module_impl = 'G_MODULE_IMPL_DL'
endif