Skip to content

Commit 36cae87

Browse files
Add multithreaded variant to ICU port (emscripten-core#15592)
1 parent 53dd48c commit 36cae87

File tree

5 files changed

+40
-10
lines changed

5 files changed

+40
-10
lines changed

embuilder.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,14 @@
5555
'libunwind-except'
5656
]
5757

58-
# Variant builds that we want to support for cetain ports
58+
# Variant builds that we want to support for certain ports
5959
# TODO: It would be nice if the ports themselves could specify the variants that they
6060
# support.
6161
PORT_VARIANTS = {
6262
'regal-mt': ('regal', {'USE_PTHREADS': 1}),
6363
'harfbuzz-mt': ('harfbuzz', {'USE_PTHREADS': 1}),
6464
'sdl2-mt': ('sdl2', {'USE_PTHREADS': 1}),
65+
'icu-mt': ('icu', {'USE_PTHREADS': 1}),
6566
'sdl2_mixer_mp3': ('sdl2_mixer', {'SDL2_MIXER_FORMATS': ["mp3"]}),
6667
'sdl2_mixer_none': ('sdl2_mixer', {'SDL2_MIXER_FORMATS': []}),
6768
'sdl2_image_png': ('sdl2_image', {'SDL2_IMAGE_FORMATS': ["png"]}),

tests/other/test_pthread_icu.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include <iostream>
2+
#include <thread>
3+
#include <unicode/unistr.h>
4+
5+
// Test that code using both pthread and icu compiles.
6+
int main() {
7+
std::thread([] {
8+
std::string str;
9+
icu::UnicodeString ustr("Hello world!");
10+
ustr.toUTF8String(str);
11+
std::cout << str << std::endl;
12+
}).join();
13+
}

tests/other/test_pthread_icu.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hello world!

tests/test_other.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11159,6 +11159,14 @@ def test_pthread_out_err(self):
1115911159
self.set_setting('EXIT_RUNTIME')
1116011160
self.do_other_test('test_pthread_out_err.c')
1116111161

11162+
@node_pthreads
11163+
def test_pthread_icu(self):
11164+
self.set_setting('USE_PTHREADS')
11165+
self.set_setting('USE_ICU')
11166+
self.set_setting('PROXY_TO_PTHREAD')
11167+
self.set_setting('EXIT_RUNTIME')
11168+
self.do_other_test('test_pthread_icu.cpp')
11169+
1116211170
# unistd tests
1116311171

1116411172
def test_unistd_confstr(self):

tools/ports/icu.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,19 @@
1111
VERSION = '68_2'
1212
HASH = '12c3db5966c234c94e7918fb8acc8bd0838edc36a620f3faa788e7ff27b06f1aa431eb117401026e3963622b9323212f444b735d5c9dd3d0b82d772a4834b993'
1313

14-
libname_libicu_common = 'libicu_common.a'
15-
libname_libicu_stubdata = 'libicu_stubdata.a'
16-
libname_libicu_i18n = 'libicu_i18n.a'
14+
libname_libicu_common = 'libicu_common'
15+
libname_libicu_stubdata = 'libicu_stubdata'
16+
libname_libicu_i18n = 'libicu_i18n'
1717

1818

1919
def needed(settings):
2020
return settings.USE_ICU
2121

2222

23+
def get_lib_name(base_name, settings):
24+
return base_name + ('-mt' if settings.USE_PTHREADS else '') + '.a'
25+
26+
2327
def get(ports, settings, shared):
2428
url = 'https://github.com/unicode-org/icu/releases/download/%s/icu4c-%s-src.zip' % (TAG, VERSION)
2529
ports.fetch_project('icu', url, 'icu', sha512hash=HASH)
@@ -48,6 +52,9 @@ def build_lib(lib_output, lib_src, other_includes, build_flags):
4852
# CXXFLAGS
4953
'-std=c++11'
5054
]
55+
if settings.USE_PTHREADS:
56+
additional_build_flags.append('-pthread')
57+
5158
ports.build_port(lib_src, lib_output, other_includes, build_flags + additional_build_flags)
5259

5360
# creator for libicu_common
@@ -71,16 +78,16 @@ def create_libicu_i18n(lib_output):
7178
build_lib(lib_output, lib_src, other_includes, ['-DU_I18N_IMPLEMENTATION=1'])
7279

7380
return [
74-
shared.Cache.get_lib(libname_libicu_common, create_libicu_common), # this also prepares the build
75-
shared.Cache.get_lib(libname_libicu_stubdata, create_libicu_stubdata),
76-
shared.Cache.get_lib(libname_libicu_i18n, create_libicu_i18n)
81+
shared.Cache.get_lib(get_lib_name(libname_libicu_common, settings), create_libicu_common), # this also prepares the build
82+
shared.Cache.get_lib(get_lib_name(libname_libicu_stubdata, settings), create_libicu_stubdata),
83+
shared.Cache.get_lib(get_lib_name(libname_libicu_i18n, settings), create_libicu_i18n)
7784
]
7885

7986

8087
def clear(ports, settings, shared):
81-
shared.Cache.erase_lib(libname_libicu_common)
82-
shared.Cache.erase_lib(libname_libicu_stubdata)
83-
shared.Cache.erase_lib(libname_libicu_i18n)
88+
shared.Cache.erase_lib(get_lib_name(libname_libicu_common, settings))
89+
shared.Cache.erase_lib(get_lib_name(libname_libicu_stubdata, settings))
90+
shared.Cache.erase_lib(get_lib_name(libname_libicu_i18n, settings))
8491

8592

8693
def process_args(ports):

0 commit comments

Comments
 (0)