Skip to content

CMake: Guard inclusion of VULKAN_HEADERS and SPIRV-Headers#8124

Merged
expipiplus1 merged 8 commits intoshader-slang:masterfrom
sergeiepopov:cmake/guard_submodules_include
Aug 19, 2025
Merged

CMake: Guard inclusion of VULKAN_HEADERS and SPIRV-Headers#8124
expipiplus1 merged 8 commits intoshader-slang:masterfrom
sergeiepopov:cmake/guard_submodules_include

Conversation

@sergeiepopov
Copy link
Copy Markdown
Contributor

Don't include the VULKAN_HEADERS and SPIRV-Headers submodule if they are already included.
Fix for the #7898.

@sergeiepopov sergeiepopov requested a review from a team as a code owner August 8, 2025 12:07
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Aug 8, 2025

CLA assistant check
All committers have signed the CLA.

@sergeiepopov sergeiepopov force-pushed the cmake/guard_submodules_include branch from 17d4372 to cfd2dfe Compare August 8, 2025 12:48
Copy link
Copy Markdown
Collaborator

@jkwak-work jkwak-work left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@expipiplus1 and @jarcherNV for second opinion.

Comment on lines +109 to +114
if(SLANG_USE_SYSTEM_SPIRV_HEADERS)
if(SLANG_OVERRIDE_SPIRV_HEADERS_PATH)
message(
WARNING
"SLANG_OVERRIDE_SPIRV_HEADERS_PATH does nothing when SLANG_USE_SPIRV_HEADERS is set"
)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be an error so that the user can fix it right away.

And from the naming perspective, "override" sounds like it could/should override SLANG_USE_SYSTEM_SPIRV_HEADERS; not the other way around.
But it wouldn't matter if it is an error and the build stops here.

@jarcherNV
Copy link
Copy Markdown
Collaborator

Looking at the original issue, are you sure this change is needed? If I understand correctly, the problem you are having is that Slang is attempting to use its own spirv and vulkan headers from the external submodules rather than yours? It is posible to override this behavior though, eg:

-DSLANG_OVERRIDE_VULKAN_HEADERS_PATH=/path/to/vulkan/headers
-DSLANG_OVERRIDE_SPIRV_HEADERS_PATH=/path/to/spirv/headers

Does this not work for your project?

@jkwak-work
Copy link
Copy Markdown
Collaborator

Looking at the original issue, are you sure this change is needed? If I understand correctly, the problem you are having is that Slang is attempting to use its own spirv and vulkan headers from the external submodules rather than yours? It is posible to override this behavior though, eg:

-DSLANG_OVERRIDE_VULKAN_HEADERS_PATH=/path/to/vulkan/headers -DSLANG_OVERRIDE_SPIRV_HEADERS_PATH=/path/to/spirv/headers

Does this not work for your project?

I think the intention is to use ones installed on the system.

So I guess there are three ways to use SPIRV-HEADER/TOOLS now.

  • external/spirv-{header,tools}
  • any directory with SLANG_OVERRIDE_SPIRV_HEADERS_PATH
  • /usr/lib/... somewhere with SLANG_USE_SYSTEM_SPIRV_HEADERS

@jarcherNV
Copy link
Copy Markdown
Collaborator

Ok that makes sense. If that third option is currently broken and this fixes it then that sounds reasonable to me.

@sergeiepopov
Copy link
Copy Markdown
Contributor Author

sergeiepopov commented Aug 9, 2025

-DSLANG_OVERRIDE_VULKAN_HEADERS_PATH=/path/to/vulkan/headers
-DSLANG_OVERRIDE_SPIRV_HEADERS_PATH=/path/to/spirv/headers

Does this not work for your project?

This does not work in my project because it has its own Vulkan and SPIR-V header libraries, which are included first. However, with the above command, Slang also tries to include them, resulting in the following error:
CMake Error at core/external/spirv-headers/CMakeLists.txt:17 (add_library): add_library cannot create target "SPIRV-Headers" because another target with the same name already exists. The existing target is an interface library created in source directory "C:/source/engine/core/external/spirv-headers". See documentation for policy CMP0002 for more details.

Ok that makes sense. If that third option is currently broken and this fixes it then that sounds reasonable to me.

No, I don't use the third option. As I mentioned, my project uses its own instances of SPIR-V and Vulkan headers, which are not the system ones (i.e., they are not added via find_package(SPIRV-Headers REQUIRED) but rather through add_subdirectory("external/vulkan-headers")). This fix prevents double inclusion of those libraries by Slang, which now checks if a library was already included by the top-level project and skips the second inclusion.

expipiplus1
expipiplus1 previously approved these changes Aug 12, 2025
@expipiplus1 expipiplus1 enabled auto-merge August 12, 2025 14:53
@jkwak-work jkwak-work added the pr: non-breaking PRs without breaking changes label Aug 12, 2025
@jkwak-work
Copy link
Copy Markdown
Collaborator

/format

@slangbot
Copy link
Copy Markdown
Contributor

🌈 Formatted, please merge the changes from this PR

auto-merge was automatically disabled August 13, 2025 04:51

Head branch was pushed to by a user without write access

@expipiplus1 expipiplus1 enabled auto-merge August 15, 2025 09:42
@sergeiepopov
Copy link
Copy Markdown
Contributor Author

It requires workflow approval. @expipiplus1, @jarcherNV, @jkwak-work, could someone approve it and tick auto-mere if all looks good?

@expipiplus1 expipiplus1 added this pull request to the merge queue Aug 19, 2025
Merged via the queue into shader-slang:master with commit 6321bf0 Aug 19, 2025
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr: non-breaking PRs without breaking changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants