Repository: llvm/llvm-project

Issue:
offload `fatal error: 'OffloadAPI.h' file not found`  - on linux
```
FAILED: offload/liboffload/CMakeFiles/LLVMOffload.dir/src/OffloadImpl.cpp.o
/build/source/build-llvm/./bin/clang++ --target=x86_64-pc-linux-gnu -DDEBUG_PREFIX=\"Liboffload\" -DTARGET_NAME=\"Liboffload\" -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/build/source/llvm/include -I/build/source/build-llvm/include -I/build/source/build-llvm/runtimes/runtimes-bins/offload/liboffload/API -I/build/source/build-llvm/runtimes/runtimes-bins/offload/liboffload/../include -I/build/source/offload/liboffload/include -I/build/source/offload/liboffload/../include -I/build/source/offload/liboffload/../plugins-nextgen/common/include -I/build/source/build-llvm/runtimes/runtimes-bins/offload/liboffload/../plugins-nextgen/common/include -I/build/source/offload/plugins-nextgen/common/include -I/build/source/build-llvm/runtimes/runtimes-bins/offload/plugins-nextgen/common/include -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection -Wno-unused-command-line-argument -Wdate-time -D_FORTIFY_SOURCE=3 -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -fdebug-prefix-map=/build/source/build-llvm/runtimes/runtimes-bins=../../../ -fdebug-prefix-map=/build/source/= -no-canonical-prefixes -ffile-prefix-map=/build/source/build-llvm/runtimes/runtimes-bins=../../../ -ffile-prefix-map=/build/source/= -no-canonical-prefixes -O3 -DNDEBUG -std=c++17 -fPIC  -fno-exceptions -funwind-tables -fno-exceptions -Werror=global-constructors -MD -MT offload/liboffload/CMakeFiles/LLVMOffload.dir/src/OffloadImpl.cpp.o -MF offload/liboffload/CMakeFiles/LLVMOffload.dir/src/OffloadImpl.cpp.o.d -o offload/liboffload/CMakeFiles/LLVMOffload.dir/src/OffloadImpl.cpp.o -c /build/source/offload/liboffload/src/OffloadImpl.cpp
In file included from /build/source/offload/liboffload/src/OffloadImpl.cpp:14:
/build/source/offload/liboffload/include/OffloadImpl.hpp:11:10: fatal error: 'OffloadAPI.h' file not found
   11 | #include <OffloadAPI.h>
      |          ^~~~~~~~~~~~~~
1 error generated.
```
probably caused by #141982


Discussion:

@llvm/issue-subscribers-offload

Author: Sylvestre Ledru (sylvestre)

<details>
```
FAILED: offload/liboffload/CMakeFiles/LLVMOffload.dir/src/OffloadImpl.cpp.o
/build/source/build-llvm/./bin/clang++ --target=x86_64-pc-linux-gnu -DDEBUG_PREFIX=\"Liboffload\" -DTARGET_NAME=\"Liboffload\" -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/build/source/llvm/include -I/build/source/build-llvm/include -I/build/source/build-llvm/runtimes/runtimes-bins/offload/liboffload/API -I/build/source/build-llvm/runtimes/runtimes-bins/offload/liboffload/../include -I/build/source/offload/liboffload/include -I/build/source/offload/liboffload/../include -I/build/source/offload/liboffload/../plugins-nextgen/common/include -I/build/source/build-llvm/runtimes/runtimes-bins/offload/liboffload/../plugins-nextgen/common/include -I/build/source/offload/plugins-nextgen/common/include -I/build/source/build-llvm/runtimes/runtimes-bins/offload/plugins-nextgen/common/include -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection -Wno-unused-command-line-argument -Wdate-time -D_FORTIFY_SOURCE=3 -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -fdebug-prefix-map=/build/source/build-llvm/runtimes/runtimes-bins=../../../ -fdebug-prefix-map=/build/source/= -no-canonical-prefixes -ffile-prefix-map=/build/source/build-llvm/runtimes/runtimes-bins=../../../ -ffile-prefix-map=/build/source/= -no-canonical-prefixes -O3 -DNDEBUG -std=c++17 -fPIC  -fno-exceptions -funwind-tables -fno-exceptions -Werror=global-constructors -MD -MT offload/liboffload/CMakeFiles/LLVMOffload.dir/src/OffloadImpl.cpp.o -MF offload/liboffload/CMakeFiles/LLVMOffload.dir/src/OffloadImpl.cpp.o.d -o offload/liboffload/CMakeFiles/LLVMOffload.dir/src/OffloadImpl.cpp.o -c /build/source/offload/liboffload/src/OffloadImpl.cpp
In file included from /build/source/offload/liboffload/src/OffloadImpl.cpp:14:
/build/source/offload/liboffload/include/OffloadImpl.hpp:11:10: fatal error: 'OffloadAPI.h' file not found
   11 | #include &lt;OffloadAPI.h&gt;
      |          ^~~~~~~~~~~~~~
1 error generated.
```
probably caused by #<!-- -->141982
</details>

Thanks for the report, I'm looking into this. Could you share the full cmake invocation you're using to build? And could you also see what the contents of `build/source/build-llvm/runtimes/runtimes-bins/offload/liboffload/API` are?
See the full log:
https://llvm-jenkins.debian.net/job/llvm-toolchain-buster-binaries/architecture=amd64,distribution=buster,label=amd64/2413/consoleFull

> Thanks for the report, I'm looking into this. Could you share the full cmake invocation you're using to build? And could you also see what the contents of `build/source/build-llvm/runtimes/runtimes-bins/offload/liboffload/API` are?

Have you done a completely clean build? Might be some dependency that's missing we didn't notice since it was already in the build tree.
@jhuber6 I've also reproduced this issue. It was a completely clean build.

A full log is available here: https://download.copr.fedorainfracloud.org/results/@fedora-llvm-team/llvm-snapshots-big-merge-20250604/fedora-rawhide-x86_64/09130808-llvm/builder-live.log.gz
Looking at the log it seems like `<build>/liboffload/API/generated/OffloadAPI.h.gen` is generated but isn't being copied back to `<build>/liboffload/API/OffloadAPI.h` (with or without the clang-format step which is optional). I'm trying a clean build now.

Patch:
diff --git a/offload/liboffload/API/CMakeLists.txt b/offload/liboffload/API/CMakeLists.txt
index cf6e132aa57a9..216710faa84f6 100644
--- a/offload/liboffload/API/CMakeLists.txt
+++ b/offload/liboffload/API/CMakeLists.txt
@@ -42,5 +42,7 @@ else()
             COMMAND ${CMAKE_COMMAND} -E copy_if_different generated/${file}.gen ${CMAKE_CURRENT_BINARY_DIR}/${file}
             DEPENDS generated/${file}.gen
         )
+        add_custom_target(OffloadAPI.${file} DEPENDS ${file})
+        add_dependencies(OffloadAPI OffloadAPI.${file})
     endforeach()
 endif()