-
Notifications
You must be signed in to change notification settings - Fork 657
Add support for precompiled headers #5298
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,14 +21,34 @@ EXE_LINKS_TO = %{link_to_botan} ${LIB_LINKS_TO} %{extra_libs} | |
| SCRIPTS_DIR = %{scripts_dir} | ||
| INSTALLED_LIB_DIR = %{libdir} | ||
|
|
||
| %{if enable_pch} | ||
| rule copy_pch_header | ||
| command = "${PYTHON_EXE}" -c "import shutil, sys; shutil.copyfile(sys.argv[1], sys.argv[2])" "$in" "$out" | ||
|
|
||
| rule compile_pch_lib | ||
| command = %{cxx} %{lib_flags} ${ABI_FLAGS} ${LANG_FLAGS} ${CXXFLAGS} -DBOTAN_IS_BEING_BUILT ${WARN_FLAGS} %{public_include_flags} %{internal_include_flags} %{external_include_flags} %{pch_compile} %{dash_c} $in %{dash_o}$out | ||
|
|
||
| rule compile_pch_exe | ||
| command = %{cxx} ${ABI_FLAGS} ${LANG_FLAGS} ${CXXFLAGS} -DBOTAN_IS_BEING_BUILT ${WARN_FLAGS} %{public_include_flags} %{internal_include_flags} %{external_include_flags} %{pch_compile} %{dash_c} $in %{dash_o}$out | ||
|
|
||
| build %{pch_header_for_lib}: copy_pch_header %{pch_src_header} | ||
|
|
||
| build %{pch_header_for_exe}: copy_pch_header %{pch_src_header} | ||
|
|
||
| build %{pch_path_for_lib}: compile_pch_lib %{pch_header_for_lib} | ||
|
|
||
| build %{pch_path_for_exe}: compile_pch_exe %{pch_header_for_exe} | ||
|
|
||
| %{endif} | ||
|
|
||
| rule compile_lib | ||
| %{if header_deps_out} | ||
| depfile = $out.d | ||
| %{endif} | ||
| %{if ninja_header_deps_style} | ||
| deps = %{ninja_header_deps_style} | ||
| %{endif} | ||
| command = %{cxx} %{lib_flags} ${ABI_FLAGS} ${LANG_FLAGS} ${CXXFLAGS} -DBOTAN_IS_BEING_BUILT ${WARN_FLAGS} %{public_include_flags} %{internal_include_flags} %{external_include_flags} %{header_deps_flag} %{header_deps_out|concat: $out.d} %{dash_c} $in %{dash_o}$out | ||
| command = %{cxx} %{pch_include_for_lib} %{lib_flags} ${ABI_FLAGS} ${LANG_FLAGS} ${CXXFLAGS} -DBOTAN_IS_BEING_BUILT ${WARN_FLAGS} %{public_include_flags} %{internal_include_flags} %{external_include_flags} %{header_deps_flag} %{header_deps_out|concat: $out.d} %{dash_c} $in %{dash_o}$out | ||
|
|
||
| rule compile_exe | ||
| %{if header_deps_out} | ||
|
|
@@ -37,7 +57,7 @@ rule compile_exe | |
| %{if ninja_header_deps_style} | ||
| deps = %{ninja_header_deps_style} | ||
| %{endif} | ||
| command = %{cxx} ${ABI_FLAGS} ${LANG_FLAGS} ${CXXFLAGS} -DBOTAN_IS_BEING_BUILT ${WARN_FLAGS} %{public_include_flags} %{internal_include_flags} %{external_include_flags} %{header_deps_flag} %{header_deps_out|concat: $out.d} %{dash_c} $in %{dash_o}$out | ||
| command = %{cxx} %{pch_include_for_exe} ${ABI_FLAGS} ${LANG_FLAGS} ${CXXFLAGS} -DBOTAN_IS_BEING_BUILT ${WARN_FLAGS} %{public_include_flags} %{internal_include_flags} %{external_include_flags} %{header_deps_flag} %{header_deps_out|concat: $out.d} %{dash_c} $in %{dash_o}$out | ||
|
|
||
| rule compile_example_exe | ||
| %{if header_deps_out} | ||
|
|
@@ -195,6 +215,10 @@ build libs: phony %{library_targets} $ | |
|
|
||
| build docs: phony %{doc_stamp_file} | ||
|
|
||
| %{if enable_pch} | ||
| build pch: phony %{pch_path_for_lib} %{pch_path_for_exe} | ||
| %{endif} | ||
|
|
||
| build clean: clean | ||
|
|
||
| build distclean: distclean | ||
|
|
@@ -211,15 +235,15 @@ build tidy: tidy | |
| # Build Commands | ||
|
|
||
| %{for lib_build_info} | ||
| build %{obj}: compile_lib %{src} | ||
| build %{obj}: compile_lib %{src} | %{pch_target} | ||
| %{endfor} | ||
|
|
||
| %{for cli_build_info} | ||
| build %{obj}: compile_exe %{src} | ||
| build %{obj}: compile_exe %{src} | %{pch_target} | ||
| %{endfor} | ||
|
|
||
| %{for test_build_info} | ||
| build %{obj}: compile_exe %{src} | ||
| build %{obj}: compile_exe %{src} | %{pch_target} | ||
| %{endfor} | ||
|
Comment on lines
237
to
247
|
||
|
|
||
| %{for fuzzer_build_info} | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| /* IWYU pragma: begin_exports */ | ||
|
|
||
| #include <algorithm> | ||
| #include <array> | ||
| #include <bit> | ||
| /* | ||
| * Note: <chrono> is intentionally omitted here, as even instantiating | ||
| * the templates in it from the PCH is so expensive that it is overall | ||
| * faster to not precompile it and accept the cost in the small number of | ||
| * files which continue to use <chrono> | ||
| */ | ||
| #include <concepts> | ||
| #include <cstddef> | ||
| #include <cstdint> | ||
| #include <cstring> | ||
| #include <exception> | ||
| #include <functional> | ||
| #include <iosfwd> | ||
| #include <limits> | ||
| #include <memory> | ||
| #include <optional> | ||
| #include <ranges> | ||
| #include <span> | ||
| #include <sstream> | ||
| #include <stdexcept> | ||
| #include <string> | ||
| #include <string_view> | ||
| #include <tuple> | ||
| #include <type_traits> | ||
| #include <utility> | ||
| #include <variant> | ||
| #include <vector> | ||
|
|
||
| /* IWYU pragma: end_exports */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
compile_exenow injects%{pch_include_for_exe}. However some Ninja build edges usingcompile_exe(e.g. fuzzers, bogo_shim_object, ct_selftest_object) don't have an order-only dependency on the PCH build. In parallel builds this can lead to nondeterministic PCH usage and, in the worst case, attempting to read a partially-written PCH file. Add the same| pchorder-only dependency for allcompile_exeinvocations whenenable_pchis enabled (or ensure these targets don't use the PCH include flag).