Skip to content

Commit

Permalink
chinese-addons (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
eagleoflqj authored Aug 21, 2024
1 parent 4def00b commit 6b24896
Show file tree
Hide file tree
Showing 7 changed files with 253 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@
[submodule "fcitx5-rime-data/rime-stroke"]
path = fcitx5-rime-data/rime-stroke
url = https://github.com/rime/rime-stroke
[submodule "fcitx5-chinese-addons"]
path = fcitx5-chinese-addons
url = https://github.com/fcitx/fcitx5-chinese-addons
1 change: 1 addition & 0 deletions fcitx5-chinese-addons
Submodule fcitx5-chinese-addons added at 64e2a0
4 changes: 4 additions & 0 deletions install-deps.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
deps=(
boost
extra-cmake-modules
glog
json-c
leveldb
libime
librime
libthai
marisa
opencc
yaml-cpp
zstd
)

EXTRACT_DIR=build/sysroot/usr
Expand Down
225 changes: 225 additions & 0 deletions patches/chinese-addons.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b8b59ad..85625da 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -8,6 +8,12 @@ include(GNUInstallDirs)
include(ECMSetupVersion)
include(ECMUninstallTarget)

+set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS TRUE)
+set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-sSIDE_MODULE")
+set(CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS "-sSIDE_MODULE")
+
+add_compile_options(-fPIC -fexceptions)
+
find_package(Fcitx5Core 5.1.11 REQUIRED)
find_package(Fcitx5Module REQUIRED COMPONENTS Notifications QuickPhrase Spell Clipboard)
find_package(Fcitx5ModuleLuaAddonLoader)
@@ -22,7 +28,7 @@ else()
set(FMT_TARGET fmt::fmt)
endif ()

-include("${FCITX_INSTALL_CMAKECONFIG_DIR}/Fcitx5Utils/Fcitx5CompilerSettings.cmake")
+include("../build/sysroot${FCITX_INSTALL_CMAKECONFIG_DIR}/Fcitx5Utils/Fcitx5CompilerSettings.cmake")

#######################################################################
# Options
@@ -67,6 +73,9 @@ find_package(Boost 1.61 REQUIRED COMPONENTS iostreams OPTIONAL_COMPONENTS json)
find_package(LibIMEPinyin 1.1.7 REQUIRED)
find_package(LibIMETable 1.1.4 REQUIRED)

+pkg_check_modules(ZSTD REQUIRED IMPORTED_TARGET "libzstd")
+set(LIBIME_INSTALL_PKGDATADIR "../libime")
+
if (ENABLE_CLOUDPINYIN)
pkg_check_modules(Curl REQUIRED IMPORTED_TARGET "libcurl")
endif()
@@ -85,7 +94,6 @@ fcitx5_add_i18n_definition()
add_subdirectory(modules)
add_subdirectory(im)
add_subdirectory(po)
-add_subdirectory(tools)

if (ENABLE_GUI)
add_subdirectory(gui)
diff --git a/im/pinyin/CMakeLists.txt b/im/pinyin/CMakeLists.txt
index 888c23c..798f4d9 100644
--- a/im/pinyin/CMakeLists.txt
+++ b/im/pinyin/CMakeLists.txt
@@ -7,7 +7,7 @@ set(PINYIN_SOURCES
)

add_library(pinyin MODULE ${PINYIN_SOURCES})
-target_link_libraries(pinyin Fcitx5::Core Fcitx5::Config LibIME::Pinyin Boost::iostreams Fcitx5::Module::Punctuation Fcitx5::Module::QuickPhrase Fcitx5::Module::Notifications Fcitx5::Module::Spell Fcitx5::Module::PinyinHelper Pthread::Pthread ${FMT_TARGET})
+target_link_libraries(pinyin -fexceptions Fcitx5::Core Fcitx5::Config LibIME::Pinyin Fcitx5::Module::Punctuation Fcitx5::Module::QuickPhrase Fcitx5::Module::Notifications Fcitx5::Module::Spell Fcitx5::Module::PinyinHelper Pthread::Pthread ${FMT_TARGET})

if (TARGET Fcitx5::Module::LuaAddonLoader)
target_compile_definitions(pinyin PRIVATE -DFCITX_HAS_LUA)
diff --git a/im/pinyin/pinyin.cpp b/im/pinyin/pinyin.cpp
index 439574c..9102dac 100644
--- a/im/pinyin/pinyin.cpp
+++ b/im/pinyin/pinyin.cpp
@@ -658,8 +658,7 @@ std::string PinyinEngine::evaluateCustomPhrase(InputContext *inputContext,

PinyinEngine::PinyinEngine(Instance *instance)
: instance_(instance),
- factory_([this](InputContext &) { return new PinyinState(this); }),
- worker_(instance->eventDispatcher()) {
+ factory_([this](InputContext &) { return new PinyinState(this); }) {
ime_ = std::make_unique<libime::PinyinIME>(
std::make_unique<libime::PinyinDictionary>(),
std::make_unique<libime::UserLanguageModel>(
@@ -828,25 +827,18 @@ void PinyinEngine::loadDict(const std::string &fullPath,
}
ime_->dict()->addEmptyDict();
PINYIN_DEBUG() << "Loading pinyin dict " << fullPath;
- std::packaged_task<libime::PinyinDictionary::TrieType()> task([fullPath]() {
- std::ifstream in(fullPath, std::ios::in | std::ios::binary);
- auto trie = libime::PinyinDictionary::load(
- in, libime::PinyinDictFormat::Binary);
- return trie;
- });
- taskTokens.push_back(worker_.addTask(
- std::move(task),
- [this, index = ime_->dict()->dictSize() - 1, fullPath](
- std::shared_future<libime::PinyinDictionary::TrieType> &future) {
- try {
- PINYIN_DEBUG()
- << "Load pinyin dict " << fullPath << " finished.";
- ime_->dict()->setTrie(index, future.get());
- } catch (const std::exception &e) {
- PINYIN_ERROR() << "Failed to load pinyin dict " << fullPath
- << ": " << e.what();
- }
- }));
+ std::ifstream in(fullPath, std::ios::in | std::ios::binary);
+ auto trie = libime::PinyinDictionary::load(
+ in, libime::PinyinDictFormat::Binary);
+ auto index = ime_->dict()->dictSize() - 1;
+ try {
+ PINYIN_DEBUG()
+ << "Load pinyin dict " << fullPath << " finished.";
+ ime_->dict()->setTrie(index, trie);
+ } catch (const std::exception &e) {
+ PINYIN_ERROR() << "Failed to load pinyin dict " << fullPath
+ << ": " << e.what();
+ }
}

void PinyinEngine::loadBuiltInDict() {
diff --git a/im/pinyin/pinyin.h b/im/pinyin/pinyin.h
index 9884c8d..3767e70 100644
--- a/im/pinyin/pinyin.h
+++ b/im/pinyin/pinyin.h
@@ -447,7 +447,6 @@ private:
std::unique_ptr<HandlerTableEntry<EventHandler>> event_;
CustomPhraseDict customPhrase_;
SymbolDict symbols_;
- WorkerThread worker_;
std::list<std::unique_ptr<TaskToken>> persistentTask_;
std::list<std::unique_ptr<TaskToken>> tasks_;

diff --git a/im/table/CMakeLists.txt b/im/table/CMakeLists.txt
index 91ed495..e5640bf 100644
--- a/im/table/CMakeLists.txt
+++ b/im/table/CMakeLists.txt
@@ -6,7 +6,7 @@ set(TABLE_SOURCES
candidate.cpp
)
add_library(table MODULE ${TABLE_SOURCES})
-target_link_libraries(table Fcitx5::Core Fcitx5::Config LibIME::Table LibIME::Pinyin Boost::iostreams Fcitx5::Module::Punctuation Fcitx5::Module::QuickPhrase Fcitx5::Module::PinyinHelper LibIME::Pinyin ${FMT_TARGET})
+target_link_libraries(table -fexceptions Fcitx5::Core Fcitx5::Config LibIME::Table LibIME::Pinyin Fcitx5::Module::Punctuation Fcitx5::Module::QuickPhrase Fcitx5::Module::PinyinHelper ${FMT_TARGET})
target_compile_definitions(table PRIVATE FCITX_STRINGUTILS_ENABLE_BOOST_STRING_VIEW)
install(TARGETS table DESTINATION "${CMAKE_INSTALL_LIBDIR}/fcitx5")
configure_file(table.conf.in.in table.conf.in)
diff --git a/modules/chttrans/CMakeLists.txt b/modules/chttrans/CMakeLists.txt
index 14351c8..631be74 100644
--- a/modules/chttrans/CMakeLists.txt
+++ b/modules/chttrans/CMakeLists.txt
@@ -5,7 +5,7 @@ if (ENABLE_OPENCC)
set(CHTTRANS_SOURCES ${CHTTRANS_SOURCES} chttrans-opencc.cpp)
endif()
add_library(chttrans MODULE ${CHTTRANS_SOURCES})
-target_link_libraries(chttrans Fcitx5::Core Fcitx5::Config Fcitx5::Module::Notifications Boost::iostreams ${FMT_TARGET})
+target_link_libraries(chttrans -fexceptions Fcitx5::Core Fcitx5::Config Fcitx5::Module::Notifications Boost::iostreams ${FMT_TARGET})
if (ENABLE_OPENCC)
target_link_libraries(chttrans OpenCC::OpenCC)
if (TARGET Boost::json)
diff --git a/modules/pinyinhelper/CMakeLists.txt b/modules/pinyinhelper/CMakeLists.txt
index a2ca5d9..8619ff9 100644
--- a/modules/pinyinhelper/CMakeLists.txt
+++ b/modules/pinyinhelper/CMakeLists.txt
@@ -5,6 +5,7 @@ set(PINYINHELPER_SOURCES
)
add_library(pinyinhelper MODULE ${PINYINHELPER_SOURCES})
target_link_libraries(pinyinhelper
+-fexceptions
Fcitx5::Core
Fcitx5::Config
LibIME::Core
diff --git a/modules/pinyinhelper/stroke.cpp b/modules/pinyinhelper/stroke.cpp
index 2e1dffa..4f8129e 100644
--- a/modules/pinyinhelper/stroke.cpp
+++ b/modules/pinyinhelper/stroke.cpp
@@ -25,11 +25,11 @@ namespace fcitx {
Stroke::Stroke() {}

void Stroke::loadAsync() {
- if (loadFuture_.valid()) {
+ if (loaded_) {
return;
}

- loadFuture_ = std::async(std::launch::async, []() {
+ loadFuture_ = ([]() {
std::tuple<libime::DATrie<int32_t>, libime::DATrie<int32_t>> result;
auto &dict = std::get<0>(result);
auto &reverseDict = std::get<1>(result);
@@ -80,18 +80,16 @@ void Stroke::loadAsync() {
reverseDict.shrink_tail();

return result;
- });
+ })();
}

bool Stroke::load() {
if (loaded_) {
return loadResult_;
}
- if (!loadFuture_.valid()) {
- loadAsync();
- }
+ loadAsync();
try {
- std::tie(dict_, revserseDict_) = loadFuture_.get();
+ std::tie(dict_, revserseDict_) = loadFuture_;
loadResult_ = true;
} catch (...) {
loadResult_ = false;
diff --git a/modules/pinyinhelper/stroke.h b/modules/pinyinhelper/stroke.h
index 048e2a0..009c496 100644
--- a/modules/pinyinhelper/stroke.h
+++ b/modules/pinyinhelper/stroke.h
@@ -33,7 +33,7 @@ private:
bool loaded_ = false;
bool loadResult_ = false;

- std::future<std::tuple<libime::DATrie<int32_t>, libime::DATrie<int32_t>>>
+ std::tuple<libime::DATrie<int32_t>, libime::DATrie<int32_t>>
loadFuture_;
};
} // namespace fcitx
diff --git a/modules/punctuation/CMakeLists.txt b/modules/punctuation/CMakeLists.txt
index 2de1433..c19dda4 100644
--- a/modules/punctuation/CMakeLists.txt
+++ b/modules/punctuation/CMakeLists.txt
@@ -9,7 +9,7 @@ set(PUNCTUATION_DATA_FILES
)

add_library(punctuation MODULE ${PUNCTUATION_SOURCES})
-target_link_libraries(punctuation Fcitx5::Core Fcitx5::Config Boost::iostreams Fcitx5::Module::Notifications)
+target_link_libraries(punctuation -fexceptions Fcitx5::Core Fcitx5::Config Boost::iostreams Fcitx5::Module::Notifications)
install(TARGETS punctuation DESTINATION "${CMAKE_INSTALL_LIBDIR}/fcitx5")
configure_file(punctuation.conf.in.in punctuation.conf.in)
fcitx5_translate_desktop_file("${CMAKE_CURRENT_BINARY_DIR}/punctuation.conf.in" punctuation.conf)
7 changes: 4 additions & 3 deletions patches/rime.patch
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e96508c..37c7cb5 100644
index e96508c..46e9923 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -9,6 +9,10 @@ include(GNUInstallDirs)
Expand All @@ -13,18 +13,19 @@ index e96508c..37c7cb5 100644
find_package(Gettext REQUIRED)
find_package(Fcitx5Core 5.1.11 REQUIRED)
find_package(Fcitx5Module REQUIRED COMPONENTS Notifications)
@@ -16,8 +20,8 @@ find_package(PkgConfig REQUIRED)
@@ -16,8 +20,9 @@ find_package(PkgConfig REQUIRED)
find_package(Pthread REQUIRED)

if (NOT DEFINED RIME_TARGET)
- pkg_check_modules(Rime REQUIRED IMPORTED_TARGET "rime>=1.0.0")
- set(RIME_TARGET PkgConfig::Rime)
+ set(RIME_TARGET "-L${PROJECT_SOURCE_DIR}/../build/sysroot/usr/lib" librime.a leveldb yaml-cpp marisa opencc glog)
+ set(Rime_VERSION "1.11.2")
+ include_directories("${PROJECT_SOURCE_DIR}/../build/sysroot/usr/include")
endif()

if ("${Rime_VERSION}" VERSION_LESS "1.8.0")
@@ -42,7 +46,7 @@ add_definitions(-DFCITX_GETTEXT_DOMAIN=\"fcitx5-rime\")
@@ -42,7 +47,7 @@ add_definitions(-DFCITX_GETTEXT_DOMAIN=\"fcitx5-rime\")
add_definitions(-DFCITX_RIME_VERSION=\"${PROJECT_VERSION}\")
fcitx5_add_i18n_definition()

Expand Down
15 changes: 15 additions & 0 deletions scripts/chinese-addons.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from common import Builder, ensure

src = 'build/sysroot/usr'
dst = 'build/chinese-addons/usr'
ensure('mkdir', ['-p', f'{dst}/lib'])
ensure('mkdir', ['-p', f'{dst}/share'])
ensure('cp', ['-r', f'{src}/lib/libime', f'{dst}/lib'])
ensure('cp', ['-r', f'{src}/share/libime', f'{dst}/share'])
ensure('cp', ['-r', f'{src}/share/opencc', f'{dst}/share'])

Builder('chinese-addons', [
'-DENABLE_CLOUDPINYIN=OFF',
'-DENABLE_TEST=OFF',
'-DENABLE_GUI=OFF'
]).exec()
2 changes: 1 addition & 1 deletion scripts/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def configure(self):
ensure('emcmake', ['cmake',
'-B', 'build', '-G', 'Ninja',
f'-DCMAKE_INSTALL_PREFIX={INSTALL_PREFIX}',
f'-DCMAKE_FIND_ROOT_PATH="{self.root}/build/sysroot/usr;/usr"',
f'-DCMAKE_FIND_ROOT_PATH={self.root}/build/sysroot/usr',
'-DCMAKE_BUILD_TYPE=Release',
*self.options
])
Expand Down

0 comments on commit 6b24896

Please sign in to comment.