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 287b52d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
3 changes: 3 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 @@ -2210,6 +2212,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
17 changes: 12 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 = ${LIB_LINKS_TO}
command = %{lib_link_cmd} ${ABI_FLAGS} ${LDFLAGS} $in @%{response_file_dir}/shared.txt %{output_to_exe}$out

build %{out_dir}/%{shared_lib_name}: link_shared %{join lib_objs}
%{endif}
Expand All @@ -80,11 +84,14 @@ 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.txt
rspfile_content = ${EXE_LINKS_TO}
command = ${EXE_LINK_CMD} ${ABI_FLAGS} $in ${BUILD_DIR_LINK_PATH} ${LANG_EXE_FLAGS} ${LDFLAGS} @%{response_file_dir}/cli.txt %{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 = ${EXE_LINKS_TO}
command = ${EXE_LINK_CMD} ${ABI_FLAGS} $in ${BUILD_DIR_LINK_PATH} ${LANG_EXE_FLAGS} ${LDFLAGS} %{test_exe_extra_ldflags} @%{response_file_dir}/tests.txt %{output_to_exe}$out

# Executable targets

Expand Down

0 comments on commit 287b52d

Please sign in to comment.