Skip to content

Commit dba4f2c

Browse files
authored
js: use raw mozc.data to for Chrome !macos !windows !ios !harmony (#50)
1 parent 3c5917a commit dba4f2c

File tree

4 files changed

+41
-5
lines changed

4 files changed

+41
-5
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ __pycache__
44
/boost*
55
*.bz2
66
*.xz
7-
mozc_data.inc
7+
mozc.data
8+
cache/mozc_data.inc
89
meson-ios-*.ini
910
!meson-ios-template.ini

patches/mozc_data.inc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
}}}
2+
3+
#include <fstream>
4+
5+
namespace mozc {
6+
namespace oss {
7+
namespace {
8+
9+
inline const EmbeddedFile& GetOssMozcDataSet() {
10+
static const EmbeddedFile file = []() -> EmbeddedFile {
11+
std::ifstream in("/usr/share/mozc/mozc.data", std::ios::binary | std::ios::ate);
12+
std::streamsize size = in.tellg();
13+
in.seekg(0, std::ios::beg);
14+
static std::vector<char> buffer(size);
15+
in.read(buffer.data(), size);
16+
return EmbeddedFile{
17+
reinterpret_cast<const uint64_t*>(buffer.data()),
18+
static_cast<size_t>(size)
19+
};
20+
}();
21+
return file;
22+
}
23+
24+
const EmbeddedFile& kOssMozcDataSet = GetOssMozcDataSet();

scripts/libmozc.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ def configure(self):
1616
super().configure()
1717
oss_dir = f'{self.build_}/data_manager/oss'
1818
ensure('mkdir', ['-p', oss_dir])
19-
ensure('ln', ['-sf', f'{ROOT}/cache/mozc_data.inc', f'{oss_dir}/mozc_data.inc'])
19+
if PLATFORM == 'js':
20+
ensure('ln', ['-sf', f'{ROOT}/patches/mozc_data.inc', f'{oss_dir}/mozc_data.inc'])
21+
else:
22+
ensure('ln', ['-sf', f'{ROOT}/cache/mozc_data.inc', f'{oss_dir}/mozc_data.inc'])
2023

2124
def install(self):
2225
super().install()
@@ -26,6 +29,11 @@ def install(self):
2629
all_libabsl_o = f'$(find {self.build_}/mozc/src/third_party/abseil-cpp -name "*.o" | sort)'
2730
ensure(ar, ['rc', libabsl_a, all_libabsl_o])
2831

32+
if PLATFORM == 'js':
33+
share_dir = f'{self.dest_dir}{INSTALL_PREFIX}/share/mozc'
34+
ensure('mkdir', ['-p', share_dir])
35+
ensure('cp', [f'{ROOT}/cache/mozc.data', share_dir])
36+
2937
def pre_package(self):
3038
if PLATFORM != 'macos':
3139
ensure('rm', ['-rf', f'{self.dest_dir}{INSTALL_PREFIX}/bin'])
@@ -51,6 +59,11 @@ def pre_package(self):
5159
patch('libmozc/mozc')
5260
# Fix RuntimeError: null function or function signature mismatch.
5361
patch('libmozc/mozc/src/third_party/abseil-cpp')
62+
# Use raw data instead of embed data into libmozc.so so that Chrome accepts it
63+
# without --enable-features=WebAssemblyUnlimitedSyncCompilation.
64+
cache('https://github.com/fcitx-contrib/fcitx5-mozc/releases/download/latest/mozc.data')
65+
else:
66+
cache('https://github.com/fcitx-contrib/fcitx5-mozc/releases/download/latest/mozc_data.inc')
5467

5568
if platform.system() == 'Darwin' and PLATFORM != 'macos':
5669
steal('libmozc', ('bin',)) # extracted to install dir so need to remove on prepack.
@@ -59,6 +72,4 @@ def pre_package(self):
5972
if PLATFORM in ('ios', 'js'):
6073
options.append(f'-DPROTOC_EXECUTABLE={protoc_exe}')
6174

62-
cache('https://github.com/fcitx-contrib/fcitx5-mozc/releases/download/latest/mozc_data.inc')
63-
6475
MozcBuilder('libmozc', options).exec()

0 commit comments

Comments
 (0)