Skip to content

Commit c9b1973

Browse files
authored
build with fcitx5 (#3)
1 parent 34c3008 commit c9b1973

File tree

14 files changed

+390
-9
lines changed

14 files changed

+390
-9
lines changed

.github/workflows/ci.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ jobs:
1313
- uses: actions/checkout@v4
1414

1515
- name: Install dependencies
16-
run: brew install swift-format
16+
run: brew install clang-format swift-format
1717

1818
- name: Lint
1919
run: |
20+
find src keyboard -name '*.cpp' -o -name '*.h' | xargs clang-format -Werror --dry-run
2021
swift-format lint -rs src keyboard
2122
2223
build:
@@ -29,10 +30,19 @@ jobs:
2930

3031
steps:
3132
- uses: actions/checkout@v4
33+
with:
34+
submodules: recursive
35+
36+
- name: Install dependencies
37+
run: |
38+
brew install \
39+
extra-cmake-modules
40+
IOS_PLATFORM=SIMULATOR ./install-deps.sh
3241
3342
- name: Build
3443
run: |
35-
cmake -B build -G Xcode \
44+
git apply --directory=fcitx5 patches/fcitx5.patch
45+
PKG_CONFIG_PATH=build/sysroot/usr/lib/pkgconfig cmake -B build -G Xcode \
3646
-DCMAKE_TOOLCHAIN_FILE=cmake/ios.cmake \
3747
-DIOS_PLATFORM=SIMULATOR
3848
cmake --build build --config Release

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.DS_Store
22
build
3+
*.tar.bz2

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "fcitx5"]
2+
path = fcitx5
3+
url = https://github.com/fcitx/fcitx5

CMakeLists.txt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ set(CMAKE_CONFIGURATION_TYPES Debug Release CACHE STRING INTERNAL FORCE)
66
project(fcitx5-ios VERSION 0.1.0 LANGUAGES CXX Swift)
77
set(CMAKE_OSX_DEPLOYMENT_TARGET 15)
88
set(CMAKE_Swift_LANGUAGE_VERSION 5.9)
9+
set(CMAKE_CXX_STANDARD 17)
910

1011
set(BUNDLE_IDENTIFIER "org.fcitx.Fcitx5")
1112
set(BUNDLE_NAME "Fcitx5")
@@ -25,5 +26,31 @@ include(AddSwift)
2526
set(KEYBOARD_NAME "Keyboard")
2627
set(KEYBOARD_LANGUAGE "zh-Hans")
2728

29+
# For dependencies not to be find via pkg-config
30+
set(LibIntl_DIR "build/sysroot/usr/lib/cmake")
31+
find_package(LibIntl)
32+
set(fmt_DIR "build/sysroot/usr/lib/cmake/fmt")
33+
find_package(fmt)
34+
35+
option(ENABLE_TEST "" OFF)
36+
option(ENABLE_COVERAGE "" OFF)
37+
option(ENABLE_ENCHANT "" OFF)
38+
option(ENABLE_X11 "" OFF)
39+
option(ENABLE_WAYLAND "" OFF)
40+
option(ENABLE_DBUS "" OFF)
41+
option(ENABLE_DOC "" OFF)
42+
option(ENABLE_SERVER "" OFF)
43+
option(ENABLE_KEYBOARD "" OFF)
44+
option(USE_SYSTEMD "" OFF)
45+
option(ENABLE_XDGAUTOSTART "" OFF)
46+
option(ENABLE_EMOJI "" OFF)
47+
option(ENABLE_LIBUUID "" OFF)
48+
option(BUILD_SPELL_DICT "" OFF)
49+
50+
find_host_package(PkgConfig)
51+
find_host_package(Gettext)
52+
53+
add_subdirectory(fcitx5)
54+
2855
add_subdirectory(keyboard)
2956
add_subdirectory(src)

cache/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This directory caches tarball of build dependencies
2+
(downloaded from [prebuilder](https://github.com/fcitx-contrib/fcitx5-ios-prebuilder/releases)),
3+
which will be extracted to `build/sysroot/usr`.

cmake/ios.cmake

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@ set (CMAKE_AR ar CACHE FILEPATH "" FORCE)
1414
set (CMAKE_CXX_COMPILER_WORKS TRUE)
1515
set (CMAKE_C_COMPILER_WORKS TRUE)
1616

17+
# Touch the toolchain variable to suppress the "unused variable" warning.
18+
# This happens if CMake is invoked with the same command line the second time.
19+
if(CMAKE_TOOLCHAIN_FILE)
20+
endif()
21+
22+
# Fix for PThread library not in path
23+
set(CMAKE_THREAD_LIBS_INIT "-lpthread")
24+
set(CMAKE_HAVE_THREADS_LIBRARY 1)
25+
set(CMAKE_USE_WIN32_THREADS_INIT 0)
26+
set(CMAKE_USE_PTHREADS_INIT 1)
27+
1728
# All iOS/Darwin specific settings - some may be redundant
1829
set (CMAKE_SHARED_LIBRARY_PREFIX "lib")
1930
set (CMAKE_SHARED_LIBRARY_SUFFIX ".dylib")

fcitx5

Submodule fcitx5 added at 9ab829b

install-deps.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
deps=(
2+
fmt
3+
libintl
4+
libuv
5+
)
6+
7+
EXTRACT_DIR=build/sysroot/usr
8+
mkdir -p $EXTRACT_DIR
9+
10+
if [[ $IOS_PLATFORM == "SIMULATOR" ]]; then
11+
POSTFIX=-$(uname -m)
12+
else
13+
POSTFIX=""
14+
fi
15+
16+
for dep in "${deps[@]}"; do
17+
file=$dep$POSTFIX.tar.bz2
18+
[[ -f cache/$file ]] || wget -P cache https://github.com/fcitx-contrib/fcitx5-ios-prebuilder/releases/download/latest/$file
19+
tar xjvf cache/$file -C $EXTRACT_DIR
20+
done
21+
22+
sed -i '' "s|=/usr/include|=$(pwd)/$EXTRACT_DIR/include|" $EXTRACT_DIR/lib/pkgconfig/libuv.pc
23+
sed -i '' "s|-L\${libdir} -luv|$(pwd)/$EXTRACT_DIR/lib/libuv.a|" $EXTRACT_DIR/lib/pkgconfig/libuv.pc

keyboard/CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@ set_target_properties(keyboard PROPERTIES
55
XCODE_PRODUCT_TYPE "com.apple.product-type.app-extension"
66
)
77

8-
target_include_directories(keyboard PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")
8+
target_include_directories(keyboard PRIVATE
9+
"${CMAKE_CURRENT_SOURCE_DIR}"
10+
"${CMAKE_CURRENT_BINARY_DIR}/../fcitx5"
11+
)
12+
913
target_compile_options(keyboard PUBLIC
1014
"$<$<COMPILE_LANGUAGE:Swift>:-cxx-interoperability-mode=default>"
1115
)
16+
17+
target_link_libraries(keyboard PRIVATE Fcitx5::Core)

keyboard/KeyboardViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class KeyboardViewController: UIInputViewController {
1717
override func viewDidLoad() {
1818
super.viewDidLoad()
1919

20-
logger.error("\(getName())")
20+
startFcitx()
2121

2222
// Perform custom UI setup here
2323
self.nextKeyboardButton = UIButton(type: .system)

0 commit comments

Comments
 (0)