Bug 1719535 - Part 4. Add ICU4X Data Provider. r=platform-i18n-reviewers,dminor,sylvestre

ICU4X will be used by ECMA-402 implementation at future. So we should link it
to SpiderMonkey instead of libxul only.

Depends on D178157

Differential Revision: https://phabricator.services.mozilla.com/D167673
This commit is contained in:
Makoto Kato 2023-08-07 06:23:48 +00:00
Родитель d34f218bae
Коммит 80aa728f71
15 изменённых файлов: 105 добавлений и 6 удалений

Просмотреть файл

@ -73,6 +73,17 @@ UNIFIED_SOURCES += [
if not CONFIG["JS_STANDALONE"]:
TEST_DIRS += ["gtest"]
if CONFIG["MOZ_ICU4X"]:
EXPORTS.mozilla.intl += [
"src/ICU4XGeckoDataProvider.h",
]
UNIFIED_SOURCES += [
"src/ICU4XGeckoDataProvider.cpp",
]
LOCAL_INCLUDES += [
"/third_party/rust/icu_capi/c/include",
]
# At the time of this writing the MOZ_HAS_MOZGLUE define must be true in order to
# correctly include ConvertUtf8toUtf16 in certain include paths, otherwise it results
# in a compile time "undeclared identifier" error. See:

Просмотреть файл

@ -0,0 +1,35 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "ICU4XGeckoDataProvider.h"
#include "ICU4XDataProvider.h"
#include "mozilla/Assertions.h"
#include <mutex>
namespace mozilla::intl {
static capi::ICU4XDataProvider* sICU4XDataProvider = nullptr;
capi::ICU4XDataProvider* GetDataProvider() {
static std::once_flag sOnce;
std::call_once(sOnce, []() {
sICU4XDataProvider = capi::ICU4XDataProvider_create_test();
});
return sICU4XDataProvider;
}
void CleanupDataProvider() {
if (!sICU4XDataProvider) {
return;
}
capi::ICU4XDataProvider_destroy(sICU4XDataProvider);
sICU4XDataProvider = nullptr;
}
} // namespace mozilla::intl

Просмотреть файл

@ -0,0 +1,21 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef intl_components_ICU4XGeckoDataProvider_h
#define intl_components_ICU4XGeckoDataProvider_h
/**
* This component is a C/C++ API to get ICU4X data provider.
*/
namespace capi {
struct ICU4XDataProvider;
}
namespace mozilla::intl {
capi::ICU4XDataProvider* GetDataProvider();
void CleanupDataProvider();
} // namespace mozilla::intl
#endif

Просмотреть файл

@ -142,6 +142,8 @@ rsync_filter_list = """
- /intl/icu/source/tools
+ /intl/icu/**
+ /intl/icu_testdata/**
- /intl/components/gtest
+ /intl/components/**
@ -284,7 +286,9 @@ def is_mozjs_cargo_member(line):
def is_mozjs_crates_io_local_patch(line):
"""Checks if the line in patch.crates-io is mozjs-related"""
return any(f'path = "{p}' in line for p in ("js", "build", "third_party/rust"))
return any(
f'path = "{p}' in line for p in ("js", "build", "third_party/rust", "intl")
)
def clean():

Просмотреть файл

@ -14,6 +14,7 @@ moz_memory = ['mozglue-static/moz_memory']
simd-accel = ['jsrust_shared/simd-accel']
smoosh = ['jsrust_shared/smoosh']
gluesmith = ['jsrust_shared/gluesmith']
icu4x = ['jsrust_shared/icu4x']
[dependencies]
mozilla-central-workspace-hack = { version = "0.1", features = ["jsrust"], optional = true }

Просмотреть файл

@ -18,6 +18,9 @@ if CONFIG["JS_ENABLE_SMOOSH"]:
if CONFIG["MOZ_MEMORY"]:
features += ["moz_memory"]
if CONFIG["MOZ_ICU4X"]:
features += ["icu4x"]
RustLibrary("jsrust", features)
if CONFIG["JS_SHARED_LIBRARY"]:

Просмотреть файл

@ -15,9 +15,11 @@ encoding_c_mem = "0.2.4"
smoosh = { path = "../../frontend/smoosh", optional = true }
mozglue-static = { path = "../../../../mozglue/static/rust" }
gluesmith = { path = "../../fuzz-tests/gluesmith", optional = true }
icu_capi = { version = "1.2.2", optional = true, default-features= false, features = ["any_provider", "icu_segmenter", "provider_test"] }
[features]
simd-accel = ['encoding_c/simd-accel']
icu4x = ['icu_capi']
# Uncomment this to enable perf support in release mode.
#[profile.release]

Просмотреть файл

@ -21,3 +21,6 @@ extern crate smoosh;
#[cfg(feature = "gluesmith")]
extern crate gluesmith;
#[cfg(feature = "icu4x")]
extern crate icu_capi;

Просмотреть файл

@ -11,6 +11,9 @@
#include "mozilla/Assertions.h"
#if JS_HAS_INTL_API
# include "mozilla/intl/ICU4CLibrary.h"
# if MOZ_ICU4X
# include "mozilla/intl/ICU4XGeckoDataProvider.h"
# endif
#endif
#include "mozilla/TextUtils.h"
@ -279,7 +282,10 @@ static void ShutdownImpl(JS::detail::FrontendOnly frontendOnly) {
#if JS_HAS_INTL_API
mozilla::intl::ICU4CLibrary::Cleanup();
#endif // JS_HAS_INTL_API
# if MOZ_ICU4X
mozilla::intl::CleanupDataProvider();
# endif // MOZ_ICU4X
#endif // JS_HAS_INTL_API
if (frontendOnly == FrontendOnly::No) {
#ifdef MOZ_VTUNE

Просмотреть файл

@ -4747,10 +4747,15 @@ THE SOFTWARE.
<h1><a id="unicode"></a>Unicode License</h1>
<p>This license applies to files in the <code>intl/icu</code>
and <code>intl/tzdata</code> directories and certain files in
the <code>js/src/util</code> directory.</p>
</p>
<p>This license applies to the following files or, in the case of
directories, certain files in those directories:</p>
<ul>
<li><code>intl/icu</code></li>
<li><code>intl/icu_testdata</code></li>
<li><code>intl/tzdata</code></li>
<li><code>js/src/util</code></li>
</ul>
<pre>
COPYRIGHT AND PERMISSION NOTICE

Просмотреть файл

@ -79,5 +79,8 @@ if CONFIG["MOZ_WEBMIDI_MIDIR_IMPL"]:
if CONFIG["MOZ_UNIFFI_FIXTURES"]:
gkrust_features += ['uniffi_fixtures']
if CONFIG["MOZ_ICU4X"]:
gkrust_features += ['icu4x']
# This must remain last.
gkrust_features = ["gkrust-shared/%s" % f for f in gkrust_features]

Просмотреть файл

@ -143,6 +143,7 @@ uniffi_fixtures = [
"uniffi-fixture-external-types",
]
webmidi_midir_impl = ["midir_impl"]
icu4x = ["jsrust_shared/icu4x"]
[lib]
path = "lib.rs"

Просмотреть файл

@ -68,6 +68,7 @@ file-whitespace:
- image/test/crashtests
- image/test/mochitest
- image/test/reftest
- intl/icu_testdata
- intl/lwbrk/crashtests
- intl/uconv/crashtests
- intl/uconv/tests

Просмотреть файл

@ -27,6 +27,8 @@ license:
- gradle.properties
# might not work with license
- gradle/wrapper/gradle-wrapper.properties
# ICU4X data
- intl/icu_testdata
# Imported code that is dual Apache2 / MIT licensed
- intl/l10n/rust/l10nregistry-rs
- intl/l10n/rust/l10nregistry-tests

Просмотреть файл

@ -9,6 +9,7 @@ rust:
- gfx/wr/peek-poke/
- gfx/wr/webrender_build/
- gfx/wr/wr_malloc_size_of/
- intl/icu_testdata/
- media/mp4parse-rust/
- servo/
- '**/*.mako.rs'