From de8522ad6b7886d1591e234189bbeca8efecbb11 Mon Sep 17 00:00:00 2001 From: wxyzhen Date: Sat, 23 Sep 2023 12:03:14 +0800 Subject: [PATCH] ci: Use Ninja Build in CI (#718) * 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 Co-authored-by: wxyzh Co-authored-by: Qijia Liu --- .github/workflows/linux-build.yml | 3 + .github/workflows/macos-build.yml | 9 +-- .github/workflows/windows-build.yml | 28 ++++++-- Makefile | 34 ++++++++-- action-install-linux.sh | 4 +- build.bat | 22 ++++--- deps.mk | 4 ++ xcode.mk | 99 ----------------------------- 8 files changed, 79 insertions(+), 124 deletions(-) delete mode 100644 xcode.mk diff --git a/.github/workflows/linux-build.yml b/.github/workflows/linux-build.yml index fb74684de2..1cc9b7a5c5 100644 --- a/.github/workflows/linux-build.yml +++ b/.github/workflows/linux-build.yml @@ -14,6 +14,7 @@ jobs: fail-fast: false matrix: compiler: [g++, clang] + steps: - name: Checkout last commit uses: actions/checkout@v4 @@ -32,3 +33,5 @@ jobs: - name: Build and test run: make test + env: + CMAKE_GENERATOR: Ninja diff --git a/.github/workflows/macos-build.yml b/.github/workflows/macos-build.yml index d1c93d9b98..570d1e9d75 100644 --- a/.github/workflows/macos-build.yml +++ b/.github/workflows/macos-build.yml @@ -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 @@ -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 \ diff --git a/.github/workflows/windows-build.yml b/.github/workflows/windows-build.yml index e7f67819b0..a23ceb94cc 100644 --- a/.github/workflows/windows-build.yml +++ b/.github/workflows/windows-build.yml @@ -21,6 +21,7 @@ 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 @@ -28,16 +29,33 @@ jobs: 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: | diff --git a/Makefile b/Makefile index 9d4f94ce6d..34e9c9f18f 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -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 diff --git a/action-install-linux.sh b/action-install-linux.sh index 8f9a6d0726..9e0dcb152d 100755 --- a/action-install-linux.sh +++ b/action-install-linux.sh @@ -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 diff --git a/build.bat b/build.bat index bf2caa98dc..8251b56e3c 100644 --- a/build.bat +++ b/build.bat @@ -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"^ @@ -208,7 +209,7 @@ if %build_deps% == 1 ( -DWITH_GFLAGS:BOOL=OFF^ -DCMAKE_MSVC_RUNTIME_LIBRARY="MultiThreaded$<$: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 @@ -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 @@ -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 @@ -240,7 +241,7 @@ 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 @@ -248,7 +249,7 @@ if %build_deps% == 1 ( 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 @@ -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 ) @@ -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 @@ -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 ) diff --git a/deps.mk b/deps.mk index 587a1557cb..2bcab57ae7 100644 --- a/deps.mk +++ b/deps.mk @@ -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 diff --git a/xcode.mk b/xcode.mk deleted file mode 100644 index cf07f0c4b2..0000000000 --- a/xcode.mk +++ /dev/null @@ -1,99 +0,0 @@ -RIME_ROOT = $(CURDIR) - -dist_dir = $(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 - -debug debug-with-icu test-debug: build ?= debug -build ?= build - -.PHONY: all release debug clean dist distclean test test-debug deps thirdparty \ -release-with-icu debug-with-icu dist-with-icu - -all: release - -release: - cmake . -B$(build) -GXcode \ - -DBUILD_STATIC=ON \ - -DCMAKE_BUILD_WITH_INSTALL_RPATH=ON \ - -DCMAKE_INSTALL_PREFIX="$(dist_dir)" \ - $(CMAKE_BOOST_OPTIONS) - cmake --build $(build) --config Release - -release-with-icu: - cmake . -B$(build) -GXcode \ - -DBUILD_STATIC=ON \ - -DBUILD_WITH_ICU=ON \ - -DCMAKE_BUILD_WITH_INSTALL_RPATH=ON \ - -DCMAKE_INSTALL_PREFIX="$(dist_dir)" \ - -DCMAKE_PREFIX_PATH="$(icu_prefix)" \ - $(CMAKE_BOOST_OPTIONS) - cmake --build $(build) --config Release - -debug: - cmake . -B$(build) -GXcode \ - -DBUILD_STATIC=ON \ - -DBUILD_SEPARATE_LIBS=ON \ - $(CMAKE_BOOST_OPTIONS) - cmake --build $(build) --config Debug - -debug-with-icu: - cmake . -B$(build) -GXcode \ - -DBUILD_STATIC=ON \ - -DBUILD_SEPARATE_LIBS=ON \ - -DBUILD_WITH_ICU=ON \ - -DCMAKE_PREFIX_PATH="$(icu_prefix)" \ - $(CMAKE_BOOST_OPTIONS) - cmake --build $(build) --config Debug - -clean: - rm -rf build > /dev/null 2>&1 || true - rm -rf debug > /dev/null 2>&1 || true - rm build.log > /dev/null 2>&1 || true - rm -f lib/* > /dev/null 2>&1 || true - $(MAKE) -f deps.mk clean-src - -dist: release - cmake --build $(build) --config Release --target install - -dist-with-icu: release-with-icu - cmake --build $(build) --config Release --target install - -distclean: clean - rm -rf "$(dist_dir)" > /dev/null 2>&1 || true - -test: release - (cd $(build)/test; DYLD_LIBRARY_PATH=../lib/Release Release/rime_test) - -test-debug: debug - (cd $(build)/test; Debug/rime_test) - -# `thirdparty` is deprecated in favor of `deps` -deps thirdparty: - $(MAKE) -f deps.mk - -deps/boost thirdparty/boost: - ./install-boost.sh - -deps/%: - $(MAKE) -f deps.mk $(@:deps/%=%) - -thirdparty/%: - $(MAKE) -f deps.mk $(@:thirdparty/%=%)