Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try to Use Ninja to Speed Up Build #666

Closed
wants to merge 11 commits into from

Conversation

WhiredPlanck
Copy link
Contributor

Pull request

Issue tracker

Fixes will automatically close the related issue

Fixes # N/A

Feature

Describe feature of pull request

This PR is to use ninja to build the stuffs on Linux and macOS to speed up the build.

Unit test

  • Done

Manual test

  • Done

Code Review

  1. Unit and manual test pass
  2. GitHub Action CI pass
  3. At least one contributor reviews and votes
  4. Can be merged clean without conflicts
  5. PR will be merged by rebase upstream base

Additional Info

@zhaozg
Copy link

zhaozg commented Jun 25, 2023

在 ci 中启用 Ninja 是合理的

但是在 Makefile 将 Ninja 设为 cmake 默认生成, 则要求开发环境中必须要安装 Ninja,是否考虑将这个能力作为一个配置项呢

@WhiredPlanck
Copy link
Contributor Author

WhiredPlanck commented Jun 25, 2023

在 ci 中启用 Ninja 是合理的

但是在 Makefile 将 Ninja 设为 cmake 默认生成, 则要求开发环境中必须要安装 Ninja,是否考虑将这个能力作为一个配置项呢

@zhaozg 确实!你想的很周到,应该允许开发者自由选择。CMake 应该可以通过设定环境变量来选择构建文件生成器,我再完善一下,感谢提议。

不过我认为关键矛盾其实还是因为 ninja 即使在今天用得越来越多,很多系统的提供的默认开发环境还是不提供 ninja。用 ninja 必须要求环境里装 ninja,那其实用 make 其实也必须要求环境里装 make 嘛 ......

@eagleoflqj
Copy link
Member

我认为librime这个make套cmake再make/ninja是不合理的,最外层的make不跨平台,而且在这个PR之前传-j也不会让内层make并行

@WhiredPlanck
Copy link
Contributor Author

我认为librime这个make套cmake再make/ninja是不合理的,最外层的make不跨平台,而且在这个PR之前传-j也不会让内层make并行

没有特殊情况,一般不需要手动传 -j。CMake 作为一个相当现代的构建系统有着完善的并行构建支持,一般不需要手动管理;CMake 生成的 Makefile 比手写的更不容易出现并行构建竞争问题。

Makefile(还有 Ninja 的 build.ninja)本质就是一个基于规则/任务的脚本。用它去控制每个构建任务其实并没有什么不合理。

@eagleoflqj
Copy link
Member

没有特殊情况,一般不需要手动传

可我在master branch make release开了top看真的只用了单线程啊😂

我想表达的是,@zhaozg 的需求其实直接调cmake就好了,用不用ninja/带不带glog之类的随便控制,不然要么把最外层的Makefile加一堆条目,要么得从Makefile往cmake传一堆参数

@WhiredPlanck
Copy link
Contributor Author

@eagleoflqj 看起来我误会了什么,应该是要手动传 -j 的,但是其实你可以通过 export MAKEFLAGS+=" -j<n> " 的方式来传,不一定要在命令后面追加。

@WhiredPlanck WhiredPlanck force-pushed the ninja-build branch 4 times, most recently from 38d7f4f to efcaf18 Compare June 26, 2023 05:41
This is required by non-Visual-Studio makefile generator
The program will not be put in the <build_config> dir if we don't set the makefile generator as Visual Studio stuffs.
@WhiredPlanck WhiredPlanck marked this pull request as ready for review June 26, 2023 08:19
@WhiredPlanck
Copy link
Contributor Author

@lotem This PR is ready for review.

@zhaozg
Copy link

zhaozg commented Jun 26, 2023

It's better that do rebase and combine to ONE commit, will get a clear commit history and avoid many intermediate commit.

@WhiredPlanck
Copy link
Contributor Author

The CI seems to be malfunctioning, I'd like to close the PR, reorganize the commits then reopen.

@WhiredPlanck
Copy link
Contributor Author

@zhaozg @lotem I open a new PR #667 inherited the works from here because I force push the commits to the branch before reopening this PR by mistake. Go to there to start a new review, please.

set CMAKE_GENERATOR="Visual Studio 15 2017"
set PLATFORM_TOOLSET=v141_xp
) else (
set "VSVEROPT=-version [15.0^,16.0^)"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does the else-block do? Why is it on the defined CMAKE_GENERATOR branch?

Copy link
Contributor Author

@WhiredPlanck WhiredPlanck Jul 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If CMAKE_GENERATOR is defined outside the scripts, it may not be Visual Studio xx xxxx. To preserve the original settings, I split out a else-block for non-Visual-Studio generator to run a script which call vswhere.exe to find the Visual Studio's install location and call vcvarsall.bat to set almost all environment variables we need.
In a word, if one don't specify CMAKE_GENERATOR before calling env.bat and build.bat to build, it will use our original settings to build, otherwise the scripts will find and set everything we need and build with the specified generator.

@@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of these envars are not set in the else-branch. That's probably not okay because build.bat uses these variables.

Copy link
Contributor Author

@WhiredPlanck WhiredPlanck Jul 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lotem These envars like ARCH here only make sense when CMAKE_GENERATOR is something like Visual Studio xx xxxx. I think there are enough refactors in `build.bat to adopt these changes.

set CMAKE_GENERATOR="Visual Studio 16 2019"
set PLATFORM_TOOLSET=v142
) else (
set "VSVEROPT=-version [16.0^,17.0^)"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about creating a separate env.bat file with the else branch.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lotem No need actually. Else-block plays the same role with if-block.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this script do?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lotem To find where Visual Studio installed in and set some envars we need.

-DBOOST_ROOT="$(BOOST_ROOT)"
endif

# https://cmake.org/cmake/help/latest/variable/CMAKE_OSX_SYSROOT.html
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These lines repeats scripts in xcode.mk. Can Makefile replace xcode.mk after this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lotem I think the answer is yes. We can merge Makefile and xcode.mk since the latter just specify CMAKE_GENERATOR as Xcode and nothing else is different with the former.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants