Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into test
Browse files Browse the repository at this point in the history
  • Loading branch information
groverlynn committed Oct 8, 2023
2 parents dff8402 + 8dd031f commit eb6ff01
Show file tree
Hide file tree
Showing 62 changed files with 942 additions and 711 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
19 changes: 12 additions & 7 deletions .github/workflows/linux-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,27 @@ jobs:
strategy:
fail-fast: false
matrix:
compiler: [g++, clang]
compiler: [gcc, clang]
include:
- compiler: gcc
cxx_compiler: g++
- compiler: clang
cxx_compiler: clang++
env:
CC: ${{ matrix.compiler }}
CXX: ${{ matrix.cxx_compiler }}

steps:
- name: Checkout last commit
uses: actions/checkout@v4
with:
repository: ${{ inputs.repository }}
submodules: recursive

- name: Use clang
if: ${{ matrix.compiler == 'clang' }}
run: |
echo "CC=/usr/bin/clang" >> $GITHUB_ENV
echo "CXX=/usr/bin/clang++" >> $GITHUB_ENV
- name: Install dependency
run: ./action-install-linux.sh

- name: Build and test
run: make test
env:
CMAKE_GENERATOR: Ninja
9 changes: 5 additions & 4 deletions .github/workflows/macos-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ jobs:

- name: Configure build environment
run: |
brew install llvm
brew install llvm ninja
echo "CMAKE_GENERATOR=Ninja" >> $GITHUB_ENV
echo "/usr/local/opt/llvm/bin" >> $GITHUB_PATH
echo git_ref_name="$(git describe --always)" >> $GITHUB_ENV
Expand Down Expand Up @@ -73,17 +74,17 @@ jobs:

- name: Build dependencies
if: steps.cache-deps.outputs.cache-hit != 'true'
run: make xcode/deps
run: make deps

- name: Install Rime plugins
run: ./action-install-plugins-macos.sh

- name: Build and test
run: make xcode/test
run: make test

- name: Create distributable
run: |
make xcode/dist
make install
tar -cjvf rime-${{ env.git_ref_name }}-${{ runner.os }}.tar.bz2 \
dist version-info.txt
tar -cjvf rime-deps-${{ env.git_ref_name }}-${{ runner.os }}.tar.bz2 \
Expand Down
68 changes: 47 additions & 21 deletions .github/workflows/windows-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,41 @@ jobs:
BOOST_ROOT: ${{ github.workspace }}\deps\boost_1_83_0
build_script: ${{ matrix.compiler == 'msvc' && './build.bat' || './build-clang.bat' }}
RIME_PLUGINS: ${{ inputs.rime_plugins }}

steps:
- name: Checkout last commit
uses: actions/checkout@v4
with:
repository: ${{ inputs.repository }}
submodules: recursive

- name: Configure MSVC
- name: Create env.bat
if: ${{ matrix.compiler == 'msvc' }}
run: |
copy env.vs2022.bat env.bat
$envfile = ".\env.bat"
$envcontent = @"
set RIME_ROOT=%CD%
if not defined BOOST_ROOT set BOOST_ROOT=%RIME_ROOT%\deps\boost_1_83_0
set CXX=cl
set CC=cl
set CMAKE_GENERATOR=Ninja
"@
Set-Content -Path $envfile -Value $envcontent
cat $envfile
- name: Configure MSVC
if: ${{ matrix.compiler == 'msvc' }}
uses: ilammy/msvc-dev-cmd@v1
with:
arch: x86

- name: Configure Ninja
run: pip install ninja

- name: Configure clang
if: ${{ matrix.compiler == 'clang' }}
run: |
choco upgrade -y llvm
pip install ninja
run: choco upgrade -y llvm

- name: Configure build environment
run: |
Expand Down Expand Up @@ -120,26 +138,33 @@ jobs:
shell: msys2 {0}

steps:
- name: Setup MSYS2
- name: Install dependencies with MSYS2
uses: msys2/setup-msys2@v2

with:
release: false
update: true
msystem: UCRT64
install: >-
git
base-devel
mingw-w64-ucrt-x86_64-boost
mingw-w64-ucrt-x86_64-glog
mingw-w64-ucrt-x86_64-gtest
mingw-w64-ucrt-x86_64-yaml-cpp
mingw-w64-ucrt-x86_64-leveldb
mingw-w64-ucrt-x86_64-marisa
mingw-w64-ucrt-x86_64-opencc
pacboy: >-
toolchain:p
cmake:p
ninja:p
- run: git config --global core.autocrlf input
- name: Checkout last commit
uses: actions/checkout@v4
with:
repository: ${{ inputs.repository }}

- name: Install dependencies
run: |
pacman -S --noconfirm git 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: Configure build environment
run: |
echo git_ref_name="$(git describe --always)" >> $GITHUB_ENV
Expand All @@ -158,7 +183,8 @@ jobs:
-DBUILD_SHARED_LIBS:BOOL=ON
cmake --build build
cmake --install build
cd build/test && cp ../lib/librime.dll . && ./rime_test
cd build && cp ./lib/librime.dll ./test
ctest --output-on-failure
- name: Create distributable
run: |
Expand Down
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
url = https://github.com/google/googletest.git
[submodule "marisa-trie"]
path = deps/marisa-trie
url = https://github.com/s-yata/marisa-trie.git
url = https://github.com/rime/marisa-trie.git
[submodule "opencc"]
path = deps/opencc
url = https://github.com/groverlynn/OpenCC.git
Expand Down
19 changes: 9 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set(CMAKE_USER_MAKE_RULES_OVERRIDE_CXX ${CMAKE_CURRENT_SOURCE_DIR}/cmake/cxx_fla

cmake_minimum_required(VERSION 3.12)
project(rime)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD 17)

set(rime_version 1.9.0)
set(rime_soversion 1)
Expand All @@ -20,11 +20,11 @@ option(BUILD_SAMPLE "Build sample Rime plugin" OFF)
option(BUILD_TEST "Build and run tests" ON)
option(BUILD_SEPARATE_LIBS "Build separate rime-* libraries" OFF)
option(ENABLE_LOGGING "Enable logging with google-glog library" ON)
option(BOOST_USE_SIGNALS2 "Boost use signals2 instead of signals" ON)
option(ENABLE_ASAN "Enable Address Sanitizer (Unix Only)" OFF)
option(INSTALL_PRIVATE_HEADERS "Install private headers (usually needed for externally built Rime plugins)" OFF)
option(ENABLE_EXTERNAL_PLUGINS "Enable loading of externally built Rime plugins (from directory set by RIME_PLUGINS_DIR variable)" OFF)
option(ENABLE_THREADING "Enable threading for deployer" ON)
option(ENABLE_TIMESTAMP "Embed timestamp to schema artifacts" ON)

set(RIME_DATA_DIR "${CMAKE_INSTALL_FULL_DATADIR}/rime-data" CACHE STRING "Target directory for Rime data")
set(RIME_PLUGINS_DIR "${CMAKE_INSTALL_FULL_LIBDIR}/rime-plugins" CACHE STRING "Target directory for externally built Rime plugins")
Expand Down Expand Up @@ -58,18 +58,13 @@ if(MSVC)
set(Boost_USE_STATIC_RUNTIME ON)
endif()

set(BOOST_COMPONENTS filesystem regex system)

if(BOOST_USE_SIGNALS2)
set(RIME_BOOST_SIGNALS2 1)
else()
set(BOOST_COMPONENTS ${BOOST_COMPONENTS} signals)
endif()
set(BOOST_COMPONENTS regex)

find_package(Boost 1.74.0 REQUIRED COMPONENTS ${BOOST_COMPONENTS})
if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
link_directories(${Boost_LIBRARY_DIRS})
add_definitions(-DBOOST_DLL_USE_STD_FS)
endif()

if(ENABLE_LOGGING)
Expand Down Expand Up @@ -97,6 +92,10 @@ if(NOT ENABLE_THREADING)
add_definitions(-DRIME_NO_THREADING)
endif()

if(NOT ENABLE_TIMESTAMP)
add_definitions(-DRIME_NO_TIMESTAMP)
endif()

if(BUILD_TEST)
find_package(GTest REQUIRED)
if(GTEST_FOUND)
Expand Down Expand Up @@ -156,7 +155,7 @@ if(MSVC)
endif()

if(UNIX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -Wno-shorten-64-to-32")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
endif()

if (NOT CMAKE_BUILD_PARALLEL_LEVEL)
Expand Down
2 changes: 0 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ RUN apt update && apt install -y \
cmake \
ninja-build \
libboost-dev \
libboost-filesystem-dev \
libboost-regex-dev \
libboost-system-dev \
libboost-locale-dev \
libgoogle-glog-dev \
libgtest-dev \
Expand Down
38 changes: 30 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,34 @@
RIME_ROOT ?= $(CURDIR)

ifeq ($(shell uname),Darwin) # for macOS
prefix ?= $(RIME_ROOT)/dist

ifdef BOOST_ROOT
CMAKE_BOOST_OPTIONS = -DBoost_NO_BOOST_CMAKE=TRUE \
-DBOOST_ROOT="$(BOOST_ROOT)"
endif

# https://cmake.org/cmake/help/latest/variable/CMAKE_OSX_SYSROOT.html
export SDKROOT ?= $(shell xcrun --sdk macosx --show-sdk-path)

# https://cmake.org/cmake/help/latest/envvar/MACOSX_DEPLOYMENT_TARGET.html
export MACOSX_DEPLOYMENT_TARGET ?= 10.15

ifdef BUILD_UNIVERSAL
# https://cmake.org/cmake/help/latest/envvar/CMAKE_OSX_ARCHITECTURES.html
export CMAKE_OSX_ARCHITECTURES = arm64;x86_64
endif

# boost::locale library from homebrew links to homebrewed icu4c libraries
icu_prefix = $(shell brew --prefix)/opt/icu4c

else # for Linux
prefix ?= $(DESTDIR)/usr
endif

ifndef NOPARALLEL
export MAKEFLAGS+=" -j$(( $(nproc) + 1)) "
endif

debug install-debug uninstall-debug test-debug: build ?= debug
build ?= build
Expand All @@ -21,12 +49,6 @@ deps/%:
thirdparty/%:
$(MAKE) -f deps.mk $(@:thirdparty/%=%)

xcode:
$(MAKE) -f xcode.mk

xcode/%:
$(MAKE) -f xcode.mk $(@:xcode/%=%)

clean:
rm -Rf build debug

Expand Down Expand Up @@ -79,7 +101,7 @@ uninstall-debug:
cmake --build $(build) --target remove

test: release
(cd $(build)/test; ./rime_test)
(cd $(build); ctest --output-on-failure)

test-debug: debug
(cd $(build)/test; ./rime_test)
(cd $(build); ctest --output-on-failure)
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ Follow the instructions to build librime on platforms other than Linux:

Build dependencies
---
- compiler with C++14 support
- cmake>=3.10
- compiler with C++17 support
- cmake>=3.12
- libboost>=1.74
- libglog (optional)
- libleveldb
Expand Down Expand Up @@ -80,6 +80,8 @@ Community:
- [PIME](https://github.com/EasyIME/PIME): frontend for Windows
- [Trime](https://github.com/osfans/trime): frontend for Android
- [XIME](https://github.com/stackia/XIME): frontend for macOS
- [My RIME](https://github.com/LibreService/my_rime): frontend for web
- [fcitx5-android](https://github.com/fcitx5-android/fcitx5-android): frontend for Android

Plugins
===
Expand Down
6 changes: 2 additions & 4 deletions action-install-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

dep_packages=(
doxygen
libboost-filesystem-dev
libboost-locale-dev
libboost-regex-dev
libboost-system-dev
libgoogle-glog-dev
libleveldb-dev
libmarisa-dev
Expand All @@ -16,8 +14,8 @@ sudo apt update -y
# fix a package dependency bug in Ubuntu 22.04
# https://bugs.launchpad.net/ubuntu/+source/google-glog/+bug/1991919
# https://github.com/kadalu-tech/pkgs/pull/2/files#r1001042597
sudo apt install -y libunwind-dev
sudo apt install -y ${dep_packages[@]}
sudo apt install -y libunwind-dev ninja-build ${dep_packages[@]}

make deps/gtest
make -C deps/opencc build
sudo env "PATH=$PATH" make -C deps/opencc install
8 changes: 3 additions & 5 deletions build-clang.bat
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ if %build_boost% == 1 (
stage^
--with-locale^
--with-filesystem^
--with-system^
--with-regex || exit
popd
)
Expand Down Expand Up @@ -118,7 +117,7 @@ if %build_deps% == 1 (

echo building marisa.
pushd deps\marisa-trie
cmake .. %deps_cmake_flags% || exit
cmake . %deps_cmake_flags% || exit
cmake --build build || exit
cmake --install build || exit
popd
Expand Down Expand Up @@ -148,8 +147,7 @@ if %build_librime% == 1 (
)

if "%build_test%" == "ON" (
copy /y dist\lib\rime.dll build\test
pushd build\test
.\rime_test.exe || exit
pushd build
ctest --output-on-failure
popd
)
Loading

0 comments on commit eb6ff01

Please sign in to comment.