Skip to content

Add multithreaded variant to ICU port #15592

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

Merged
merged 3 commits into from
Nov 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion embuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,14 @@
'libunwind-except'
]

# Variant builds that we want to support for cetain ports
# Variant builds that we want to support for certain ports
# TODO: It would be nice if the ports themselves could specify the variants that they
# support.
PORT_VARIANTS = {
'regal-mt': ('regal', {'USE_PTHREADS': 1}),
'harfbuzz-mt': ('harfbuzz', {'USE_PTHREADS': 1}),
'sdl2-mt': ('sdl2', {'USE_PTHREADS': 1}),
'icu-mt': ('icu', {'USE_PTHREADS': 1}),
'sdl2_mixer_mp3': ('sdl2_mixer', {'SDL2_MIXER_FORMATS': ["mp3"]}),
'sdl2_mixer_none': ('sdl2_mixer', {'SDL2_MIXER_FORMATS': []}),
'sdl2_image_png': ('sdl2_image', {'SDL2_IMAGE_FORMATS': ["png"]}),
Expand Down
13 changes: 13 additions & 0 deletions tests/other/test_pthread_icu.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <iostream>
#include <thread>
#include <unicode/unistr.h>

// Test that code using both pthread and icu compiles.
int main() {
std::thread([] {
std::string str;
icu::UnicodeString ustr("Hello world!");
ustr.toUTF8String(str);
std::cout << str << std::endl;
}).join();
}
1 change: 1 addition & 0 deletions tests/other/test_pthread_icu.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello world!
8 changes: 8 additions & 0 deletions tests/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -11125,6 +11125,14 @@ def test_pthread_out_err(self):
self.set_setting('EXIT_RUNTIME')
self.do_other_test('test_pthread_out_err.c')

@node_pthreads
def test_pthread_icu(self):
self.set_setting('USE_PTHREADS')
self.set_setting('USE_ICU')
self.set_setting('PROXY_TO_PTHREAD')
self.set_setting('EXIT_RUNTIME')
self.do_other_test('test_pthread_icu.cpp')

# unistd tests

def test_unistd_confstr(self):
Expand Down
25 changes: 16 additions & 9 deletions tools/ports/icu.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,19 @@
VERSION = '68_2'
HASH = '12c3db5966c234c94e7918fb8acc8bd0838edc36a620f3faa788e7ff27b06f1aa431eb117401026e3963622b9323212f444b735d5c9dd3d0b82d772a4834b993'

libname_libicu_common = 'libicu_common.a'
libname_libicu_stubdata = 'libicu_stubdata.a'
libname_libicu_i18n = 'libicu_i18n.a'
libname_libicu_common = 'libicu_common'
libname_libicu_stubdata = 'libicu_stubdata'
libname_libicu_i18n = 'libicu_i18n'


def needed(settings):
return settings.USE_ICU


def get_lib_name(base_name, settings):
return base_name + ('-mt' if settings.USE_PTHREADS else '') + '.a'


def get(ports, settings, shared):
url = 'https://github.com/unicode-org/icu/releases/download/%s/icu4c-%s-src.zip' % (TAG, VERSION)
ports.fetch_project('icu', url, 'icu', sha512hash=HASH)
Expand Down Expand Up @@ -48,6 +52,9 @@ def build_lib(lib_output, lib_src, other_includes, build_flags):
# CXXFLAGS
'-std=c++11'
]
if settings.USE_PTHREADS:
additional_build_flags.append('-pthread')

ports.build_port(lib_src, lib_output, other_includes, build_flags + additional_build_flags)

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

return [
shared.Cache.get_lib(libname_libicu_common, create_libicu_common), # this also prepares the build
shared.Cache.get_lib(libname_libicu_stubdata, create_libicu_stubdata),
shared.Cache.get_lib(libname_libicu_i18n, create_libicu_i18n)
shared.Cache.get_lib(get_lib_name(libname_libicu_common, settings), create_libicu_common), # this also prepares the build
shared.Cache.get_lib(get_lib_name(libname_libicu_stubdata, settings), create_libicu_stubdata),
shared.Cache.get_lib(get_lib_name(libname_libicu_i18n, settings), create_libicu_i18n)
]


def clear(ports, settings, shared):
shared.Cache.erase_lib(libname_libicu_common)
shared.Cache.erase_lib(libname_libicu_stubdata)
shared.Cache.erase_lib(libname_libicu_i18n)
shared.Cache.erase_lib(get_lib_name(libname_libicu_common, settings))
shared.Cache.erase_lib(get_lib_name(libname_libicu_stubdata, settings))
shared.Cache.erase_lib(get_lib_name(libname_libicu_i18n, settings))


def process_args(ports):
Expand Down