Update FindVulkan.cmake to cross-compile for Windows/Windows on ARM64#1490
Update FindVulkan.cmake to cross-compile for Windows/Windows on ARM64#1490fgiancane8 wants to merge 9 commits intoKhronosGroup:mainfrom
FindVulkan.cmake to cross-compile for Windows/Windows on ARM64#1490Conversation
Let CMake use its own bundled version of this module. It is more maintained and has some quality of life fixed, most notably cross-compilation on Windows(ARM64/Intel). See KhronosGroup#1489 for more context about this change.
|
|
|
This is failing on iOS because the standard version of FindVulkan.cmake is missing the following code. In contrast, this code is present in the downstream project version: Possible solutions:
Option 3 is likely the best IMHO and would retain your main objective for this PR. The updated CMakeLists.txt code would look like this: |
|
Thanks for testing @SRSaunders You're exactly right. While we are not quite to the point where we can do a complete removal of findVulkan.cmake in favor of a package maintained config variation; which would be the ultimate correct solution. I think, if possible we should promote these changes back to kitware's gitlab version; then remove the copy here. In the meantime, we should at a minimum accept the upstream changes to our copy of findVulkan.cmake. |
|
Thanks @gpx1000. Just to clarify, Option 1 (merge upstream changes into the project's FindVulkan.cmake) and Option 3 (remove FindVulkan.cmake and patch CMakeLists.txt) are mutually exclusive - we should do one or the other, but not both. Option 2 could happen in parallel regardless and let that process take its course. |
|
I'm not a fan of option 3; it invites a lot of questions as to why it's required and encourages end users to think the top level CMakeLists.txt is too complex to learn anything from (a feedback item we're already receiving). As much as possible, I want to encourage the "best practice" of using find_library(vulkan) being the universal only thing that is needed by end users beyond needing the findVulkan.cmake file if necessary. |
|
Note that there is a discussion on removing the FindVulkan.cmake from CMake: https://gitlab.kitware.com/cmake/cmake/-/issues/25617 |
|
Thanks @SaschaWillems. From the discussion link it seems that Option 1, i.e. merging upstream changes and retaining the project-specific FindVulkan.cmake, is the right way to go. While it appears that Kitware is still accepting changes to the FindVulkan module, the longer term view is that downstream projects should handle it themselves. |
|
Hello and thanks for all the feedbacks! So I started already the discussion with upstream CMake and sounds like the accepted go-to is to at some point remove In the meanwhile what I can do is:
Let me know what you all folks think about. |
Reached out to upstream CMake folks to further clarify. This issue was linked to my previous Pull Request for |
So my understanding on this is that the split would be a requirement since Vulkan on Linux is managed by distro packagers, while on Windows/iOS/macOS is packaged with LunarG SDK. Android is managed by Android SDK itself. So it would make sense to keep the upstream version as much updated as possible so that:
This is what I feel would be the best outcome but let's discuss, I'd like to reach for a conclusion that works for all these major platforms without duplicating too much between vendored/downstream/upstream. |
Seems like it's not on priority list and will take time to materialise. The thread got revived today with similar issues. So as of now, it's basically mostly on upstream CMake and this repo. |
|
FYI: https://gitlab.kitware.com/cmake/cmake/-/issues/27661 Upstream CMake provided a recommended way to build on iOS. They recommended us to have an iOS toolchain file and amend the way we search for the Vulkan SDK. I'll try and post another commit to see if that fixes the issue. |
As per upstream CMake recommendations, configure iOS targets using a toolchain file.
Move all the variables that were passed through command line here, as per CMake upstream recommendation.
|
Thanks for tracking this down and working with kitware on this. The toolchain file idea is not a bad one. We might want to think if there's a way to do additional toolchain files as downstream projects from us (i.e. lots of people copy paste directly out of samples) might use toolchain files for project specific needs and this might inhibit their use if we take up the project's sole toolchain slot. This concern might be addressed via documentation and highlighting the toolchain requirement. But, it is worth considering if we want this for best practice recommendations which samples are meant to be. |
No worries at all!
@gpx1000 , |
|
Well, all platforms technically can use Vulkan Samples, so everything from a rPi / wrist watch to desktop or server rack or XR development rig including the Apple headset, watch, phone, TV, car etc could all be potential platform end points. Each are popular places to have a toolchain. It might be exceedingly rare to the point of not even the SDK has a pre-made build for such platform. But, each does have a potential role as a target end platform. Samples are useful to validate that Vulkan is working on newer unreleased systems as well; so it's hard to predict where it might be used and we try to opt for practices in general that don't make assumptions about what end users might require. If we can make a decision that doesn't restrict users that's what we typically try to do. |
Makes sense. So in my mind:
|
|
By the way, I see we do not yet build for Windows on ARM64. Since this change is exactly trying to validate that, maybe that target should be added as well. |
|
Well we can keep this solely targeted to iOS. It's just important to remember the scope of potential platforms when we make decisions like using a toolchain file vs not. Yes, we can add windows ARM64 build to the CI, but CI in windows already takes a really long time and it's something I've been struggling to find ways to make faster already. I'm hesitant to add more to the CI for windows until I can get the build time reduced on windows. |
Sure, was just sharing couple of ideas to brainstorm on the subject. Let's see if these changes are enough to better align with upstream CMake. We can take further action from there. Thanks! |
|
Good news, build for iOS correctly detected 🚀 Vulkan-Samples/app/CMakeLists.txt Lines 138 to 148 in 19a5668 |
|
iOS is a bit more complicated than just finding the pre-installed Vulkan runtime libraries and dynamically linking to them at runtime which is all you need on most desktop platforms. iOS and other device-oriented Apple platforms (e.g. iPad, AppleTV) require packaging all library dependencies (i.e. MoltenVK.framework and optionally Vulkan.framework and VkLayer_khronos_validation.framework) into an app bundle for installing onto a physical device or device simulator. Because of this Vulkan-Samples needs to know specific library locations so Xcode can build the app bundle and load onto the chosen device or simulator for execution and debugging. The locations are identified by CMake variables set by find_package(Vulkan) which uses project's FindVulkan.cmake as the underlying module. The cmake variables are: I guess this is a long-winded way of saying that any replacement for the FindVulkan.cmake module needs to take these variables into account and define them, or if not possible, change the iOS logic in the above two files to accommodate. The latter is possible but not that much fun as it would mandate a bunch of retesting. And since I was the last person to update most of this iOS-specific logic it would likely fall to me or @gpx1000. With that said, if the only error is an undefined Note that my original Option 3, which @gpx1000 did not like due to adding complexity to the main CMakeLists file, solved the problem without any change to the logic in the two files named above. As an alternative, I could move the same logic from Option 3 into global_options.cmake instead, since that file calls |
|
Going back to the beginning, and perhaps I am missing something here, but given the following: from @fgiancane8:
from @gpx1000:
Why are we trying to change FindVulkan.cmake if Windows ARM64 was the reason for this PR, but will not be added to the project as an official target with CI, at least for now? In spite of the discussion regarding technical alternatives above, iOS currently works just fine with no changes to the project's current FindVulkan.cmake. Is the request in this PR therefore to provide "unofficial" support for Windows ARM64? i.e. allow it to work without adding it as a CI target? Before jumping into cmake changes, I would like to understand the reason and scope. |
Checked upstream CMake, and only
So I posted an update on this. Looks like the SDK is properly detected, but it fails at the app/CMakeLists.txt because of the packaging as resource command over there. I don't really know what's going on there so an explanation would be very appreciated as well! (I am no iOS/macOS developer, only know the ways of Linux and Windows).
Thanks for the super detailed explanation, really appreciated it! |
So the reason for this PR was to fix issues when cross-compiling Vulkan apps to and from ARM64. As of now either Intel machine to ARM64 machine or ARM64 machines to Intel builds are broken. I posted a fix upstream and since there is the whole discussion of unifying the modules, plus CMake will eventually remove their module in favour of LunarG's one (whenever it happens), I was trying to be nice and have a working solution for all Vulkan platforms in place.
Not at all. We can discuss WoA on a separate issue/PR if needed. The goal here was to enable people to cross compile on Windows for both its supported architectures (Intel/ARM64) since LunarG is shipping SDKs supporting both targets. Also a note on the "unofficial": as far as I can tell, LunarG SDK on Windows officially supports Windows on ARM64, shouldn't we consider that enough to mark the target as official? Not saying we need to add CI and strong testing today, maybe tier 2? I would expect people to at some point start playing with Vulkan Samples on those machines as well. What's your thoughts on this? |
Thanks for your clear restatement of the issue. Are Windows ARM64 native builds working with the current project cmake files? Is it only the Windows cross compilation scenarios that aren't? I know from my own efforts that macOS arm64 (Apple Silicon) native builds do work without issue, and cross compiling from macOS x86_64 hosts to iOS arm64 targets also works fine.
Regarding expanding Vulkan-Samples official supported platforms list, that is above my pay grade 😄. I am a contributor with expertise in Apple platforms, but not a maintainer here. Please ask @gpx1000 about whether Windows on ARM64 and Win x86_64 to ARM64 cross-compilation builds (and vice versa) are within the project's scope. As an aside I don't have the hardware for testing those scenarios so can't really contribute on that side of things. To keep things moving on the technical side for possibly removing the project FindVulkan.cmake, can you tell me specifically what you did to generate the cmake error at app/CMakeLists.txt:140 (target_sources):? Okay, I see that you posted new commits. I will have a look at those first... |
|
@fgiancane8 the error caused by an undefined In Vulkan-Samples/app/CMakeLists.txt add the following line: Your solution with the toolchain file finds the iOS Vulkan frameworks because of updating
See the following link for docs on how to build for iOS: https://github.com/KhronosGroup/Vulkan-Samples/blob/main/docs/build.adoc#ios I suppose we could make 3 toolchain file for iOS:
However, this toolchain stuff feels a bit of overkill for the problem at hand. Only two small things really have to change to make this PR (i.e. remove project FindVulkan.cmake) work:
I have tried this and it works fine with no toolchain files. Nothing else has to change, including CI and docs. The only downside is that the project FindVulkan.cmake also defines layer cmake variables: |
No problem at all. So I haven't tested it extensively. We had couple of issues with other projects using Vulkan on Windows on ARM64. I fixed them on CMake upstream initially (as there were some relics of x86 era SDK and no proper management of ARM64). As far as I can tell, with my changes on upstream CMake all the combinations of Windows flavours and Vulkan work.
Haha of course nothing binding here, was talking about community effort altogether. Not expecting to leave all the burden on you (or other solo efforts as well!)
I let the CI here do its own tests. You can find the full log failures here: https://github.com/KhronosGroup/Vulkan-Samples/actions/runs/22683125940/job/65768554240 Just for reference: I would consider the proper/official/recommended command line to build on iOS targets. |
The cmake toolchain file was recommended by upstream CMake maintainers as "best practices" for Vulkan on MacOS/iOS use case. I linked this PR in their repository, just in case someone from them wanted to step into the discussion.
Acked.
Ok, sure. I'll let you think over it. That line was added in the toolchain file for iOS as well. As I said before I am not iOS/MacOS developer myself so any good input is very welcomed! I can take the lead if needed on updating any file(s) if required.
I think this is a good opportunity to contribute this downstream change back to upstream CMake. I can re-open my issue and post these variables, so that we are perfectly in sync and we don't miss any feature downstream. I see value in having a "single-source-of-truth" in upstream CMake for Vulkan users, considering the ultimate goal to be LunarG to take in charge the maintenance of this module for the SDK moving forward. |
Removing downstream vendored version of `FindVulkan.cmake` caused this variable to disappear. Compute it again where it is needed. KhronosGroup#1490 (comment) for the full discussion.
I did a double-check with a colleague of mine (@aarnaud1) and he told me that Vulkan Layers are loaded at run-time by the Vulkan loader. So there's no need for them to be searched for and eventually found at build time. Unless there is a use case for iOS/MacOS. Can these platforms load those layers through the loader? |
|
@fgiancane8 I am not too worried about the defintion of However, I still have concerns about this PR in general:
Before we go any further here, I would like @gpx1000 and possibly others to weigh in on whether removal of the project's FindVulkan.cmake is an agreed-to objective, or if augmenting the current project file to support Windows ARM64 uses cases (including cross-compilation) would be better. |
I posted another commit that includes your recommended change into the CMakeLists.txt, effectively following your first suggestion, so that we do not break command line build for others. Toolchain files can be added on top of this PR or on a follow-up one.
I see your point here, and you're right. The problem is that when you diverge from upstream, it is always going to be painful. From my side there's no rush to merge this change as it is (we can always resort to the trick of deleting the file locally and succeed building/cross-compiling). I feel though things need to start moving, as otherwise we would always be stuck in an endless loop of CMake waiting for LunarG, LunarG waiting for CMake and Khronos repositories and so on. As you said let's discuss better and weight all the possible scenarios here. I do not want this to be necessarily merged, I just wanted to draw a line and plan on how to move on from here, all things considered.
Ok, let's keep the discussion open and continue. I am fine eventually porting my upstream changes from cmake to this version if that's a first step to converge. I thought there was consensus on the unification idea based on this comment: #1490 (comment) but let's review the current state of things since many commits have happened in between :) Thanks! |
I was talking about adding I still want to hear back from @gpx1000 and possibly other project maintainers about overall objectives re FindVulkan.cmake - i.e. remove or augment. |
Oh I see, I did it in the toolchain so I didn't bother.
|
Your colleague is correct for desktop applications (including Windows, Linux, macOS), but not for iOS device applications. If an iOS app requires a Vulkan Layer, the layer library (e.g. Pushing the cmake layer variables upstream would likely be a good idea. This is one of the specific issues that gives me pause about removing the project's FindVulkan.cmake prematurely. They may be other issues (perhaps on other platforms) that would have to be discovered through regression testing before taking this step. |
|
I can offer one idea that may be of use for moving forward here: Change the iOS build to be fault tolerant regarding removal of the project's FindVulkan.cmake, but don't actually remove the file until differences are pushed upstream and become generally available in cmake distros (e.g. homebrew). For example, the specific difference re To achieve this "iOS build fault tolerance" goal I think your cmake toolchain idea is viable. I would be happy to design a common ios.cmake toolchain file that could be used across CI and user builds for ios and ios-sim. And along with this, I would also provide necessary changes to the CI command and iOS build docs on the project site. In return I would ask you to revert the removal of FindVulkan.cmake in this PR, or potentially close it and I could open a different PR with the required iOS build and documentation changes. Perhaps you could also open a new PR with required additions to enable Win ARM64 use cases to the project’s FindVulkan.cmake. Would this be a viable option for you and @gpx1000? |
We came to the same conclusion but thanks for reiterating on this and thus giving confirmation. I can prepare a patch for the upstream to port these variables. Maybe it's worth exporting all the layers that I can find up to today from the SDK and maybe doing it conditionally only on Apple/IOS. |
Agreed! Let's do it.
Sounds nice! I can add these two tasks to my backlog:
Do we want to continue the work on top of this branch, or split the changes independently? I am fine separating iOS-specific changes from this one and keeping this branch only for when the time is right to deprecate/remove the downstream module. |
Excellent!
I would prefer to split it. I will handle the iOS build/doc changes with a new PR, and you can handle this PR plus any new work on FindVulkan.cmake for Windows on ARM64. However, please back out the iOS stuff in here to prevent confusion going forward. |
|
Sorry guys, I'm trying to catch up. It looks like everything you're doing is reasonable. It might need to wait for the Samples phone call on Monday to get a lot of us maintainers able to review in depth. However, to give feedback now, I do like the direction (I think), I still need to catch up myself and make sure I fully understand it. |
Sure thing. I'll revert changes on iOS and let you do your own stuff in parallel. Maybe we can use the issue that I opened prior to this PR to track efforts. |
Thanks @gpx1000 ! Take your time for the review,there's no rush. Have a good one and for further clarifications just ping me/us. |
This reverts commit 1a672f7.
This reverts commit 6f1680f.
This reverts commit 265d313.
Backport these patches into our downstream `FindVulkan` CMake module:
5e1440302a FindVulkan: Add support for cross-compiling between Windows x64/ARM64
f9a09f76f3 FindVulkan: Drop support for 32-bit SDK on Windows
b40740f28a FindVulkan: Do not search bin directories for libraries
947adbba91 FindVulkan: Use ENV{VULKAN_SDK} only if it exists
This allows proper libraries discovery of Vulkan Libraries on Windows,
both for x86_64 and ARM64 targets.
Co-Authored-By: Brad King <brad.king@kitware.com>
Tested-By: Giancane, Francesco <fgiancan@qti.qualcomm.com>
FindVulkan.cmakeFindVulkan.cmake to cross-compile for Windows/Windows on ARM64
|
@SRSaunders P.S. if this is ever going to be merged, please squash the commit logs with the PR text otherwise we'll get a lot of unpleasant "revert xxxx" not super cool :) |
Thanks @fgiancane8, I will review this weekend. In the mean time I have submitted my PR with the iOS build changes. I cited you in the copyright notice for the new ios.cmake toolchain file. Thanks for your help on this. |
Thanks @SRSaunders enjoy the weekend and let me know if there is something to amend. I could not post the downstream changes to CMake but will do it either this weekend or on Monday. Talk to you later! |
Backport patches from upstream CMake to support Windows cross-compilation use cases (
x86_64toARM64and vice-versa).Upstream patches backported:
5e1440302a FindVulkan: Add support for cross-compiling between Windows x64/ARM64
f9a09f76f3 FindVulkan: Drop support for 32-bit SDK on Windows
b40740f28a FindVulkan: Do not search bin directories for libraries
947adbba91 FindVulkan: Use ENV{VULKAN_SDK} only if it exists
See #1489 for more context about this change.
General Checklist:
Please ensure the following points are checked:
My code follows the coding styleI have commented any added functions (in line with Doxygen)I have commented any code that could be hard to understandI have used existing framework/helper functions where possibleNote: The Samples CI runs a number of checks including:
I have updated the header Copyright to reflect the current year (CI build will fail if Copyright is out of date)