ninja-build / ninja

a small build system with a focus on speed
https://ninja-build.org/
Apache License 2.0
11.2k stars 1.59k forks source link

RSP file not found due to @ symbol before RSP_FILE not understood #2111

Open dmikushin opened 2 years ago

dmikushin commented 2 years ago

Here is what I get for OpenBLAS with Ninja 1.10.2_1, CMake 3.23 on MacOS X Catalina:

FAILED: ThirdParty/openblas/ThirdParty/OpenBLAS/lib/libopenblas.a 
: && /usr/local/Cellar/cmake/3.23.0/bin/cmake -E rm -f ThirdParty/openblas/ThirdParty/OpenBLAS/lib/libopenblas.a && /Library/Developer/CommandLineTools/usr/bin/ar qc ThirdParty/openblas/ThirdParty/OpenBLAS/lib/libopenblas.a  @CMakeFiles/openblas_static.rsp && /Library/Developer/CommandLineTools/usr/bin/ranlib ThirdParty/openblas/ThirdParty/OpenBLAS/lib/libopenblas.a && /usr/local/Cellar/cmake/3.23.0/bin/cmake -E touch ThirdParty/openblas/ThirdParty/OpenBLAS/lib/libopenblas.a && :
ar: @CMakeFiles/openblas_static.rsp: No such file or directory

Although CMakeFiles/openblas_static.rsp exists, the '@' symbol prevents the path from being recognized correctly. Looks like the '@' "at" symbol was supposed to be expanded to a real path, but the expansion was missed out. Is it the case?

jonesmz commented 2 years ago

You'll need to provide a lot more information.

We'll need all of the files necessary to reproduce this issue on another machine.

tcsunhao commented 1 year ago

I have the same issue that ninja cannot find rsp file, the log is showed: Fatal error[Ms007]: could not open file "@CMakeFiles\erpc_matrix_multiply_rpmsg_cm33_core1.rsp" Directories searched: E:\build\55s69m3\boards\69\me\erpc_matrix_multiply_rpmsg\tmp\erpc _matrix_multiply_rpmsg_cm33_core1\iar\debug but the CMakeFiles\erpc_matrix_multiply_rpmsg_cm33_core1.rsp just lay there. Not sure it is caused by the @ symbol or other reasons.

andrewjavao commented 8 months ago

Seems I have the same issue that a extra @ symbol is presented in command line when linking: OS: Macos IDE: VSCode(CMake Tools) Task: Using CMake ninja build system to build a executable Libraries: CGAL-5.6 with Qt5 module

CMakeLists.txt: find_package(CGAL 5.6 REQUIRED COMPONENTS Qt5 )

the CGAL package (CGAL_Qt5_moc_and_resource_files.cmake):

if(CGAL_Qt5_moc_and_resource_files_included)
  return()
endif()
set(CGAL_Qt5_moc_and_resource_files_included TRUE)
# qrc files (resources files, that contain icons, at least)
if(EXISTS ${CGAL_GRAPHICSVIEW_PACKAGE_DIR}/demo/resources/CGAL.qrc)
  qt5_add_resources (_CGAL_Qt5_RESOURCE_FILES_private
    ${CGAL_GRAPHICSVIEW_PACKAGE_DIR}/demo/resources/CGAL.qrc
    ${CGAL_GRAPHICSVIEW_PACKAGE_DIR}/demo/icons/Input.qrc
    ${CGAL_GRAPHICSVIEW_PACKAGE_DIR}/demo/icons/File.qrc
    ${CGAL_GRAPHICSVIEW_PACKAGE_DIR}/demo/icons/Triangulation_2.qrc)
else()
  # Installed version, in CMake resources
  file ( COPY
    ${CGAL_MODULES_DIR}/demo/resources
    ${CGAL_MODULES_DIR}/demo/icons
    DESTINATION ${CMAKE_BINARY_DIR})
  qt5_add_resources (_CGAL_Qt5_RESOURCE_FILES_private
    ${CMAKE_BINARY_DIR}/resources/CGAL.qrc
    ${CMAKE_BINARY_DIR}/icons/Input.qrc
    ${CMAKE_BINARY_DIR}/icons/File.qrc
    ${CMAKE_BINARY_DIR}/icons/Triangulation_2.qrc)
endif()

qt5_wrap_ui(_CGAL_Qt5_UI_FILES ${CGAL_GRAPHICSVIEW_PACKAGE_DIR}/include/CGAL/Qt/ImageInterface.ui)

rules.ninja in build directory:

# Rule for linking CXX static library.

rule CXX_STATIC_LIBRARY_LINKER__CGAL_Qt5_moc_and_resources_Release
  command = $PRE_LINK && /usr/local/Cellar/cmake/3.28.2/bin/cmake -E rm -f $TARGET_FILE && /usr/bin/ar qc $TARGET_FILE $LINK_FLAGS @$RSP_FILE && /usr/bin/ranlib $TARGET_FILE && /usr/local/Cellar/cmake/3.28.2/bin/cmake -E touch $TARGET_FILE && $POST_BUILD
  description = Linking CXX static library $TARGET_FILE
  rspfile = $RSP_FILE
  rspfile_content = $in_newline $LINK_PATH $LINK_LIBRARIES
  restat = $RESTAT

building output:

[23/25  60% :: 13.881] Building CXX object CMakeFiles/CGAL_Qt5_moc_and_resources.dir/CGAL_Qt5_moc_and_resources_autogen/mocs_compilation.cpp.o
[24/25  64% :: 13.947] Linking CXX static library libCGAL_Qt5_moc_and_resources.a
FAILED: libCGAL_Qt5_moc_and_resources.a 
: && /usr/local/Cellar/cmake/3.28.2/bin/cmake -E rm -f libCGAL_Qt5_moc_and_resources.a && /usr/bin/ar qc libCGAL_Qt5_moc_and_resources.a  @CMakeFiles/CGAL_Qt5_moc_and_resources.rsp && /usr/bin/ranlib libCGAL_Qt5_moc_and_resources.a && /usr/local/Cellar/cmake/3.28.2/bin/cmake -E touch libCGAL_Qt5_moc_and_resources.a && :
ar: @CMakeFiles/CGAL_Qt5_moc_and_resources.rsp: No such file or directory

is it a result of improper configuration or something need to fix?

digit-google commented 8 months ago

Looks like improper CMake generation.

Ninja doesn't do anything special here apart from passing the @ to your build command, as it is specified in your build.ninja file (generated itself by CMake).

Using @<path> to point to a response file is an ad-hoc convention that some tools, but not all of them actually support. In this case it looks like the ar program you are using does not support it.

Further inspection shows that the Linux ar command does support this feature (see https://linux.die.net/man/1/ar), but the MacOS version does not (see https://www.unix.com/man-page/osx/1/ar/).

I recommend asking on CMake development lists instead, since it is likely that CMake didn't understand that subtle difference for some reason.

A last resort solution in this case is to provide an ar wrapper script that recognizes the @<path> argument, then expands it before calling the real ar binary with the result of reading it, and ensure CMake uses that one by defining a variable like CMAKE_AR. But again, I am not a CMake expert, and you'll find more relevant information elsewhere.

dmikushin commented 8 months ago

@digit-google , thanks for this very nice explanation! So one workaround to try would be CMAKE_AR=llvm-ar.

In my experience an absolute <path> instead of @<path> works, which as you said could be indeed forwarded to CMake folks.