Skip to content

Add Windows workflow #1351

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
pull_request:
branches:
- master
workflow_dispatch:

jobs:
clang-format:
Expand Down Expand Up @@ -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
3 changes: 1 addition & 2 deletions src/lib/fcitx-utils/fs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 26 additions & 13 deletions src/lib/fcitx-utils/library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,18 @@
#include <cerrno>
#include <cstdlib>
#include <cstring>
#include <filesystem>
#include <functional>
#include <memory>
#include <string>
#include <utility>
#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 <sys/mman.h>
Expand All @@ -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() {
Expand All @@ -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<fcitx::LibraryLoadHint> loadFlag_;
};

Library::Library(const std::string &path)
: Library(std::filesystem::path(path)) {}

Library::Library(const std::filesystem::path &path)
: d_ptr(std::make_unique<LibraryPrivate>(path)) {}

FCITX_DEFINE_DEFAULT_DTOR_AND_MOVE(Library)
Expand Down Expand Up @@ -99,12 +107,13 @@ bool Library::load(Flags<fcitx::LibraryLoadHint> 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();
Expand Down Expand Up @@ -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;
}
Expand All @@ -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
Expand All @@ -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;
}
}
Expand All @@ -200,8 +210,6 @@ bool Library::findData(const char *slug, const char *magic, size_t lenOfMagic,
#endif
} while (false);

close(fd);

return result;
}

Expand All @@ -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_;
}
Expand Down
5 changes: 4 additions & 1 deletion src/lib/fcitx-utils/library.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
/// \brief Class to handler dynamic library.

#include <cstddef>
#include <filesystem>
#include <functional>
#include <memory>
#include <string>
Expand All @@ -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;
Expand All @@ -46,6 +48,7 @@ class FCITXUTILS_EXPORT Library {
const std::function<void(const char *data)> &parser);
std::string error();
const std::string &path() const;
const std::filesystem::path &fspath() const;

template <typename Func>
static auto toFunction(void *ptr) {
Expand Down
10 changes: 5 additions & 5 deletions src/lib/fcitx-utils/misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
6 changes: 4 additions & 2 deletions src/lib/fcitx-utils/standardpath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <unistd.h>
#include <algorithm>
#include <atomic>
#include <cassert>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
Expand All @@ -21,6 +22,7 @@
#include <functional>
#include <map>
#include <memory>
#include <optional>
#include <stdexcept>
#include <string>
#include <string_view>
Expand Down Expand Up @@ -670,7 +672,7 @@ std::map<std::string, std::string> 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));
Expand All @@ -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) {
Expand Down
46 changes: 28 additions & 18 deletions src/lib/fcitx-utils/standardpaths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include <algorithm>
#include <atomic>
#include <cassert>
#include <chrono>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
Expand All @@ -37,6 +36,7 @@
#include <vector>
#include <ranges>
#include <span>
#include "fcitx-utils/unixfd.h"
#include "config.h" // IWYU pragma: keep
#include "environ.h"
#include "fs.h"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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<UnixFD>
StandardPaths::openAll(StandardPathsType type,
const std::filesystem::path &path,
Expand All @@ -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;
}
Expand All @@ -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()));
Expand All @@ -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;
}

Expand Down
3 changes: 3 additions & 0 deletions src/lib/fcitx-utils/standardpaths.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<UnixFD>
Expand Down
2 changes: 1 addition & 1 deletion src/lib/fcitx-utils/stringutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ FCITXUTILS_EXPORT size_t backwardSearch(const std::string &haystack,

/// \brief Join a range of string with delim.
template <typename Iter, typename T>
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);
Expand Down
Loading
Loading