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

build(deps): automatically pull in dependencies #5982

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

vikke1234
Copy link

To ease development, this patch pulls in dependencies automatically using
FetchContent1. Test dependencies are only pulled in if tests are enabled.

There' still a few open questions, I opened this PR to see if the direction
I'm going with is good.

Open questions:

  • The path will now be "dynamic" as it depends what is passed to
    cmake -B ${BUILD_FOLDER}. This means that scripts like
    tools/sva/tools/process_grammar.rb which has a hard coded path
    will need to account for this. My suggestion is for example to cache
    the SPIRV headers directory and have the script run something like
    cmake -LA -N | grep SPIRV_HEADERS_DIR.

  • I'm not familiar with bazel, does the build config there need to be
    adjusted to reflect these changes as well?

Footnotes

  1. https://cmake.org/cmake/help/latest/module/FetchContent.html

To ease development, this patch pulls in dependencies automatically
using FetchContent[^1]. Test dependencies are only pulled in if tests
are enabled.

[^1]: https://cmake.org/cmake/help/latest/module/FetchContent.html
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@s-perron s-perron requested a review from dneto0 February 3, 2025 16:58
Copy link
Collaborator

@s-perron s-perron left a comment

Choose a reason for hiding this comment

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

I don't think we want to go in a direction that will breaking existing users. We want to allow other project that use SPIRV-Tools to pick their own version of SPIRV-Headers.

I don't know how the fetch works, but I'm pretty sure this would break the choromium builds because they want to pick their version for each of our dependencies.

Comment on lines +34 to +39
fetch_content(
SPIRV-Headers
GIT_REPOSITORY https://github.com/KhronosGroup/SPIRV-Headers.git
GIT_TAG origin/main
OVERRIDE_FIND_PACKAGE
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should not unconditionally fetching the dependency. This should only happen if the directory does not already exist.

This will also create problem if SPIRV Headers get ahead of SPIR-V tools. This may not always compile. We use the DEPS file to keep track of a currently working version. We try to keep that as up-to-date as possible. You should try to get the commit hash from there.

With that said, I'm not sure if this is too useful since all people have to do to get the deps is call python3 utils/git-sync-deps. See https://github.com/KhronosGroup/SPIRV-Tools?tab=readme-ov-file#getting-the-source. This creates a second way of doing the samething.

Copy link
Author

Choose a reason for hiding this comment

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

We should not unconditionally fetching the dependency. This should only happen if the directory does not already exist.

It does not do that.

This will also create problem if SPIRV Headers get ahead of SPIR-V tools. This may not always compile. We use the DEPS file to keep track of a currently working version. We try to keep that as up-to-date as possible. You should try to get the commit hash from there.

There's a TODO to for me to lock it into the correct commit. I wasn't sure which one was the correct one. Just wanted to get initial reviews. The commit IDs can be set by the GIT_TAG argument.

With that said, I'm not sure if this is too useful since all people have to do to get the deps is call python3 utils/git-sync-deps. See https://github.com/KhronosGroup/SPIRV-Tools?tab=readme-ov-file#getting-the-source. This creates a second way of doing the samething.

It automates the process though to make the build more comfortable.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It does not do that.

Sorry, I don't know cmake too well. I guess it only fetches the content if the package could not be found.

There's a TODO to for me to lock it into the correct commit.

I saw the TODO. I just want to make sure that you get the commit from the DEPS file. We do not want to keep track of the proper commit in multiple places.

Now I see why the fetching is use, if you are relying on find_package.

Comment on lines -36 to -50
if (IS_DIRECTORY ${SPIRV_HEADER_DIR})
# TODO(dneto): We should not be modifying the parent scope.
set(SPIRV_HEADER_INCLUDE_DIR ${SPIRV_HEADER_DIR}/include PARENT_SCOPE)

# Add SPIRV-Headers as a sub-project if it isn't already defined.
# Do this so enclosing projects can use SPIRV-Headers_SOURCE_DIR to find
# headers to include.
if (NOT DEFINED SPIRV-Headers_SOURCE_DIR)
add_subdirectory(${SPIRV_HEADER_DIR})
endif()
else()
message(FATAL_ERROR
"SPIRV-Headers was not found - please checkout a copy at external/spirv-headers.")
endif()

Copy link
Collaborator

Choose a reason for hiding this comment

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

You cannot remove this. We cannot change the way it works for existing users. This would break many projects.

Copy link
Author

Choose a reason for hiding this comment

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

You cannot remove this. We cannot change the way it works for existing users. This would break many projects.

I see, so the dependencies would need to be cloned to the same places?

Copy link
Collaborator

@s-perron s-perron Feb 5, 2025

Choose a reason for hiding this comment

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

Consider how spirv-tools is used in https://github.com/google/shaderc. This repo has two "submodule" that use spirv-headers: glslang, spirv-tools. Shaderc does not want to compile with two different versions of spriv-headers for these tools, so it will checkout its own version, and tell glslang and spirv-tools where to find it:

https://github.com/google/shaderc/blob/ab0d3ed184e4919a236eecddb6514e4923a5e38f/third_party/CMakeLists.txt

In the SPIR-V tools cmake files, we have no way of knowing which version the parent project wants to use nor do we know where they have put it. A few other tools are the same way.

If you want to use find_package you cannot change the behaviour of existing working project. You might want to replace the fatal error with the call to find_package, with an error if that fails for some reason. Do not change the rest of the logic.

@vikke1234
Copy link
Author

I don't know how the fetch works, but I'm pretty sure this would break the choromium builds because they want to pick their version for each of our dependencies.

Can you elaborate? Do they provide a different configuration file for pulling the dependencies?

@s-perron
Copy link
Collaborator

s-perron commented Feb 5, 2025

I don't know how the fetch works, but I'm pretty sure this would break the choromium builds because they want to pick their version for each of our dependencies.

Can you elaborate? Do they provide a different configuration file for pulling the dependencies?

You can try building shaderc with your change in third_party. I get this error:

-- Fetching  SPIRV-Headers...
CMake Error at build/_deps/spirv-headers-src/CMakeLists.txt:34 (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
  "/usr/local/google/home/stevenperron/spirv/shaderc/third_party/spirv-headers".
  See documentation for policy CMP0002 for more details.

SPIRV-Headers will already be defined by shaderc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants