From efed85af7dee651036e4ae2a10dbbc2d07d78255 Mon Sep 17 00:00:00 2001 From: Qijia Liu Date: Fri, 7 Feb 2025 17:44:29 -0500 Subject: [PATCH] build with clang64 (#6) --- .github/workflows/ci.yml | 35 +++++++++++++++++++++++++++++++-- .gitignore | 1 + CMakeLists.txt | 42 ++++++++++++++++++++++++++++------------ fcitx5 | 2 +- patches/fcitx5.patch | 36 ++++++++++++++++++++++++++++++++++ src/CMakeLists.txt | 4 ++++ src/main.cpp | 21 ++++++++++++++++++++ 7 files changed, 126 insertions(+), 15 deletions(-) create mode 100644 patches/fcitx5.patch create mode 100644 src/CMakeLists.txt create mode 100644 src/main.cpp diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e21545a..36e4e83 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,16 +10,21 @@ on: jobs: build-fcitx5: runs-on: windows-2025 + strategy: + fail-fast: false + matrix: + env: [msys, clang64] steps: - uses: actions/checkout@v4 with: submodules: recursive - - name: Install dependencies + - name: Install dependencies (msys) + if: ${{ matrix.env == 'msys' }} run: | C:/msys64/usr/bin/pacman -Syu --noconfirm C:/msys64/usr/bin/pacman -S --noconfirm ` - mingw-w64-ucrt-x86_64-extra-cmake-modules ` + mingw-w64-clang-x86_64-extra-cmake-modules ` cmake ` fmt ` gcc ` @@ -30,12 +35,38 @@ jobs: cp -r its C:/msys64/usr/share/gettext Add-Content $env:GITHUB_PATH "C:/msys64/usr/bin" + - name: Install dependencies (clang) + if: ${{ matrix.env == 'clang64' }} + 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-clang ` + mingw-w64-clang-x86_64-cmake ` + mingw-w64-clang-x86_64-dlfcn ` + mingw-w64-clang-x86_64-fmt ` + mingw-w64-clang-x86_64-libuv ` + mingw-w64-clang-x86_64-pkgconf ` + gettext ` + ninja + mkdir -p C:/msys64/usr/share/gettext + cp -r its C:/msys64/usr/share/gettext + Add-Content $env:GITHUB_PATH "C:/msys64/clang64/bin" + git apply --directory=fcitx5 patches/fcitx5.patch + - name: Build run: | cmake -B build -G Ninja ` -DCMAKE_BUILD_TYPE=Release cmake --build build + - name: Package + if: ${{ matrix.env == 'clang64' }} + env: + DESTDIR: dist + run: | + cmake --install build + - name: Setup tmate session if: ${{ failure() }} uses: mxschmitt/action-tmate@v3 diff --git a/.gitignore b/.gitignore index 9785597..cd00d75 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ build +dist .cache diff --git a/CMakeLists.txt b/CMakeLists.txt index aa96690..d7c7187 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,8 @@ cmake_minimum_required(VERSION 3.27) project(fcitx5-windows VERSION 0.1.0) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + set(CMAKE_CXX_STANDARD 17) option(ENABLE_TESTING_ADDONS "" OFF) @@ -18,18 +20,34 @@ option(USE_SYSTEMD "" OFF) option(ENABLE_XDGAUTOSTART "" OFF) option(ENABLE_EMOJI "" OFF) option(ENABLE_LIBUUID "" OFF) +option(BUILD_SPELL_DICT "" ${CYGWIN}) + +if (CYGWIN) + set(CMAKE_INSTALL_PREFIX /usr) + set(ECM_DIR /clang64/share/ECM/cmake) + add_compile_definitions(-D_GNU_SOURCE) +else() + set(CMAKE_INSTALL_PREFIX C:) + set(ECM_DIR C:/msys64/clang64/share/ECM/cmake) + set(GETTEXT_MSGMERGE_EXECUTABLE C:/msys64/usr/bin/msgmerge.exe) + set(GETTEXT_MSGFMT_EXECUTABLE C:/msys64/usr/bin/msgfmt.exe) +endif() -set(ECM_DIR /ucrt64/share/ECM/cmake) -add_definitions(-DFcitx5Core_EXPORTS -DFcitx5Utils_EXPORTS -D_GNU_SOURCE) add_subdirectory(fcitx5) +target_compile_definitions(Fcitx5Utils PUBLIC -DFcitx5Utils_EXPORTS) +target_compile_definitions(Fcitx5Core PUBLIC -DFcitx5Core_EXPORTS) + +if (CYGWIN) + # exe needs dll in the same directory. + set(FCITX5UTILS_DLL_NAME msys-Fcitx5Utils-2.dll) + set(FCITX5UTILS_COPY "${PROJECT_BINARY_DIR}/fcitx5/src/modules/spell/${FCITX5UTILS_DLL_NAME}") + add_custom_command( + OUTPUT "${FCITX5UTILS_COPY}" + DEPENDS Fcitx5Utils + COMMAND cp "$" "${FCITX5UTILS_COPY}" + ) + add_custom_target(copy_fcitx5utils ALL DEPENDS "${FCITX5UTILS_COPY}") + add_dependencies(spell_en_dict copy_fcitx5utils) +endif() -# exe needs dll in the same directory. -set(FCITX5UTILS_DLL_NAME msys-Fcitx5Utils-2.dll) -set(FCITX5UTILS_COPY "${PROJECT_BINARY_DIR}/fcitx5/src/modules/spell/${FCITX5UTILS_DLL_NAME}") -add_custom_command( - OUTPUT "${FCITX5UTILS_COPY}" - DEPENDS Fcitx5Utils - COMMAND cp "$" "${FCITX5UTILS_COPY}" -) -add_custom_target(copy_fcitx5utils ALL DEPENDS "${FCITX5UTILS_COPY}") -add_dependencies(spell_en_dict copy_fcitx5utils) +add_subdirectory(src) diff --git a/fcitx5 b/fcitx5 index 9b7bb06..7921881 160000 --- a/fcitx5 +++ b/fcitx5 @@ -1 +1 @@ -Subproject commit 9b7bb069e63da378f2f301c3f0f5292d89361ce3 +Subproject commit 79218815deaae2893ea7bdf099a7feb71c12cfd7 diff --git a/patches/fcitx5.patch b/patches/fcitx5.patch new file mode 100644 index 0000000..b2b917e --- /dev/null +++ b/patches/fcitx5.patch @@ -0,0 +1,36 @@ +diff --git a/src/lib/fcitx-utils/standardpath.cpp b/src/lib/fcitx-utils/standardpath.cpp +index 3312214c..c2e7412c 100644 +--- a/src/lib/fcitx-utils/standardpath.cpp ++++ b/src/lib/fcitx-utils/standardpath.cpp +@@ -222,6 +222,7 @@ private: + } + dir = stringutils::joinPath(*home, defaultPath); + } else { ++#ifndef _WIN32 + if (env && strcmp(env, "XDG_RUNTIME_DIR") == 0) { + dir = stringutils::joinPath( + defaultPath, +@@ -232,11 +233,15 @@ private: + } + } + } else { ++#endif + dir = defaultPath; ++#ifndef _WIN32 + } ++#endif + } + } + ++#ifndef _WIN32 + if (!dir.empty() && env && strcmp(env, "XDG_RUNTIME_DIR") == 0) { + struct stat buf; + if (stat(dir.c_str(), &buf) != 0 || buf.st_uid != geteuid() || +@@ -244,6 +249,7 @@ private: + return {}; + } + } ++#endif + return dir; + } + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..4eb2fe5 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,4 @@ +add_executable(Fcitx5 main.cpp) +target_link_libraries(Fcitx5 Fcitx5::Core) + +install(TARGETS Fcitx5 DESTINATION "${FCITX_INSTALL_BINDIR}") diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..cb57403 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,21 @@ +#include +#include +#include + +namespace fcitx { +std::unique_ptr instance; +std::unique_ptr dispatcher; + +void start() { + instance = std::make_unique(0, nullptr); + instance->initialize(); + dispatcher = std::make_unique(); + dispatcher->attach(&instance->eventLoop()); + instance->eventLoop().exec(); +} +} // namespace fcitx + +int main() { + fcitx::start(); + return 0; +}