Skip to content

Commit

Permalink
use @response_files.txt for linking in ninja
Browse files Browse the repository at this point in the history
Response files are a means to work around the limited command line length
particularly on Windows. Instead of listing all to-be-linked object files
on the command line, ninja will write them into a "response file" and
address that in the command using the @something.txt syntax.
  • Loading branch information
reneme committed Oct 2, 2024
1 parent 7f256a0 commit d9e12cc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
4 changes: 4 additions & 0 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ def __init__(self, source_paths, options, modules):
self.handbook_output_dir = os.path.join(self.doc_output_dir, 'handbook')
self.doc_output_dir_doxygen = os.path.join(self.doc_output_dir, 'doxygen') if options.with_doxygen else None
self.doc_module_info = os.path.join(self.build_dir, 'module_info') if options.with_doxygen else None
self.response_file_dir = os.path.join(self.build_dir, 'response_files')

# We split the header include paths into 'public', 'internal' and 'external'
# to allow for better control over what is exposed to each compilation unit.
Expand Down Expand Up @@ -272,6 +273,7 @@ def build_dirs(self):
self.internal_include_dir,
self.external_include_dir,
self.handbook_output_dir,
self.response_file_dir
]
if self.doc_output_dir_doxygen:
out += [self.doc_output_dir_doxygen, self.doc_module_info]
Expand Down Expand Up @@ -1938,6 +1940,7 @@ def _build_info(sources, objects, target_type):

if target_type in ['fuzzer', 'examples']:
exe_basename = os.path.basename(obj_file).replace('.' + osinfo.obj_suffix, osinfo.program_suffix)
info['exe_basename'] = exe_basename

if target_type == 'fuzzer':
info['exe'] = os.path.join(build_paths.fuzzer_output_dir, exe_basename)
Expand Down Expand Up @@ -2210,6 +2213,7 @@ def test_exe_extra_ldflags():
'doc_output_dir': build_paths.doc_output_dir,
'handbook_output_dir': build_paths.handbook_output_dir,
'doc_output_dir_doxygen': build_paths.doc_output_dir_doxygen,
'response_file_dir': build_paths.response_file_dir,

'os': options.os,
'arch': options.arch,
Expand Down
21 changes: 16 additions & 5 deletions src/build-data/ninja.in
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,19 @@ default all
%{if build_static_lib}

rule link_static
command = %{ar_command} %{ar_options} %{ar_output_to}$out $in
rspfile = %{response_file_dir}/static.txt
rspfile_content = $in
command = %{ar_command} %{ar_options} %{ar_output_to}$out @%{response_file_dir}/static.txt

build %{out_dir}/%{static_lib_name}: link_static %{join lib_objs}

%{endif}
%{if build_shared_lib}

rule link_shared
command = %{lib_link_cmd} ${ABI_FLAGS} ${LDFLAGS} $in ${LIB_LINKS_TO} %{output_to_exe}$out
rspfile = %{response_file_dir}/shared.txt
rspfile_content = $in
command = %{lib_link_cmd} ${ABI_FLAGS} ${LDFLAGS} @%{response_file_dir}/shared.txt ${LIB_LINKS_TO} %{output_to_exe}$out

build %{out_dir}/%{shared_lib_name}: link_shared %{join lib_objs}
%{endif}
Expand All @@ -80,15 +84,19 @@ build %{out_dir}/%{soname_patch}: symlink %{out_dir}/%{shared_lib_name}
%{endif}

rule link_cli
command = ${EXE_LINK_CMD} ${ABI_FLAGS} $in ${BUILD_DIR_LINK_PATH} ${LANG_EXE_FLAGS} ${LDFLAGS} ${EXE_LINKS_TO} %{output_to_exe}$out
rspfile = %{response_file_dir}/cli_${cli_name}.txt
rspfile_content = $in
command = ${EXE_LINK_CMD} ${ABI_FLAGS} @%{response_file_dir}/cli_${cli_name}.txt ${BUILD_DIR_LINK_PATH} ${LANG_EXE_FLAGS} ${LDFLAGS} ${EXE_LINKS_TO} %{output_to_exe}$out

rule link_tests
command = ${EXE_LINK_CMD} ${ABI_FLAGS} $in ${BUILD_DIR_LINK_PATH} ${LANG_EXE_FLAGS} ${LDFLAGS} %{test_exe_extra_ldflags} ${EXE_LINKS_TO} %{output_to_exe}$out

rspfile = %{response_file_dir}/tests.txt
rspfile_content = $in
command = ${EXE_LINK_CMD} ${ABI_FLAGS} @%{response_file_dir}/tests.txt ${BUILD_DIR_LINK_PATH} ${LANG_EXE_FLAGS} ${LDFLAGS} %{test_exe_extra_ldflags} ${EXE_LINKS_TO} %{output_to_exe}$out

# Executable targets

build %{cli_exe}: link_cli %{join cli_objs} | libs
cli_name = cli

build %{test_exe}: link_tests %{join test_objs} | libs

Expand Down Expand Up @@ -121,6 +129,7 @@ build examples: phony | %{example_bin}
%{if build_bogo_shim}

build botan_bogo_shim: link_cli bogo_shim_object | libs
cli_name = bogo

# BoGo shim
build %{out_dir}/bogo_shim_object: compile_exe %{bogo_shim_src}
Expand All @@ -130,6 +139,7 @@ build %{out_dir}/bogo_shim_object: compile_exe %{bogo_shim_src}
%{if build_ct_selftest}

build botan_ct_selftest: link_cli ct_selftest_object | libs
cli_name = ct_selftest

build %{out_dir}/ct_selftest_object: compile_exe %{ct_selftest_src}

Expand Down Expand Up @@ -214,4 +224,5 @@ build %{exe}: link_fuzzer %{obj} | libs
%{for examples_build_info}
build %{obj}: compile_example_exe %{src}
build %{exe}: link_cli %{obj} | libs
cli_name = example_%{exe_basename}
%{endfor}

0 comments on commit d9e12cc

Please sign in to comment.