KhronosGroup / glslang

Khronos-reference front end for GLSL/ESSL, partial front end for HLSL, and a SPIR-V generator.
Other
3.08k stars 845 forks source link

Trying to upgrade to 11.12.0: The following imported targets are referenced, but are missing: SPIRV-Tools-opt #3065

Open svenstaro opened 2 years ago

svenstaro commented 2 years ago

Hello, I'm the maintainer of the official glslang package in Arch Linux. We're currently trying to migrate to glslang 11.12.0. However, whenever I use the compatibility shims I get:

CMake Warning at /usr/lib/cmake/OSDependentTargets.cmake:2 (message):
  Using `OSDependentTargets.cmake` is deprecated: use `find_package(glslang)`
  to find glslang CMake targets.
Call Stack (most recent call first):
  CMakeLists.txt:507 (include)

CMake Error at /usr/lib/cmake/glslang/glslang-targets.cmake:172 (message):
  The following imported targets are referenced, but are missing:
  SPIRV-Tools-opt
Call Stack (most recent call first):
  /usr/lib/cmake/OSDependentTargets.cmake:5 (include)
  CMakeLists.txt:507 (include)

When using the recommended way with find_package(glslang) I get:

CMake Warning at CMakeLists.txt:506 (find_package):
  Found package configuration file:

    /usr/lib64/cmake/glslang/glslang-config.cmake

  but it set glslang_FOUND to FALSE so package "glslang" is considered to be
  NOT FOUND.  Reason given by package:

  The following imported targets are referenced, but are missing:
  SPIRV-Tools-opt

I can produce this using a bare CMakeLists.txt with only find_package(glslang) in it.

Now granted, this might be a packaging issue but we've been packaging glslang with few package changes for a long time and it would be odd to hit this now. This particular problem hasn't happened before.

Frankly, I have no idea what's wrong that it's not finding SPIRV-Tools-opt and what could be wrong in the system.

We're building glslang using this script: https://github.com/archlinux/svntogit-packages/blob/packages/glslang/trunk/PKGBUILD

Full build log of glslang attached. build.txt

We're hoping you can help us figure out whether this is a bug in glslang or in our packaging.

sl1pkn07 commented 2 years ago

i have this patch on my local package

diff --git a/External/CMakeLists.txt b/External/CMakeLists.txt
index cbabd2e3..05ae305e 100644
--- a/External/CMakeLists.txt
+++ b/External/CMakeLists.txt
@@ -71,7 +70,8 @@ endif()
 if(ENABLE_OPT AND NOT TARGET SPIRV-Tools-opt)
     if(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/spirv-tools)
         set(SPIRV_SKIP_TESTS ON CACHE BOOL "Skip building SPIRV-Tools tests")
-        add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/spirv-tools spirv-tools)
+        set(BUILD_SHARED_LIBS OFF CACHE BOOL "Disable build shared libs" FORCE)
+        add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/spirv-tools EXCLUDE_FROM_ALL)
     endif()
 endif()

diff --git a/SPIRV/CMakeLists.txt b/SPIRV/CMakeLists.txt
index 22f767d7..8fe24363 100644
--- a/SPIRV/CMakeLists.txt
+++ b/SPIRV/CMakeLists.txt
@@ -98,7 +100,7 @@ if(ENABLE_OPT)
     target_link_libraries(SPIRV PRIVATE MachineIndependent SPIRV-Tools-opt)
     target_include_directories(SPIRV PUBLIC
         $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../External>
-        $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/External>)
+        $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
 else()
     target_link_libraries(SPIRV PRIVATE MachineIndependent)
 endif()
diff --git a/StandAlone/CMakeLists.txt b/StandAlone/CMakeLists.txt
index 2b163e7f..6247a42e 100644
--- a/StandAlone/CMakeLists.txt
+++ b/StandAlone/CMakeLists.txt
@@ -83,7 +84,7 @@ endif()
 target_link_libraries(glslangValidator ${LIBRARIES})
 target_include_directories(glslangValidator PUBLIC
     $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../External>
-    $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/External>)
+    $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)

 if(ENABLE_OPT)
     target_include_directories(glslangValidator

maybe help

or add spirv-tools package as dependency, or mix of both

greetings

anthraxx commented 2 years ago

@jeremy-lunarg can you please take a look and maybe help @svenstaro to figure out how to properly fix it while not disabling the shared libs etc?

jeremy-lunarg commented 1 year ago

Will do. I think we need to export it from the newer cmake implementation that was added a month ago. My naive attempt at doing that failed and I haven't been able to spend cycles on it the last few days.

felixonmars commented 1 year ago

@sl1pkn07 I have tried your patch. It does make the cmake error go away, but unfortunately also makes the resulting libglslang.a missing at least all the glslang::TShader symbols as well.

Update: I need to investigate more, sorry.

sl1pkn07 commented 1 year ago

my tried to goal is use spirv-tools(from the commit in know-good file) as static into glslang. at the moment. none of the projects i buid wich required gslang has failed (the only i get failed is the unittest with double-free error in here https://github.com/KhronosGroup/glslang/issues/2128)

can you share a piece of code were i can test if i have missing symbols in my build? i can share my pkgbuild with all my patches. but is a splitted pkgbuild with all vulkan related projects in one, and not follow the archlinux standars of quality

greetings

felixonmars commented 1 year ago

I have figured it out that missing -ffat-lto-objects in CXXFLAGS is responsible for the glslang::TShader symbol missing issues.

I have took the last two parts of your patch (removing the /External include path) and only one problem remains now:

undefined reference to `spvtools::CreateEliminateDeadInputComponentsPass()'

This symbol is present in libSPIRV.{a,so} shipped by glslang but not by our packaged spirv-tools which provides libSPIRV-Tools-opt.so. I am assuming this to be a version mismatch as the commit adding this function isn't available in any spirv-tools release yet: https://github.com/KhronosGroup/SPIRV-Tools/commit/c8e1588cfa3ff9e3b5d600ef04f4261c4e68af90

Probably the cmake files of glslang shouldn't instruct to link to SPIRV-Tools-opt when the latter isn't provided by the glslang package itself.

felixonmars commented 1 year ago

@sl1pkn07 My failing example is the ncnn package. An old version (20220729) triggered the error in OP, and the updated version (20221128) triggers the next issue, which is then fixed by your patch:

CMake Error in src/CMakeLists.txt:
  Imported target "glslang::SPIRV" includes non-existent path

    "/usr/include/External"

  in its INTERFACE_INCLUDE_DIRECTORIES.  Possible reasons include:

  * The path was deleted, renamed, or moved to another location.

  * An install or uninstall procedure did not complete successfully.

  * The installation package was faulty and references files it does not
  provide.
sl1pkn07 commented 1 year ago

ncnn (asp export ncnn) works for me

log.txt

here is my pkgbuild for all khronos vulkan projects and patches (build GIT packages,and maybe have missing dependencies) sl1-vulkan-git-1.3.236.r3940.82d4232f0-1.src.tar.gz (meybe need tweak because the last version i builded is 1.3.235.r3927.6c7b2db41-1. maybe need tweak again for new changes)

greetings