diff --git a/.github/workflows/linux-build.yml b/.github/workflows/linux-build.yml index 3bc1ca5e3..b9100ed2c 100644 --- a/.github/workflows/linux-build.yml +++ b/.github/workflows/linux-build.yml @@ -25,4 +25,6 @@ jobs: run: ./action-install-linux.sh - name: Build and test - run: make test + run: | + export CMAKE_GENERATOR=Ninja + make test diff --git a/.github/workflows/macos-build.yml b/.github/workflows/macos-build.yml index 44df48e8d..c7724cb04 100644 --- a/.github/workflows/macos-build.yml +++ b/.github/workflows/macos-build.yml @@ -26,9 +26,13 @@ jobs: repository: ${{ inputs.repository }} submodules: recursive + - name: Install ninja-build tool + uses: seanmiddleditch/gha-setup-ninja@v3 + - name: Configure build environment run: | echo git_ref_name="$(git describe --always)" >> $GITHUB_ENV + echo CMAKE_GENERATOR="Ninja" >> $GITHUB_ENV - name: Configure build variant if: contains(inputs.build_variant, '-universal') @@ -71,17 +75,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 b32026f67..54721677c 100644 --- a/.github/workflows/windows-build.yml +++ b/.github/workflows/windows-build.yml @@ -23,11 +23,15 @@ jobs: repository: ${{ inputs.repository }} submodules: recursive + - name: Install ninja-build tool + uses: seanmiddleditch/gha-setup-ninja@v3 + - name: Configure build environment run: | copy env.vs2022.bat env.bat $git_ref_name = git describe --always echo "git_ref_name=$git_ref_name" >> $env:GITHUB_ENV + echo "CMAKE_GENERATOR=Ninja" >> $env:GITHUB_ENV - name: Cache Boost id: cache-boost @@ -65,12 +69,16 @@ jobs: - name: Build dependencies if: steps.cache-deps.outputs.cache-hit != 'true' + env: + CMAKE_GENERATOR: Ninja run: .\build.bat deps - name: Install Rime plugins run: .\action-install-plugins-windows.bat - name: Build and test + env: + CMAKE_GENERATOR: Ninja run: .\build.bat test - name: Create distributable diff --git a/Makefile b/Makefile index 6f5c5f5fa..d19483d0c 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,30 @@ 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 debug install-debug uninstall-debug test-debug: build ?= debug build ?= build @@ -34,6 +58,12 @@ librime: release install-librime: install uninstall-librime: uninstall +ifdef NOPARALLEL +export MAKEFLAGS+=" -j1 " +else +export MAKEFLAGS+=" -j$(( $(nproc) + 1)) " +endif + librime-static: cmake . -B$(build) \ -DCMAKE_INSTALL_PREFIX=$(prefix) \ diff --git a/action-install-linux.sh b/action-install-linux.sh index 8f9a6d072..c8d0a32a3 100755 --- a/action-install-linux.sh +++ b/action-install-linux.sh @@ -17,6 +17,7 @@ sudo apt update -y # 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 ninja-build sudo apt install -y ${dep_packages[@]} make deps/gtest make -C deps/opencc build diff --git a/build.bat b/build.bat index f6b43edda..e3feecaed 100644 --- a/build.bat +++ b/build.bat @@ -194,6 +194,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"^ @@ -209,7 +210,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 @@ -219,7 +220,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 @@ -232,7 +233,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 @@ -241,7 +242,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 @@ -249,7 +250,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 @@ -259,7 +260,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 ) @@ -273,6 +274,7 @@ set rime_cmake_flags=%common_cmake_flags%^ -DENABLE_LOGGING=%enable_logging%^ -DBOOST_USE_CXX11=ON^ -DCMAKE_CONFIGURATION_TYPES="%build_config%"^ + -DCMAKE_BUILD_TYPE="%build_config%"^ -DCMAKE_INSTALL_PREFIX:PATH="%RIME_ROOT%\dist" echo on @@ -284,14 +286,14 @@ 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 + .\Release\rime_test.exe || .\rime_test.exe || goto error popd ) diff --git a/deps.mk b/deps.mk index ac8f6e1bd..bb9b3ab1b 100644 --- a/deps.mk +++ b/deps.mk @@ -3,6 +3,12 @@ rime_root = $(CURDIR) src_dir = $(rime_root)/deps +ifdef NOPARALLEL +export MAKEFLAGS+=" -j1 " +else +export MAKEFLAGS+=" -j$(( $(nproc) + 1)) " +endif + glog: build ?= cmake-build build ?= build diff --git a/env.bat.template b/env.bat.template index cdcb2563f..2a10834cb 100644 --- a/env.bat.template +++ b/env.bat.template @@ -6,10 +6,18 @@ rem REQUIRED: path to Boost source directory if not defined BOOST_ROOT set BOOST_ROOT=%RIME_ROOT%\deps\boost_1_78_0 rem architecture, Visual Studio version and platform toolset -set ARCH=Win32 -set BJAM_TOOLSET=msvc-14.2 -set CMAKE_GENERATOR="Visual Studio 16 2019" -set PLATFORM_TOOLSET=v142 +if not defined CMAKE_GENERATOR ( + set ARCH=Win32 + set BJAM_TOOLSET=msvc-14.2 + set CMAKE_GENERATOR="Visual Studio 16 2019" + set PLATFORM_TOOLSET=v142 +) else ( + set VSVEROPT="-version 16,17" + call "%~dp0env.vswhere.bat" x86 + set VSVEROPT= + set CXX=cl + set CC=cl +) rem OPTIONAL: path to additional build tools rem set DEVTOOLS_PATH=%ProgramFiles%\Git\cmd;%ProgramFiles%\CMake\bin;C:\Python27; diff --git a/env.vs2017_xp.bat b/env.vs2017_xp.bat index bcf4a1e3f..623813a25 100644 --- a/env.vs2017_xp.bat +++ b/env.vs2017_xp.bat @@ -6,10 +6,18 @@ rem REQUIRED: path to Boost source directory if not defined BOOST_ROOT set BOOST_ROOT=%RIME_ROOT%\deps\boost_1_69_0 rem architecture, Visual Studio version and platform toolset -set ARCH=Win32 -set BJAM_TOOLSET=msvc-14.1 -set CMAKE_GENERATOR="Visual Studio 15 2017" -set PLATFORM_TOOLSET=v141_xp +if not defined CMAKE_GENERATOR ( + set ARCH=Win32 + set BJAM_TOOLSET=msvc-14.1 + set CMAKE_GENERATOR="Visual Studio 15 2017" + set PLATFORM_TOOLSET=v141_xp +) else ( + set "VSVEROPT=-version [15.0^,16.0^)" + call ./env.vswhere.bat x86 + set VSVEROPT= + set CXX=cl + set CC=cl +) rem OPTIONAL: path to additional build tools rem set DEVTOOLS_PATH=%ProgramFiles%\Git\cmd;%ProgramFiles%\CMake\bin;C:\Python27; diff --git a/env.vs2019.bat b/env.vs2019.bat index cdcb2563f..e535b4487 100644 --- a/env.vs2019.bat +++ b/env.vs2019.bat @@ -6,10 +6,18 @@ rem REQUIRED: path to Boost source directory if not defined BOOST_ROOT set BOOST_ROOT=%RIME_ROOT%\deps\boost_1_78_0 rem architecture, Visual Studio version and platform toolset -set ARCH=Win32 -set BJAM_TOOLSET=msvc-14.2 -set CMAKE_GENERATOR="Visual Studio 16 2019" -set PLATFORM_TOOLSET=v142 +if not defined CMAKE_GENERATOR ( + set ARCH=Win32 + set BJAM_TOOLSET=msvc-14.2 + set CMAKE_GENERATOR="Visual Studio 16 2019" + set PLATFORM_TOOLSET=v142 +) else ( + set "VSVEROPT=-version [16.0^,17.0^)" + call ./env.vswhere.bat x86 + set VSVEROPT= + set CXX=cl + set CC=cl +) rem OPTIONAL: path to additional build tools rem set DEVTOOLS_PATH=%ProgramFiles%\Git\cmd;%ProgramFiles%\CMake\bin;C:\Python27; diff --git a/env.vs2022.bat b/env.vs2022.bat index 6f9d7c70e..b8a8c3201 100644 --- a/env.vs2022.bat +++ b/env.vs2022.bat @@ -6,10 +6,18 @@ rem REQUIRED: path to Boost source directory if not defined BOOST_ROOT set BOOST_ROOT=%RIME_ROOT%\deps\boost_1_78_0 rem architecture, Visual Studio version and platform toolset -set ARCH=Win32 -set BJAM_TOOLSET=msvc-14.3 -set CMAKE_GENERATOR="Visual Studio 17 2022" -set PLATFORM_TOOLSET=v143 +if not defined CMAKE_GENERATOR ( + set ARCH=Win32 + set BJAM_TOOLSET=msvc-14.3 + set CMAKE_GENERATOR="Visual Studio 17 2022" + set PLATFORM_TOOLSET=v143 +) else ( + set "VSVEROPT=-version [17.0^,18.0^)" + call ./env.vswhere.bat x86 + set VSVEROPT= + set CXX=cl + set CC=cl +) rem OPTIONAL: path to additional build tools rem set DEVTOOLS_PATH=%ProgramFiles%\Git\cmd;%ProgramFiles%\CMake\bin;C:\Python27; diff --git a/env.vswhere.bat b/env.vswhere.bat new file mode 100644 index 000000000..6cb4c667a --- /dev/null +++ b/env.vswhere.bat @@ -0,0 +1,73 @@ +@echo off +rem This file is taken from vim project. +rem To be used on MS-Windows for Visual C++ 2017 or later. +rem See INSTALLpc.txt for information. +rem +rem Usage: +rem For x86 builds run this with "x86" option: +rem msvc-latest x86 +rem For x64 builds run this with "x86_amd64" option or "x64" option: +rem msvc-latest x86_amd64 +rem msvc-latest x64 +rem +rem Optional environment variables: +rem VSWHERE: +rem Full path to vswhere.exe. +rem VSVEROPT: +rem Option to search specific version of Visual Studio. +rem Default: -latest +rem To search VS2017: +rem set "VSVEROPT=-version [15.0^,16.0^)" +rem To search VS2019: +rem set "VSVEROPT=-version [16.0^,17.0^)" +rem To search VS2022: +rem set "VSVEROPT=-version [17.0^,18.0^)" + +if "%VSWHERE%"=="" ( + set "VSWHERE=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" + set VSWHERE_SET=yes +) +if not exist "%VSWHERE%" ( + echo Error: vswhere not found. + set VSWHERE= + set VSWHERE_SET= + exit /b 1 +) + +if "%VSVEROPT%"=="" ( + set VSVEROPT=-latest + set VSVEROPT_SET=yes +) + +rem Search Visual Studio Community, Professional or above. +for /f "usebackq tokens=*" %%i in (`"%VSWHERE%" %VSVEROPT% -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath`) do ( + set InstallDir=%%i +) +if exist "%InstallDir%\VC\Auxiliary\Build\vcvarsall.bat" ( + call "%InstallDir%\VC\Auxiliary\Build\vcvarsall.bat" %* + goto done +) + +rem Search Visual Studio 2017 Express. +rem (Visual Studio 2017 Express uses different component IDs.) +for /f "usebackq tokens=*" %%i in (`"%VSWHERE%" %VSVEROPT% -products Microsoft.VisualStudio.Product.WDExpress -property installationPath`) do ( + set InstallDir=%%i +) +if exist "%InstallDir%\VC\Auxiliary\Build\vcvarsall.bat" ( + call "%InstallDir%\VC\Auxiliary\Build\vcvarsall.bat" %* +) else ( + echo Error: vcvarsall.bat not found. + rem Set ERRORLEVEL to 1. + call +) + +:done +if "%VSWHERE_SET%"=="yes" ( + set VSWHERE= + set VSWHERE_SET= +) +if "%VSVEROPT_SET%"=="yes" ( + set VSVEROPT= + set VSVEROPT_SET= +) +set InstallDir=