diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 7584c72d2..b7b8032a9 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -7,6 +7,7 @@ on: pull_request: branches: - master + workflow_dispatch: jobs: clang-format: @@ -71,3 +72,34 @@ jobs: ctest --test-dir fcitx5/build - name: CodeQL Analysis uses: github/codeql-action/analyze@v2 + + check-windows: + name: Build on Windows + needs: clang-format + runs-on: windows-2025 + strategy: + fail-fast: false + + steps: + - uses: actions/checkout@v4 + + - name: Install dependencies + run: | + C:/msys64/usr/bin/pacman -Syu --noconfirm + C:/msys64/usr/bin/pacman -S --noconfirm ` + mingw-w64-clang-x86_64-extra-cmake-modules ` + mingw-w64-clang-x86_64-dlfcn ` + mingw-w64-clang-x86_64-libuv ` + mingw-w64-clang-x86_64-clang ` + mingw-w64-clang-x86_64-cmake ` + mingw-w64-clang-x86_64-ninja ` + mingw-w64-clang-x86_64-pkgconf ` + mingw-w64-clang-x86_64-gettext-tools + Add-Content $env:GITHUB_PATH "C:/msys64/clang64/bin" + + - name: Build + uses: fcitx/github-actions@cmake + with: + path: . + cmake-option: >- + -DENABLE_DBUS=Off -DENABLE_X11=Off -DENABLE_WAYLAND=Off -DENABLE_ENCHANT=Off -DENABLE_SERVER=Off -DENABLE_XDGAUTOSTART=Off -DENABLE_LIBUUID=Off -DENABLE_KEYBOARD=Off -DBUILD_SPELL_DICT=Off diff --git a/src/lib/fcitx-utils/fs.cpp b/src/lib/fcitx-utils/fs.cpp index fbcc34400..dae751cac 100644 --- a/src/lib/fcitx-utils/fs.cpp +++ b/src/lib/fcitx-utils/fs.cpp @@ -35,8 +35,7 @@ namespace { int makeDir(const std::filesystem::path &name) { #ifdef _WIN32 - const auto path = utf8::UTF8ToUTF16(name); - return ::_wmkdir(path.data()); + return ::_wmkdir(name.c_str()); #else return ::mkdir(name.c_str(), 0777); #endif diff --git a/src/lib/fcitx-utils/library.cpp b/src/lib/fcitx-utils/library.cpp index aef290d53..b7f1d1db2 100644 --- a/src/lib/fcitx-utils/library.cpp +++ b/src/lib/fcitx-utils/library.cpp @@ -13,14 +13,18 @@ #include #include #include +#include #include #include #include #include #include "config.h" +#include "flags.h" #include "macros.h" #include "misc.h" +#include "standardpaths.h" #include "stringutils.h" +#include "unixfd.h" #ifdef HAVE_SYS_MMAN_H #include @@ -40,7 +44,8 @@ constexpr bool hasRTLDNoDelete = false; class LibraryPrivate { public: - LibraryPrivate(std::string path) : path_(std::move(path)) {} + LibraryPrivate(std::filesystem::path path) + : path_(std::move(path)), pathStr_(path_.string()) {} ~LibraryPrivate() { unload(); } bool unload() { @@ -61,14 +66,17 @@ class LibraryPrivate { handle_ = nullptr; return true; } - - std::string path_; + const std::filesystem::path path_; + const std::string pathStr_; void *handle_ = nullptr; std::string error_; Flags loadFlag_; }; Library::Library(const std::string &path) + : Library(std::filesystem::path(path)) {} + +Library::Library(const std::filesystem::path &path) : d_ptr(std::make_unique(path)) {} FCITX_DEFINE_DEFAULT_DTOR_AND_MOVE(Library) @@ -99,12 +107,13 @@ bool Library::load(Flags hint) { if (hint & LibraryLoadHint::NewNameSpace) { // allow dlopen self d->handle_ = dlmopen( - LM_ID_NEWLM, !d->path_.empty() ? d->path_.c_str() : nullptr, flag); + LM_ID_NEWLM, + !d->path_.empty() ? d->path_.string().c_str() : nullptr, flag); } else #endif { - d->handle_ = - dlopen(!d->path_.empty() ? d->path_.c_str() : nullptr, flag); + d->handle_ = dlopen( + !d->path_.empty() ? d->path_.string().c_str() : nullptr, flag); } if (!d->handle_) { d->error_ = dlerror(); @@ -153,8 +162,8 @@ bool Library::findData(const char *slug, const char *magic, size_t lenOfMagic, return true; } - int fd = open(d->path_.c_str(), O_RDONLY); - if (fd < 0) { + UnixFD fd = StandardPaths::openPath(d->path_); + if (!fd.isValid()) { d->error_ = strerror(errno); return false; } @@ -163,14 +172,15 @@ bool Library::findData(const char *slug, const char *magic, size_t lenOfMagic, bool result = false; do { struct stat statbuf; - int statresult = fstat(fd, &statbuf); + int statresult = fstat(fd.fd(), &statbuf); if (statresult < 0) { d->error_ = strerror(errno); break; } void *data = nullptr; #ifdef HAVE_SYS_MMAN_H - data = mmap(nullptr, statbuf.st_size, PROT_READ, MAP_PRIVATE, fd, 0); + data = + mmap(nullptr, statbuf.st_size, PROT_READ, MAP_PRIVATE, fd.fd(), 0); void *needunmap = nullptr; needunmap = data; #endif @@ -180,7 +190,7 @@ bool Library::findData(const char *slug, const char *magic, size_t lenOfMagic, if (!data) { break; } - if (read(fd, data, statbuf.st_size) != statbuf.st_size) { + if (read(fd.fd(), data, statbuf.st_size) != statbuf.st_size) { break; } } @@ -200,8 +210,6 @@ bool Library::findData(const char *slug, const char *magic, size_t lenOfMagic, #endif } while (false); - close(fd); - return result; } @@ -219,6 +227,11 @@ bool Library::isNewNamespaceSupported() { } const std::string &Library::path() const { + FCITX_D(); + return d->pathStr_; +} + +const std::filesystem::path &Library::fspath() const { FCITX_D(); return d->path_; } diff --git a/src/lib/fcitx-utils/library.h b/src/lib/fcitx-utils/library.h index e11d84ebd..b44488be9 100644 --- a/src/lib/fcitx-utils/library.h +++ b/src/lib/fcitx-utils/library.h @@ -13,6 +13,7 @@ /// \brief Class to handler dynamic library. #include +#include #include #include #include @@ -35,7 +36,8 @@ class LibraryPrivate; class FCITXUTILS_EXPORT Library { public: - Library(const std::string &path = {}); + explicit Library(const std::string &path); + explicit Library(const std::filesystem::path &path = {}); FCITX_DECLARE_VIRTUAL_DTOR_MOVE(Library); bool loaded() const; @@ -46,6 +48,7 @@ class FCITXUTILS_EXPORT Library { const std::function &parser); std::string error(); const std::string &path() const; + const std::filesystem::path &fspath() const; template static auto toFunction(void *ptr) { diff --git a/src/lib/fcitx-utils/misc.h b/src/lib/fcitx-utils/misc.h index a0f3b52eb..2ad6d558e 100644 --- a/src/lib/fcitx-utils/misc.h +++ b/src/lib/fcitx-utils/misc.h @@ -152,7 +152,7 @@ FCITXUTILS_EXPORT bool isInFlatpak(); * * @since 5.1.2 */ -FCITXUTILS_EXPORT constexpr inline bool isAndroid() { +constexpr bool isAndroid() { #if defined(ANDROID) || defined(__ANDROID__) return true; #else @@ -165,7 +165,7 @@ FCITXUTILS_EXPORT constexpr inline bool isAndroid() { * * @since 5.1.7 */ -FCITXUTILS_EXPORT constexpr inline bool isApple() { +constexpr bool isApple() { #if defined(__APPLE__) return true; #else @@ -178,7 +178,7 @@ FCITXUTILS_EXPORT constexpr inline bool isApple() { * * @since 5.1.12 */ -FCITXUTILS_EXPORT constexpr inline bool isEmscripten() { +constexpr bool isEmscripten() { #if defined(__EMSCRIPTEN__) return true; #else @@ -187,11 +187,11 @@ FCITXUTILS_EXPORT constexpr inline bool isEmscripten() { } /** - * Util function that returns whether it is compile against emscripten. + * Util function that returns whether it is compile against Windows. * * @since 5.1.13 */ -FCITXUTILS_EXPORT constexpr inline bool isWindows() { +constexpr bool isWindows() { #if defined(_WIN32) return true; #else diff --git a/src/lib/fcitx-utils/standardpath.cpp b/src/lib/fcitx-utils/standardpath.cpp index 46c81254f..4d8b30cf5 100644 --- a/src/lib/fcitx-utils/standardpath.cpp +++ b/src/lib/fcitx-utils/standardpath.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -21,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -670,7 +672,7 @@ std::map StandardPath::locateWithFilter( scanFiles(type, path, [&result, &filter](const std::string &path, const std::string &dir, bool isUser) { - if (!result.count(path) && filter(path, dir, isUser)) { + if (!result.contains(path) && filter(path, dir, isUser)) { auto fullPath = constructPath(dir, path); if (fs::isreg(fullPath)) { result.emplace(path, std::move(fullPath)); @@ -691,7 +693,7 @@ StandardPathFileMap StandardPath::multiOpenFilter( scanFiles(type, path, [&result, flags, &filter](const std::string &path, const std::string &dir, bool isUser) { - if (!result.count(path) && filter(path, dir, isUser)) { + if (!result.contains(path) && filter(path, dir, isUser)) { auto fullPath = constructPath(dir, path); int fd = ::open(fullPath.c_str(), flags); if (fd >= 0) { diff --git a/src/lib/fcitx-utils/standardpaths.cpp b/src/lib/fcitx-utils/standardpaths.cpp index 0013a8e0c..f4de4b36e 100644 --- a/src/lib/fcitx-utils/standardpaths.cpp +++ b/src/lib/fcitx-utils/standardpaths.cpp @@ -13,7 +13,6 @@ #include #include #include -#include #include #include #include @@ -37,6 +36,7 @@ #include #include #include +#include "fcitx-utils/unixfd.h" #include "config.h" // IWYU pragma: keep #include "environ.h" #include "fs.h" @@ -213,7 +213,7 @@ class StandardPathsPrivate { if (!pathOrig.has_filename() || skipUserPath_) { return {}; } - std::string fullPathOrig; + std::filesystem::path fullPathOrig; if (pathOrig.is_absolute()) { fullPathOrig = pathOrig; } else { @@ -474,20 +474,28 @@ UnixFD StandardPaths::open(StandardPathsType type, std::filesystem::path *outPath) const { FCITX_D(); UnixFD retFD; - d->scanDirectories( - type, path, modes, [&retFD, outPath](std::filesystem::path fullPath) { - retFD.give(::open(fullPath.string().c_str(), O_RDONLY)); - if (!retFD.isValid()) { - return true; - } - if (outPath) { - *outPath = std::move(fullPath); - } - return false; - }); + d->scanDirectories(type, path, modes, + [&retFD, outPath](std::filesystem::path fullPath) { + retFD = openPath(fullPath); + if (!retFD.isValid()) { + return true; + } + if (outPath) { + *outPath = std::move(fullPath); + } + return false; + }); return retFD; } +UnixFD StandardPaths::openPath(const std::filesystem::path &path) { +#ifdef _WIN32 + return UnixFD::own(::_wopen(path.c_str(), O_RDONLY)); +#else + return UnixFD::own(::open(path.c_str(), O_RDONLY)); +#endif +} + std::vector StandardPaths::openAll(StandardPathsType type, const std::filesystem::path &path, @@ -500,8 +508,7 @@ StandardPaths::openAll(StandardPathsType type, } d->scanDirectories(type, path, modes, [&retFDs, outPaths](std::filesystem::path fullPath) { - UnixFD fd; - fd.give(::open(fullPath.string().c_str(), O_RDONLY)); + UnixFD fd = StandardPaths::openPath(fullPath); if (!fd.isValid()) { return true; } @@ -526,9 +533,8 @@ bool StandardPaths::safeSave(StandardPathsType type, if (callback(file.fd())) { // sync first. #ifdef _WIN32 - auto wfile = utf8::UTF8ToUTF16(file.tempPath()); - ::_wchmod(wfile.data(), 0666 & ~(d->umask())); - _commit(fd_.fd()); + ::_wchmod(path.c_str(), 0666 & ~(d->umask())); + _commit(file.fd()); #else // close it fchmod(file.fd(), 0666 & ~(d->umask())); @@ -541,7 +547,11 @@ bool StandardPaths::safeSave(StandardPathsType type, } catch (const std::exception &e) { FCITX_ERROR() << "Failed to write file: " << fullPathOrig << e.what(); } +#ifdef _WIN32 + _wunlink(path.c_str()); +#else unlink(path.c_str()); +#endif return false; } diff --git a/src/lib/fcitx-utils/standardpaths.h b/src/lib/fcitx-utils/standardpaths.h index 7a658ffb6..43e064575 100644 --- a/src/lib/fcitx-utils/standardpaths.h +++ b/src/lib/fcitx-utils/standardpaths.h @@ -143,6 +143,9 @@ class FCITXUTILS_EXPORT StandardPaths { StandardPathsModes modes = StandardPathsMode::Default, std::filesystem::path *outPath = nullptr) const; + /** \brief Open the path for read. */ + static UnixFD openPath(const std::filesystem::path &path); + /** \brief Open the all matched and file for read. */ std::vector diff --git a/src/lib/fcitx-utils/stringutils.h b/src/lib/fcitx-utils/stringutils.h index b1e8a6263..0ae85b844 100644 --- a/src/lib/fcitx-utils/stringutils.h +++ b/src/lib/fcitx-utils/stringutils.h @@ -105,7 +105,7 @@ FCITXUTILS_EXPORT size_t backwardSearch(const std::string &haystack, /// \brief Join a range of string with delim. template -FCITXUTILS_EXPORT std::string join(Iter start, Iter end, T &&delim) { +inline std::string join(Iter start, Iter end, T &&delim) { std::string result; if (start != end) { result += (*start); diff --git a/src/lib/fcitx/addoninstance.h b/src/lib/fcitx/addoninstance.h index fa63c1c9d..19b8779af 100644 --- a/src/lib/fcitx/addoninstance.h +++ b/src/lib/fcitx/addoninstance.h @@ -163,6 +163,12 @@ class FCITXCORE_EXPORT AddonInstance { }; } // namespace fcitx +#if defined(_WIN32) +#define FCITX_ADDON_EXPORT __declspec(dllexport) +#else +#define FCITX_ADDON_EXPORT __attribute__((visibility("default"))) +#endif + #define FCITX_ADDON_DECLARE_FUNCTION(NAME, FUNCTION, SIGNATURE...) \ namespace fcitx { \ template <> \ @@ -194,7 +200,7 @@ class FCITXCORE_EXPORT AddonInstance { #define FCITX_ADDON_FACTORY(ClassName) \ extern "C" { \ - FCITXCORE_EXPORT ::fcitx::AddonFactory *fcitx_addon_factory_instance() { \ + FCITX_ADDON_EXPORT ::fcitx::AddonFactory *fcitx_addon_factory_instance() { \ static ClassName factory; \ return &factory; \ } \ @@ -202,7 +208,7 @@ class FCITXCORE_EXPORT AddonInstance { #define FCITX_ADDON_FACTORY_V2(AddonName, ClassName) \ extern "C" { \ - FCITXCORE_EXPORT ::fcitx::AddonFactory * \ + FCITX_ADDON_EXPORT ::fcitx::AddonFactory * \ fcitx_addon_factory_instance_##AddonName() { \ static ClassName factory; \ return &factory; \ diff --git a/src/lib/fcitx/addonmanager.cpp b/src/lib/fcitx/addonmanager.cpp index 54fb319ee..ab4e36f40 100644 --- a/src/lib/fcitx/addonmanager.cpp +++ b/src/lib/fcitx/addonmanager.cpp @@ -22,7 +22,6 @@ #include "fcitx-utils/misc_p.h" #include "fcitx-utils/semver.h" #include "fcitx-utils/standardpaths.h" -#include "fcitx-utils/unixfd.h" #include "addoninfo.h" #include "addoninstance.h" #include "addoninstance_p.h" @@ -268,7 +267,7 @@ void AddonManager::load(const std::unordered_set &enabled, bool disableAll = disabled.contains("all"); for (const auto &[fileName, fullName] : fileNames) { // remove .conf - std::string name = fileName.stem(); + std::string name = fileName.stem().string(); if (name == "core") { FCITX_ERROR() << "\"core\" is not a valid addon name."; continue; @@ -278,8 +277,7 @@ void AddonManager::load(const std::unordered_set &enabled, } RawConfig config; - UnixFD fd = UnixFD::own(open(fullName.c_str(), O_RDONLY)); - readFromIni(config, fd.fd()); + readAsIni(config, StandardPathsType::PkgData, fullName); // override configuration auto addon = std::make_unique(name, config); diff --git a/src/lib/fcitx/icontheme.cpp b/src/lib/fcitx/icontheme.cpp index b9067b035..56b0b8ac8 100644 --- a/src/lib/fcitx/icontheme.cpp +++ b/src/lib/fcitx/icontheme.cpp @@ -207,7 +207,7 @@ class IconThemeCache { #ifdef _WIN32 FCITX_UNUSED(filename); #else - auto fd = UnixFD::own(open(filename.string().c_str(), O_RDONLY)); + auto fd = StandardPaths::openPath(filename); if (!fd.isValid()) { return; } @@ -545,7 +545,8 @@ class IconThemePrivate : QPtrHolder { const IconThemeDirectory &directory, std::filesystem::path baseDir) -> std::filesystem::path { baseDir = baseDir / directory.path(); - if (!fs::isdir(baseDir)) { + std::error_code ec; + if (!std::filesystem::is_directory(baseDir, ec)) { return {}; } @@ -592,7 +593,7 @@ class IconThemePrivate : QPtrHolder { } auto minSize = std::numeric_limits::max(); - std::string closestFilename; + std::filesystem::path closestFilename; for (const auto &baseDir : baseDirs_) { bool hasCache = false; @@ -646,9 +647,10 @@ class IconThemePrivate : QPtrHolder { std::visit( VariantOverload{ [&](const StandardPath &sppath) { - path = sppath.locate(StandardPath::Type::Data, - std::filesystem::path("icons") / - (iconname + ext)); + path = sppath.locate( + StandardPath::Type::Data, + (std::filesystem::path("icons") / (iconname + ext)) + .string()); }, [&](const StandardPaths &sppath) { path = sppath.locate(StandardPathsType::Data, @@ -665,7 +667,8 @@ class IconThemePrivate : QPtrHolder { } void addBaseDir(const std::filesystem::path &path) { - if (!fs::isdir(path)) { + std::error_code ec; + if (!std::filesystem::is_directory(path, ec)) { return; } baseDirs_.emplace_back( @@ -738,14 +741,15 @@ IconTheme::IconTheme(const std::string &name, IconTheme *parent, FCITX_D(); auto files = standardPath.openAll( StandardPath::Type::Data, - std::filesystem::path("icons") / name / "index.theme", O_RDONLY); + (std::filesystem::path("icons") / name / "index.theme").string(), + O_RDONLY); RawConfig config; for (auto &file : files | std::views::reverse) { readFromIni(config, file.fd()); } auto path = d->home_ / ".icons" / name / "index.theme"; - auto fd = UnixFD::own(open(path.c_str(), O_RDONLY)); + auto fd = StandardPaths::openPath(path); if (fd.fd() >= 0) { readFromIni(config, fd.fd()); } @@ -774,8 +778,8 @@ IconTheme::IconTheme(const std::string &name, IconTheme *parent, readFromIni(config, file.fd()); } auto path = d->home_ / ".icons" / name / "index.theme"; - auto fd = UnixFD::own(open(path.string().c_str(), O_RDONLY)); - if (fd.fd() >= 0) { + auto fd = StandardPaths::openPath(path); + if (fd.isValid()) { readFromIni(config, fd.fd()); } @@ -805,15 +809,16 @@ FCITX_DEFINE_READ_ONLY_PROPERTY_PRIVATE(IconTheme, std::string, example); std::string IconTheme::findIcon(const std::string &iconName, unsigned int desiredSize, int scale, const std::vector &extensions) { - return std::as_const(*this).findIconPath(iconName, desiredSize, scale, - extensions); + return std::as_const(*this) + .findIconPath(iconName, desiredSize, scale, extensions) + .string(); } std::string IconTheme::findIcon(const std::string &iconName, unsigned int desiredSize, int scale, const std::vector &extensions) const { - return findIconPath(iconName, desiredSize, scale, extensions); + return findIconPath(iconName, desiredSize, scale, extensions).string(); } std::filesystem::path @@ -884,7 +889,7 @@ std::string IconTheme::defaultIconThemeName() { std::filesystem::path(*home) / ".kde/share/config/kdeglobals", "/etc/kde4/kdeglobals"}; for (auto &file : files) { - auto fd = UnixFD::own(open(file.c_str(), O_RDONLY)); + auto fd = StandardPaths::openPath(file); auto theme = getKdeTheme(fd.fd()); if (!theme.empty()) { return theme; diff --git a/src/lib/fcitx/inputmethodmanager.cpp b/src/lib/fcitx/inputmethodmanager.cpp index 2b85ca343..2a94166e9 100644 --- a/src/lib/fcitx/inputmethodmanager.cpp +++ b/src/lib/fcitx/inputmethodmanager.cpp @@ -176,7 +176,7 @@ void InputMethodManagerPrivate::loadStaticEntries( continue; } RawConfig config; - UnixFD fd = UnixFD::own(open(fullName.c_str(), O_RDONLY)); + UnixFD fd = StandardPaths::openPath(fullName); readFromIni(config, fd.fd()); InputMethodInfo imInfo; diff --git a/src/lib/fcitx/instance.cpp b/src/lib/fcitx/instance.cpp index bcf2e99e9..5bf879be6 100644 --- a/src/lib/fcitx/instance.cpp +++ b/src/lib/fcitx/instance.cpp @@ -1938,7 +1938,8 @@ std::string Instance::addonForInputMethod(const std::string &imName) { } void Instance::configure() { - startProcess({StandardPaths::fcitxPath("bindir", "fcitx5-configtool")}); + startProcess( + {StandardPaths::fcitxPath("bindir", "fcitx5-configtool").string()}); } void Instance::configureAddon(const std::string &) {} diff --git a/src/modules/quickphrase/quickphraseprovider.cpp b/src/modules/quickphrase/quickphraseprovider.cpp index 26e712264..427db313f 100644 --- a/src/modules/quickphrase/quickphraseprovider.cpp +++ b/src/modules/quickphrase/quickphraseprovider.cpp @@ -63,7 +63,7 @@ void BuiltInQuickPhraseProvider::reloadConfig() { if (disableFiles.contains(path)) { continue; } - UnixFD fd = UnixFD::own(open(p.second.c_str(), O_RDONLY)); + UnixFD fd = StandardPaths::openPath(p.second); if (fd.isValid()) { load(fd.fd()); } diff --git a/src/server/main.cpp b/src/server/main.cpp index 216a5ef80..9d4ccde4a 100644 --- a/src/server/main.cpp +++ b/src/server/main.cpp @@ -89,9 +89,11 @@ int main(int argc, char *argv[]) { std::vector args; if (isInFlatpak()) { args = {"flatpak-spawn", - StandardPaths::fcitxPath("bindir", "fcitx5"), "-rd"}; + StandardPaths::fcitxPath("bindir", "fcitx5").string(), + "-rd"}; } else { - args = {StandardPaths::fcitxPath("bindir", "fcitx5"), "-r"}; + args = {StandardPaths::fcitxPath("bindir", "fcitx5").string(), + "-r"}; } startProcess(args); } diff --git a/src/ui/classic/theme.cpp b/src/ui/classic/theme.cpp index 2e061eb0a..c29cfa464 100644 --- a/src/ui/classic/theme.cpp +++ b/src/ui/classic/theme.cpp @@ -277,7 +277,7 @@ ThemeImage::ThemeImage(const IconTheme &iconTheme, const std::string &icon, if (!preferTextIcon && !icon.empty()) { std::filesystem::path iconPath = iconTheme.findIconPath(icon, size, 1, gdkPixbufSupportedFormats()); - auto fd = UnixFD::own(open(iconPath.c_str(), O_RDONLY)); + auto fd = StandardPaths::openPath(iconPath); image_.reset(loadImage(fd, iconPath)); if (image_ && cairo_surface_status(image_.get()) != CAIRO_STATUS_SUCCESS) { diff --git a/test/testemoji.cpp b/test/testemoji.cpp index 13b1962b0..60e4ae37c 100644 --- a/test/testemoji.cpp +++ b/test/testemoji.cpp @@ -37,7 +37,7 @@ int main() { pathfilter::extension(".dict")); // Check if all languages are loadable. for (const auto &[name, __] : files) { - std::string lang = name.stem(); + std::string lang = name.stem().string(); FCITX_ASSERT(emoji->call(lang, false)) << "Failed to load " << lang; } diff --git a/test/testlibrary.cpp b/test/testlibrary.cpp index 03fac6d01..375cb68c5 100644 --- a/test/testlibrary.cpp +++ b/test/testlibrary.cpp @@ -6,23 +6,28 @@ */ #include -#include "fcitx-utils/fcitxutils_export.h" #include "fcitx-utils/library.h" #include "fcitx-utils/log.h" #define DATA "AAAAAAAAA" #define MAGIC "MAGIC_TEST_DATA" +#if defined(_WIN32) +#define MY_EXPORT __declspec(dllexport) +#else +#define MY_EXPORT __attribute__((visibility("default"))) +#endif + extern "C" { -FCITXUTILS_EXPORT char magic_test[] = MAGIC DATA; +MY_EXPORT char magic_test[] = MAGIC DATA; -FCITXUTILS_EXPORT int func() { return 0; } +MY_EXPORT int func() { return 0; } } void parser(const char *data) { FCITX_ASSERT(strcmp(data, DATA) == 0); } int main() { - fcitx::Library lib(""); + fcitx::Library lib; FCITX_ASSERT(lib.load(fcitx::LibraryLoadHint::DefaultHint)); FCITX_ASSERT(func == lib.resolve("func")); FCITX_ASSERT(lib.findData("magic_test", MAGIC, strlen(MAGIC), parser)); diff --git a/test/teststandardpaths.cpp b/test/teststandardpaths.cpp index 063301be8..ca761909b 100644 --- a/test/teststandardpaths.cpp +++ b/test/teststandardpaths.cpp @@ -45,9 +45,9 @@ void test_basic() { { auto result = standardPaths.locate(StandardPathsType::PkgData, "addon", pathfilter::extension(".conf")); - std::set names; - std::set expect_names = {"testim.conf", - "testfrontend.conf"}; + std::set names; + std::set expect_names = {"testim.conf", + "testfrontend.conf"}; for (auto &p : result) { names.insert(p.first); } @@ -59,9 +59,9 @@ void test_basic() { auto result = standardPaths.locate(StandardPathsType::PkgData, "addon", pathfilter::extension(".conf"), StandardPathsMode::System); - std::set names; - std::set expect_names = {"testim.conf", - "testfrontend.conf"}; + std::set names; + std::set expect_names = {"testim.conf", + "testfrontend.conf"}; for (auto &p : result) { names.insert(p.first); }