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

Kokkos, ninja: make clean deletes generated cpp file and is not regenerated, causing compilation issues with rebuild when using ninja #13643

Closed
ndellingwood opened this issue Dec 2, 2024 · 10 comments · Fixed by #13647
Labels
type: bug The primary issue is a bug in Trilinos code or tests

Comments

@ndellingwood
Copy link
Contributor

Bug Report

@trilinos/kokkos

Description

Following the merge of #13589 , some build system behavior changes, when using ninja as build generator, were reported by @jhux2 @cgcgcg .

When attempting to re-compile Trilinos after calling make clean, compilation fails due to a missing generated file Kokkos_Version_Info.cpp that was deleted during the make clean call, but not regenerated (no rerun of configure+generation stage) during a follow up build stage

  • This only occurs with ninja as the build generator - I did not reproduce the issue with Unix Makefiles as generator
  • This does not occur when following the same basic steps, but with the standalone kokkos repo (i.e. no Trilinos)

Steps to Reproduce

export TRILINOS_SRC=<path-to-your-source>

cmake -B build -G Ninja -DTrilinos_ENABLE_Kokkos=ON  -DCMAKE_CXX_COMPILER=g++ -DCMAKE_C_COMPILER=gcc ${TRILINOS_SRC}
cmake --build build
cmake --build build --target clean

# this next call triggers compilation error
cmake --build build

Error output:

[2/25] Building CXX object packages/kokkos/CMakeFiles/impl_git_version.dir/__/__/generated/Kokkos_Version_Info.cpp.o
FAILED: packages/kokkos/CMakeFiles/impl_git_version.dir/__/__/generated/Kokkos_Version_Info.cpp.o 
/opt/local/bin/g++  -I/Users/ndellin/Research/trilinos/Trilinos-kp/Build/Repr-post-release/build -I/Users/ndellin/Research/trilinos/Trilinos-kp/Build/Repr-post-release/build/generated -O3 -DNDEBUG -std=c++17 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX14.5.sdk -MD -MT packages/kokkos/CMakeFiles/impl_git_version.dir/__/__/generated/Kokkos_Version_Info.cpp.o -MF packages/kokkos/CMakeFiles/impl_git_version.dir/__/__/generated/Kokkos_Version_Info.cpp.o.d -o packages/kokkos/CMakeFiles/impl_git_version.dir/__/__/generated/Kokkos_Version_Info.cpp.o -c /Users/ndellin/Research/trilinos/Trilinos-kp/Build/Repr-post-release/build/generated/Kokkos_Version_Info.cpp
cc1plus: fatal error: /Users/ndellin/Research/trilinos/Trilinos-kp/Build/Repr-post-release/build/generated/Kokkos_Version_Info.cpp: No such file or directory
compilation terminated.
[19/25] Building CXX object packages/kokkos/core/src/CMakeFiles/kokkoscore.dir/impl/Kokkos_Core.cpp.o
ninja: build stopped: subcommand failed.

Adding more knowledgeable folks than myself for possible insights or guidance on how to continue triage - @bartlettroscoe @masterleinad @dalg24 @crtrott

@ndellingwood ndellingwood added the type: bug The primary issue is a bug in Trilinos code or tests label Dec 2, 2024
@masterleinad
Copy link
Contributor

@bartlettroscoe
Copy link
Member

Looks similar to gitlab.kitware.com/cmake/cmake/-/issues/18032.

From looking at the file kokkos/cmake/build_env_info.cmake, I don't think that is an identical problem. (In that case, there was an issue with not giving it an explicit absolute path.)

I don't remember all the details, but I you have to be careful about how you define custom targets/commands that generate files. It may be that:

add_custom_target(
AlwaysCheckGit COMMAND ${CMAKE_COMMAND} -DRUN_CHECK_GIT_VERSION=1 -DKOKKOS_SOURCE_DIR=${Kokkos_SOURCE_DIR} -P
${CURRENT_LIST_DIR}/build_env_info.cmake BYPRODUCTS ${post_configure_file}
)

is the issue. I think you have to use a custom command, not a custom target (the documentation is confusing on this). See, for example:

https://github.com/TriBITSPub/TriBITS/blob/ade2bbbb57767f38b1e6efd464d50753717403fa/tribits/core/package_arch/TribitsCopyFilesToBinaryDir.cmake#L255-L259

Just a hutch (and a bad memory from 15+ years ago dealing with the same issue).

@masterleinad
Copy link
Contributor

Looks like

diff --git a/packages/kokkos/cmake/build_env_info.cmake b/packages/kokkos/cmake/build_env_info.cmake
index ac28b2d8503..e9c6f8b8686 100644
--- a/packages/kokkos/cmake/build_env_info.cmake
+++ b/packages/kokkos/cmake/build_env_info.cmake
@@ -100,10 +100,11 @@ function(check_git_version)
 endfunction()
 
 function(check_git_setup)
-  add_custom_target(
-    AlwaysCheckGit COMMAND ${CMAKE_COMMAND} -DRUN_CHECK_GIT_VERSION=1 -DKOKKOS_SOURCE_DIR=${Kokkos_SOURCE_DIR} -P
-                           ${CURRENT_LIST_DIR}/build_env_info.cmake BYPRODUCTS ${post_configure_file}
+  add_custom_command(OUTPUT ${post_configure_file} COMMAND touch ${post_configure_file}
+    COMMAND ${CMAKE_COMMAND} -DRUN_CHECK_GIT_VERSION=1 -DKOKKOS_SOURCE_DIR=${Kokkos_SOURCE_DIR} -P
+                           ${CURRENT_LIST_DIR}/build_env_info.cmake
   )
+  add_custom_target(AlwaysCheckGit DEPENDS ${post_configure_file})
 
   add_library(impl_git_version ${CMAKE_BINARY_DIR}/generated/Kokkos_Version_Info.cpp)
   target_include_directories(impl_git_version PUBLIC ${CMAKE_BINARY_DIR}/generated)

would fix the issue.

@ndellingwood
Copy link
Contributor Author

Thanks @masterleinad , I tried a similar change without success, didn't realize the COMMAND touch ${post_configure_file} addition was necessary 👍

When testing the rebuild after clean, I got this warning:

/Library/Developer/CommandLineTools/usr/bin/ranlib: file: packages/kokkos/libimpl_git_version.a(Kokkos_Version_Info.cpp.o) has no symbols
warning: /Library/Developer/CommandLineTools/usr/bin/ranlib: archive library: packages/kokkos/libimpl_git_version.a the table of contents is empty (no object file members in the library define global symbols)

Is that a concern?

More detailed summary of steps:

s1067110:Repr-post-release ndellin$ cmake --build build 
[25/25] Linking CXX static library packages/kokkos/containers/src/libkokkoscontainers.a
s1067110:Repr-post-release ndellin$ cmake --build build --target clean
[1/1] Cleaning all built files...
Cleaning... 25 files.
s1067110:Repr-post-release ndellin$ cmake --build build 
[6/25] Linking CXX static library packages/kokkos/libimpl_git_version.a
/Library/Developer/CommandLineTools/usr/bin/ranlib: file: packages/kokkos/libimpl_git_version.a(Kokkos_Version_Info.cpp.o) has no symbols
/Library/Developer/CommandLineTools/usr/bin/ranlib: file: packages/kokkos/libimpl_git_version.a(Kokkos_Version_Info.cpp.o) has no symbols
warning: /Library/Developer/CommandLineTools/usr/bin/ranlib: archive library: packages/kokkos/libimpl_git_version.a the table of contents is empty (no object file members in the library define global symbols)
[25/25] Linking CXX static library packages/kokkos/containers/src/libkokkoscontainers.a

@masterleinad
Copy link
Contributor

It seems

diff --git a/packages/kokkos/cmake/build_env_info.cmake b/packages/kokkos/cmake/build_env_info.cmake
index ac28b2d8503..76afbb74b63 100644
--- a/packages/kokkos/cmake/build_env_info.cmake
+++ b/packages/kokkos/cmake/build_env_info.cmake
@@ -4,7 +4,7 @@ find_package(Git QUIET)
 
 set(CURRENT_LIST_DIR ${CMAKE_CURRENT_LIST_DIR})
 set(pre_configure_dir ${CMAKE_CURRENT_LIST_DIR})
-set(post_configure_dir ${CMAKE_BINARY_DIR}/generated)
+set(post_configure_dir ${CMAKE_CURRENT_BINARY_DIR}/generated)
 
 set(pre_configure_file ${pre_configure_dir}/Kokkos_Version_Info.cpp.in)
 set(post_configure_file ${post_configure_dir}/Kokkos_Version_Info.cpp)
@@ -105,7 +105,7 @@ function(check_git_setup)
                            ${CURRENT_LIST_DIR}/build_env_info.cmake BYPRODUCTS ${post_configure_file}
   )
 
-  add_library(impl_git_version ${CMAKE_BINARY_DIR}/generated/Kokkos_Version_Info.cpp)
+  add_library(impl_git_version ${CMAKE_CURRENT_BINARY_DIR}/generated/Kokkos_Version_Info.cpp)
   target_include_directories(impl_git_version PUBLIC ${CMAKE_BINARY_DIR}/generated)
   target_compile_features(impl_git_version PRIVATE cxx_raw_string_literals)
   add_dependencies(impl_git_version AlwaysCheckGit)

is the better fix.

@ndellingwood
Copy link
Contributor Author

@masterleinad your newest suggestion worked well 👍

@masterleinad
Copy link
Contributor

@ndellingwood Can you create a pull request?

@ndellingwood
Copy link
Contributor Author

@ndellingwood Can you create a pull request?

@masterleinad yes, I'll put up a kokkos PR shortly along with patch match PR to Trilinos

ndellingwood added a commit to ndellingwood/kokkos that referenced this issue Dec 3, 2024
This PR resolves issues with ninja as generator reported in
trilinos/Trilinos#13643

In Trilinos builds with ninja as generator, calling `make clean`
followed by recompiling resulted in compilation errors due to a missing
generated file Kokkos_Version_Info.cpp that was deleted during clean

The changes in this PR resolve the issue

Added notes:

* The issue did not occur with Unix Makefiles as generator
* The issue did not ocur with standalond kokkos

Co-authored-by: Daniel Arndt <[email protected]>
ndellingwood added a commit to ndellingwood/Trilinos that referenced this issue Dec 3, 2024
This PR resolves issues with ninja as generator reported in
trilinos#13643

In Trilinos builds with ninja as generator, calling `make clean`
followed by recompiling resulted in compilation errors due to a missing
generated file Kokkos_Version_Info.cpp that was deleted during clean

The changes in this PR resolve the issue

Added notes:

* The issue did not occur with Unix Makefiles as generator
* The issue did not ocur with standalond kokkos

Co-authored-by: Daniel Arndt <[email protected]>
Signed-off-by: Nathan Ellingwood <[email protected]>
@ndellingwood ndellingwood linked a pull request Dec 3, 2024 that will close this issue
csiefer2 pushed a commit that referenced this issue Dec 3, 2024
This PR resolves issues with ninja as generator reported in
#13643

In Trilinos builds with ninja as generator, calling `make clean`
followed by recompiling resulted in compilation errors due to a missing
generated file Kokkos_Version_Info.cpp that was deleted during clean

The changes in this PR resolve the issue

Added notes:

* The issue did not occur with Unix Makefiles as generator
* The issue did not ocur with standalond kokkos

Signed-off-by: Nathan Ellingwood <[email protected]>
Co-authored-by: Daniel Arndt <[email protected]>
@jhux2
Copy link
Member

jhux2 commented Dec 6, 2024

@ndellingwood I can confirm that building Trilinos withninja works again.

@jhux2
Copy link
Member

jhux2 commented Dec 6, 2024

and thanks for the quick fix!

crtrott pushed a commit to kokkos/kokkos that referenced this issue Dec 13, 2024
This PR resolves issues with ninja as generator reported in
trilinos/Trilinos#13643

In Trilinos builds with ninja as generator, calling `make clean`
followed by recompiling resulted in compilation errors due to a missing
generated file Kokkos_Version_Info.cpp that was deleted during clean

The changes in this PR resolve the issue

Added notes:

* The issue did not occur with Unix Makefiles as generator
* The issue did not ocur with standalond kokkos

Co-authored-by: Daniel Arndt <[email protected]>
ccober6 pushed a commit to ccober6/Trilinos that referenced this issue Jan 8, 2025
This PR resolves issues with ninja as generator reported in
trilinos#13643

In Trilinos builds with ninja as generator, calling `make clean`
followed by recompiling resulted in compilation errors due to a missing
generated file Kokkos_Version_Info.cpp that was deleted during clean

The changes in this PR resolve the issue

Added notes:

* The issue did not occur with Unix Makefiles as generator
* The issue did not ocur with standalond kokkos

Signed-off-by: Nathan Ellingwood <[email protected]>
Co-authored-by: Daniel Arndt <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug The primary issue is a bug in Trilinos code or tests
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants