diff --git a/.github/workflows/windows-build.yml b/.github/workflows/windows-build.yml index f239386e4..9793b6b85 100644 --- a/.github/workflows/windows-build.yml +++ b/.github/workflows/windows-build.yml @@ -112,3 +112,39 @@ jobs: path: | rime-${{ env.git_ref_name }}-${{ runner.os }}.7z rime-deps-${{ env.git_ref_name }}-${{ runner.os }}.7z + + build-mingw: + runs-on: windows-latest + defaults: + run: + shell: msys2 {0} + + steps: + - name: Setup MSYS2 + uses: msys2/setup-msys2@v2 + + - name: Checkout last commit + uses: actions/checkout@v3 + + - name: Install dependencies + run: | + pacman -S --noconfirm base-devel mingw-w64-x86_64-toolchain ninja \ + mingw64/mingw-w64-x86_64-cmake \ + mingw-w64-x86_64-boost \ + mingw-w64-x86_64-glog \ + mingw-w64-x86_64-gtest \ + mingw-w64-x86_64-yaml-cpp \ + mingw-w64-x86_64-leveldb \ + mingw-w64-x86_64-marisa \ + mingw-w64-x86_64-opencc + + - name: Build with mingw-w64 + run: | + cmake -B build -G Ninja \ + -DCMAKE_BUILD_TYPE:STRING=Release \ + -DENABLE_LOGGING:BOOL=ON \ + -DBUILD_TEST:BOOL=ON \ + -DBUILD_STATIC:BOOL=ON \ + -DBUILD_SHARED_LIBS:BOOL=ON + cmake --build build + cd build/test && cp ../lib/librime.dll . && ./rime_test diff --git a/build-clang.bat b/build-clang.bat index 10c7f1e2e..d2cc8fd04 100644 --- a/build-clang.bat +++ b/build-clang.bat @@ -125,7 +125,7 @@ if %build_deps% == 1 ( echo building opencc. pushd deps\opencc cmake . %deps_cmake_flags%^ - -DCMAKE_CXX_FLAGS:PATH="-I %RIME_ROOT%\include -L %RIME_ROOT%\lib"^ + -DCMAKE_CXX_FLAGS:STRING="-I %RIME_ROOT%\include -L %RIME_ROOT%\lib"^ -DUSE_SYSTEM_MARISA:BOOL=ON || exit cmake --build build || exit cmake --install build || exit @@ -141,7 +141,6 @@ set rime_cmake_flags=%common_cmake_flags%^ if %build_librime% == 1 ( echo building librime. - echo %rime_cmake_flags% cmake . %rime_cmake_flags% || exit cmake --build build || exit cmake --install build || exit diff --git a/src/rime/algo/encoder.h b/src/rime/algo/encoder.h index 047f2fc87..00290fe48 100644 --- a/src/rime/algo/encoder.h +++ b/src/rime/algo/encoder.h @@ -63,16 +63,16 @@ struct TableEncodingRule { }; // for rule-based phrase encoding -class TableEncoder : public Encoder { +class RIME_API TableEncoder : public Encoder { public: - RIME_API TableEncoder(PhraseCollector* collector = NULL); + TableEncoder(PhraseCollector* collector = NULL); - RIME_API bool LoadSettings(Config* config); + bool LoadSettings(Config* config); - RIME_API bool Encode(const RawCode& code, string* result); - RIME_API bool EncodePhrase(const string& phrase, const string& value); + bool Encode(const RawCode& code, string* result); + bool EncodePhrase(const string& phrase, const string& value); - RIME_API bool IsCodeExcluded(const string& code); + bool IsCodeExcluded(const string& code); bool loaded() const { return loaded_; } const vector& encoding_rules() const { diff --git a/src/rime/composition.h b/src/rime/composition.h index 8fe6a97e7..489da8a34 100644 --- a/src/rime/composition.h +++ b/src/rime/composition.h @@ -29,7 +29,7 @@ class Composition : public Segmentation { string GetPrompt() const; string GetCommitText() const; string GetScriptText() const; - string GetDebugText() const; + RIME_API string GetDebugText() const; // Returns text of the last segment before the given position. string GetTextBefore(size_t pos) const; }; diff --git a/src/rime/config/config_types.h b/src/rime/config/config_types.h index 9278a7afd..809734cf0 100644 --- a/src/rime/config/config_types.h +++ b/src/rime/config/config_types.h @@ -36,9 +36,9 @@ class ConfigValue : public ConfigItem { ConfigValue() : ConfigItem(kScalar) {} RIME_API ConfigValue(bool value); RIME_API ConfigValue(int value); - ConfigValue(double value); + RIME_API ConfigValue(double value); RIME_API ConfigValue(const char* value); - ConfigValue(const string& value); + RIME_API ConfigValue(const string& value); // schalar value accessors bool GetBool(bool* value) const; @@ -155,7 +155,7 @@ class ConfigItemRef { RIME_API bool Append(an item); RIME_API size_t size() const; // map - bool HasKey(const string& key) const; + RIME_API bool HasKey(const string& key) const; RIME_API bool modified() const; RIME_API void set_modified(); diff --git a/src/rime/context.h b/src/rime/context.h index 58ea39aa5..988a5817d 100644 --- a/src/rime/context.h +++ b/src/rime/context.h @@ -28,11 +28,11 @@ class Context { Context() = default; ~Context() = default; - bool Commit(); + RIME_API bool Commit(); string GetCommitText() const; string GetScriptText() const; Preedit GetPreedit() const; - bool IsComposing() const; + RIME_API bool IsComposing() const; bool HasMenu() const; an GetSelectedCandidate() const; diff --git a/src/rime/deployer.h b/src/rime/deployer.h index 4d01d22e1..9045e1d66 100644 --- a/src/rime/deployer.h +++ b/src/rime/deployer.h @@ -43,8 +43,8 @@ class Deployer : public Messenger { string distribution_version; // } - Deployer(); - ~Deployer(); + RIME_API Deployer(); + RIME_API ~Deployer(); bool RunTask(const string& task_name, TaskInitializer arg = TaskInitializer()); diff --git a/src/rime/dict/corrector.h b/src/rime/dict/corrector.h index 48f07183a..c5e31ef56 100644 --- a/src/rime/dict/corrector.h +++ b/src/rime/dict/corrector.h @@ -112,14 +112,14 @@ class EditDistanceCorrector : public Corrector, public Prism { corrector::Distance threshold); }; -class NearSearchCorrector : public Corrector { +class RIME_API NearSearchCorrector : public Corrector { public: NearSearchCorrector() = default; ~NearSearchCorrector() override = default; - RIME_API void ToleranceSearch(const Prism& prism, - const string& key, - corrector::Corrections* results, - size_t tolerance) override; + void ToleranceSearch(const Prism& prism, + const string& key, + corrector::Corrections* results, + size_t tolerance) override; }; template diff --git a/src/rime/dict/db.h b/src/rime/dict/db.h index 6c0163b26..674414375 100644 --- a/src/rime/dict/db.h +++ b/src/rime/dict/db.h @@ -93,7 +93,7 @@ class Recoverable { class ResourceResolver; -class DbComponentBase { +class RIME_API DbComponentBase { public: DbComponentBase(); virtual ~DbComponentBase(); diff --git a/src/rime/dict/dictionary.h b/src/rime/dict/dictionary.h index 99dae4fce..cf0de9e47 100644 --- a/src/rime/dict/dictionary.h +++ b/src/rime/dict/dictionary.h @@ -23,9 +23,9 @@ struct QueryResult; } // namespace dictionary -class DictEntryIterator : public DictEntryFilterBinder { +class RIME_API DictEntryIterator : public DictEntryFilterBinder { public: - RIME_API DictEntryIterator(); + DictEntryIterator(); virtual ~DictEntryIterator() = default; DictEntryIterator(const DictEntryIterator& other) = default; DictEntryIterator& operator=(const DictEntryIterator& other) = default; @@ -34,11 +34,11 @@ class DictEntryIterator : public DictEntryFilterBinder { void AddChunk(dictionary::Chunk&& chunk); void Sort(); - RIME_API void AddFilter(DictEntryFilter filter) override; - RIME_API an Peek(); - RIME_API bool Next(); + void AddFilter(DictEntryFilter filter) override; + an Peek(); + bool Next(); bool Skip(size_t num_entries); - RIME_API bool exhausted() const; + bool exhausted() const; size_t entry_count() const { return entry_count_; } protected: diff --git a/src/rime/dict/level_db.cc b/src/rime/dict/level_db.cc index b056d279b..4377fa82c 100644 --- a/src/rime/dict/level_db.cc +++ b/src/rime/dict/level_db.cc @@ -327,13 +327,13 @@ bool LevelDb::CommitTransaction() { } template <> -string UserDbComponent::extension() const { +RIME_API string UserDbComponent::extension() const { return ".userdb"; } template <> -UserDbWrapper::UserDbWrapper(const string& file_name, - const string& db_name) +RIME_API UserDbWrapper::UserDbWrapper(const string& file_name, + const string& db_name) : LevelDb(file_name, db_name, "userdb") {} } // namespace rime diff --git a/src/rime/dict/text_db.h b/src/rime/dict/text_db.h index a33068110..66d8701b1 100644 --- a/src/rime/dict/text_db.h +++ b/src/rime/dict/text_db.h @@ -46,18 +46,18 @@ class TextDb : public Db { RIME_API virtual ~TextDb(); RIME_API virtual bool Open(); - virtual bool OpenReadOnly(); + RIME_API virtual bool OpenReadOnly(); RIME_API virtual bool Close(); - virtual bool Backup(const string& snapshot_file); - virtual bool Restore(const string& snapshot_file); + RIME_API virtual bool Backup(const string& snapshot_file); + RIME_API virtual bool Restore(const string& snapshot_file); - virtual bool CreateMetadata(); - virtual bool MetaFetch(const string& key, string* value); - virtual bool MetaUpdate(const string& key, const string& value); + RIME_API virtual bool CreateMetadata(); + RIME_API virtual bool MetaFetch(const string& key, string* value); + RIME_API virtual bool MetaUpdate(const string& key, const string& value); - virtual an QueryMetadata(); - virtual an QueryAll(); + RIME_API virtual an QueryMetadata(); + RIME_API virtual an QueryAll(); RIME_API virtual an Query(const string& key); RIME_API virtual bool Fetch(const string& key, string* value); RIME_API virtual bool Update(const string& key, const string& value); diff --git a/src/rime/dict/user_db.cc b/src/rime/dict/user_db.cc index 22b448051..21d32b98a 100644 --- a/src/rime/dict/user_db.cc +++ b/src/rime/dict/user_db.cc @@ -96,8 +96,8 @@ static TextFormat plain_userdb_format = { }; template <> -UserDbWrapper::UserDbWrapper(const string& file_name, - const string& db_name) +RIME_API UserDbWrapper::UserDbWrapper(const string& file_name, + const string& db_name) : TextDb(file_name, db_name, "userdb", plain_userdb_format) {} bool UserDbHelper::UpdateUserInfo() { diff --git a/src/rime/dict/user_db.h b/src/rime/dict/user_db.h index 418708118..17bbfa7bf 100644 --- a/src/rime/dict/user_db.h +++ b/src/rime/dict/user_db.h @@ -61,10 +61,10 @@ class UserDbHelper { UserDbHelper(const the& db) : db_(db.get()) {} UserDbHelper(const an& db) : db_(db.get()) {} - bool UpdateUserInfo(); - static bool IsUniformFormat(const string& name); - bool UniformBackup(const string& snapshot_file); - bool UniformRestore(const string& snapshot_file); + RIME_API bool UpdateUserInfo(); + RIME_API static bool IsUniformFormat(const string& name); + RIME_API bool UniformBackup(const string& snapshot_file); + RIME_API bool UniformRestore(const string& snapshot_file); bool IsUserDb(); string GetDbName(); diff --git a/src/rime/dict/vocabulary.h b/src/rime/dict/vocabulary.h index ec40fc1a1..3e54752f8 100644 --- a/src/rime/dict/vocabulary.h +++ b/src/rime/dict/vocabulary.h @@ -68,10 +68,10 @@ class DictEntryList : public vector> { using DictEntryFilter = function entry)>; -class DictEntryFilterBinder { +class RIME_API DictEntryFilterBinder { public: virtual ~DictEntryFilterBinder() = default; - RIME_API virtual void AddFilter(DictEntryFilter filter); + virtual void AddFilter(DictEntryFilter filter); protected: DictEntryFilter filter_; diff --git a/src/rime/gear/simplifier.cc b/src/rime/gear/simplifier.cc index 7463af3b2..d7cba581e 100644 --- a/src/rime/gear/simplifier.cc +++ b/src/rime/gear/simplifier.cc @@ -25,7 +25,7 @@ #include #include -#ifdef WIN32 +#ifdef _MSC_VER #include namespace fs = boost::filesystem; #endif @@ -42,13 +42,13 @@ class Opencc { opencc::Config config; try { // windows config_path in CP_ACP, convert it to UTF-8 -#ifdef WIN32 +#ifdef _MSC_VER fs::path path{config_path}; converter_ = config.NewFromFile(opencc::UTF8Util::U16ToU8(path.wstring())); #else converter_ = config.NewFromFile(config_path); -#endif /* WIN32 */ +#endif /* _MSC_VER */ const list conversions = converter_->GetConversionChain()->GetConversions(); dict_ = conversions.front()->GetDict(); diff --git a/src/rime/lever/deployment_tasks.h b/src/rime/lever/deployment_tasks.h index 8fd61f633..6555fad59 100644 --- a/src/rime/lever/deployment_tasks.h +++ b/src/rime/lever/deployment_tasks.h @@ -25,14 +25,14 @@ class DetectModifications : public DeploymentTask { }; // initialize/update installation.yaml -class InstallationUpdate : public DeploymentTask { +class RIME_API InstallationUpdate : public DeploymentTask { public: InstallationUpdate(TaskInitializer arg = TaskInitializer()) {} bool Run(Deployer* deployer); }; // update distributed config files and preset schemas -class WorkspaceUpdate : public DeploymentTask { +class RIME_API WorkspaceUpdate : public DeploymentTask { public: WorkspaceUpdate(TaskInitializer arg = TaskInitializer()) {} bool Run(Deployer* deployer); @@ -44,7 +44,7 @@ class WorkspaceUpdate : public DeploymentTask { }; // update a specific schema, build corresponding dictionary -class SchemaUpdate : public DeploymentTask { +class RIME_API SchemaUpdate : public DeploymentTask { public: explicit SchemaUpdate(const string& schema_file) : schema_file_(schema_file) {} diff --git a/src/rime/lever/user_dict_manager.h b/src/rime/lever/user_dict_manager.h index 9670d2ca5..21726e13d 100644 --- a/src/rime/lever/user_dict_manager.h +++ b/src/rime/lever/user_dict_manager.h @@ -16,7 +16,7 @@ class Deployer; using UserDictList = vector; -class UserDictManager { +class RIME_API UserDictManager { public: UserDictManager(Deployer* deployer); diff --git a/src/rime/resource.h b/src/rime/resource.h index bc4f042b6..47cef2dfd 100644 --- a/src/rime/resource.h +++ b/src/rime/resource.h @@ -20,12 +20,11 @@ struct ResourceType { string suffix; }; -class ResourceResolver { +class RIME_API ResourceResolver { public: explicit ResourceResolver(const ResourceType type) : type_(type) {} virtual ~ResourceResolver() {} - RIME_API virtual boost::filesystem::path ResolvePath( - const string& resource_id); + virtual boost::filesystem::path ResolvePath(const string& resource_id); string ToResourceId(const string& file_path) const; string ToFilePath(const string& resource_id) const; void set_root_path(boost::filesystem::path root_path) { @@ -39,12 +38,11 @@ class ResourceResolver { }; // try fallback path if target file doesn't exist in root path -class FallbackResourceResolver : public ResourceResolver { +class RIME_API FallbackResourceResolver : public ResourceResolver { public: explicit FallbackResourceResolver(const ResourceType& type) : ResourceResolver(type) {} - RIME_API boost::filesystem::path ResolvePath( - const string& resource_id) override; + boost::filesystem::path ResolvePath(const string& resource_id) override; void set_fallback_root_path(boost::filesystem::path fallback_root_path) { fallback_root_path_ = fallback_root_path; } diff --git a/src/rime/service.h b/src/rime/service.h index f8023c4dd..3a8b47b88 100644 --- a/src/rime/service.h +++ b/src/rime/service.h @@ -84,7 +84,7 @@ class Service { Deployer& deployer() { return deployer_; } bool disabled() { return !started_ || deployer_.IsMaintenanceMode(); } - static Service& instance(); + RIME_API static Service& instance(); private: Service(); diff --git a/src/rime/setup.cc b/src/rime/setup.cc index 05730a639..eb843e364 100644 --- a/src/rime/setup.cc +++ b/src/rime/setup.cc @@ -28,7 +28,7 @@ namespace rime { #define Q(x) #x RIME_API RIME_MODULE_LIST(kDefaultModules, "default" RIME_EXTRA_MODULES); #undef Q -RIME_MODULE_LIST(kDeployerModules, "deployer"); +RIME_API RIME_MODULE_LIST(kDeployerModules, "deployer"); RIME_MODULE_LIST(kLegacyModules, "legacy"); RIME_REGISTER_MODULE_GROUP(default, "core", "dict", "gears") diff --git a/src/rime/setup.h b/src/rime/setup.h index 7a5cfe19d..f88a9efd7 100644 --- a/src/rime/setup.h +++ b/src/rime/setup.h @@ -12,7 +12,7 @@ namespace rime { RIME_API extern const char* kDefaultModules[]; -extern const char* kDeployerModules[]; +RIME_API extern const char* kDeployerModules[]; extern const char* kLegacyModules[]; RIME_API void LoadModules(const char* module_names[]); diff --git a/src/rime/translation.h b/src/rime/translation.h index 8c690203d..fe241783d 100644 --- a/src/rime/translation.h +++ b/src/rime/translation.h @@ -14,7 +14,7 @@ namespace rime { -class Translation { +class RIME_API Translation { public: Translation() = default; virtual ~Translation() = default; @@ -27,8 +27,7 @@ class Translation { // should it provide the next candidate (negative value, zero) or // should it give up the chance for other translations (positive)? - RIME_API virtual int Compare(an other, - const CandidateList& candidates); + virtual int Compare(an other, const CandidateList& candidates); bool exhausted() const { return exhausted_; } diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 18e3407f7..bb0361cc7 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -17,11 +17,9 @@ target_link_libraries(rime_patch ${rime_library} ${rime_levers_library}) -# msvc doesn't export all symbols -if(NOT (WIN32 AND BUILD_SHARED_LIBS)) - set(rime_console_src "rime_console.cc") add_executable(rime_console ${rime_console_src}) +target_compile_definitions(rime_console PRIVATE RIME_IMPORTS) target_link_libraries(rime_console ${rime_console_deps}) set(rime_dict_manager_src "rime_dict_manager.cc") @@ -33,6 +31,7 @@ target_link_libraries(rime_dict_manager set(rime_deployer_src "rime_deployer.cc") add_executable(rime_deployer ${rime_deployer_src}) +target_compile_definitions(rime_deployer PRIVATE RIME_IMPORTS) target_link_libraries(rime_deployer ${rime_library} ${rime_dict_library} @@ -41,8 +40,6 @@ target_link_libraries(rime_deployer install(TARGETS rime_deployer DESTINATION ${BIN_INSTALL_DIR}) install(TARGETS rime_dict_manager DESTINATION ${BIN_INSTALL_DIR}) -endif() - install(TARGETS rime_patch DESTINATION ${BIN_INSTALL_DIR}) file(COPY ${PROJECT_SOURCE_DIR}/data/minimal/default.yaml