Skip to content

Commit

Permalink
ci: Use Ninja Build in CI (rime#718)
Browse files Browse the repository at this point in the history
* add ninja-build on Linux & add support for non-Visual-Studio makefile

* use CI create env.bat for ninja-bulid

* use ilammy/msvc-dev-cmd  configure msvc

* merge the setup in xcode.mk into Makefile

* feat(Makefile,deps.mk): add flag to control parallel build

---------

Co-authored-by: WhiredPlanck <whiredplanck@outlook.com>
Co-authored-by: wxyzh <wxyzhen@live.com>
Co-authored-by: Qijia Liu <liumeo@pku.edu.cn>
  • Loading branch information
4 people authored and graphemecluster committed Sep 23, 2023
1 parent 925eaac commit de8522a
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 124 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/linux-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:
fail-fast: false
matrix:
compiler: [g++, clang]

steps:
- name: Checkout last commit
uses: actions/checkout@v4
Expand All @@ -32,3 +33,5 @@ jobs:

- 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
28 changes: 23 additions & 5 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
34 changes: 28 additions & 6 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.13

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
4 changes: 2 additions & 2 deletions action-install-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,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
22 changes: 14 additions & 8 deletions build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ if defined PLATFORM_TOOLSET (
)
set deps_cmake_flags=%common_cmake_flags%^
-DCMAKE_CONFIGURATION_TYPES:STRING="%build_config%"^
-DCMAKE_BUILD_TYPE:STRING="%build_config%"^
-DCMAKE_CXX_FLAGS_RELEASE:STRING="/MT /O2 /Ob2 /DNDEBUG"^
-DCMAKE_C_FLAGS_RELEASE:STRING="/MT /O2 /Ob2 /DNDEBUG"^
-DCMAKE_CXX_FLAGS_DEBUG:STRING="/MTd /Od"^
Expand All @@ -208,7 +209,7 @@ if %build_deps% == 1 (
-DWITH_GFLAGS:BOOL=OFF^
-DCMAKE_MSVC_RUNTIME_LIBRARY="MultiThreaded$<$<CONFIG:Debug>:Debug>"
if errorlevel 1 goto error
cmake --build cmake-%build_dir% --config %build_config% --target INSTALL
cmake --build cmake-%build_dir% --config %build_config% --target install
if errorlevel 1 goto error
popd

Expand All @@ -218,7 +219,7 @@ if %build_deps% == 1 (
-DLEVELDB_BUILD_BENCHMARKS:BOOL=OFF^
-DLEVELDB_BUILD_TESTS:BOOL=OFF
if errorlevel 1 goto error
cmake --build %build_dir% --config %build_config% --target INSTALL
cmake --build %build_dir% --config %build_config% --target install
if errorlevel 1 goto error
popd

Expand All @@ -231,7 +232,7 @@ if %build_deps% == 1 (
-DYAML_CPP_BUILD_TESTS:BOOL=OFF^
-DYAML_CPP_BUILD_TOOLS:BOOL=OFF
if errorlevel 1 goto error
cmake --build %build_dir% --config %build_config% --target INSTALL
cmake --build %build_dir% --config %build_config% --target install
if errorlevel 1 goto error
popd

Expand All @@ -240,15 +241,15 @@ if %build_deps% == 1 (
cmake . -B%build_dir% %deps_cmake_flags%^
-DBUILD_GMOCK:BOOL=OFF
if errorlevel 1 goto error
cmake --build %build_dir% --config %build_config% --target INSTALL
cmake --build %build_dir% --config %build_config% --target install
if errorlevel 1 goto error
popd

echo building marisa.
pushd deps\marisa-trie
cmake . -B%build_dir% %deps_cmake_flags%
if errorlevel 1 goto error
cmake --build %build_dir% --config %build_config% --target INSTALL
cmake --build %build_dir% --config %build_config% --target install
if errorlevel 1 goto error
popd

Expand All @@ -258,7 +259,7 @@ if %build_deps% == 1 (
-DBUILD_SHARED_LIBS=OFF^
-DBUILD_TESTING=OFF
if errorlevel 1 goto error
cmake --build %build_dir% --config %build_config% --target INSTALL
cmake --build %build_dir% --config %build_config% --target install
if errorlevel 1 goto error
popd
)
Expand All @@ -271,6 +272,7 @@ set rime_cmake_flags=%common_cmake_flags%^
-DBUILD_TEST=%build_test%^
-DENABLE_LOGGING=%enable_logging%^
-DCMAKE_CONFIGURATION_TYPES="%build_config%"^
-DCMAKE_BUILD_TYPE:STRING="%build_config%"^
-DCMAKE_INSTALL_PREFIX:PATH="%RIME_ROOT%\dist"

echo on
Expand All @@ -282,14 +284,18 @@ echo.
echo building librime.
echo.
echo on
cmake --build %build_dir% --config %build_config% --target INSTALL
cmake --build %build_dir% --config %build_config% --target install
@echo off
if errorlevel 1 goto error

if "%build_test%" == "ON" (
copy /y dist\lib\rime.dll build\test
pushd build\test
.\Release\rime_test.exe || goto error
if %CMAKE_GENERATOR% == Ninja (
.\rime_test.exe
) else (
.\Release\rime_test.exe
)
popd
)

Expand Down
4 changes: 4 additions & 0 deletions deps.mk
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
rime_root = $(CURDIR)
src_dir = $(rime_root)/deps

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

glog: build ?= cmake-build
build ?= build

Expand Down
99 changes: 0 additions & 99 deletions xcode.mk

This file was deleted.

0 comments on commit de8522a

Please sign in to comment.