Skip to content

Restore WindowsAI CMake sample to support WinAppSDK 1.8 Experimental 2 - #474

Merged
Jon Wiswall (jonwis) merged 12 commits into
release/experimentalfrom
user/jonwis/sparse-packaged
Jun 2, 2025
Merged

Restore WindowsAI CMake sample to support WinAppSDK 1.8 Experimental 2#474
Jon Wiswall (jonwis) merged 12 commits into
release/experimentalfrom
user/jonwis/sparse-packaged

Conversation

@Scottj1s

Copy link
Copy Markdown
Member

Changes include:

  • Adding sparse packaging for new package identity requirement
  • Updating main.cpp for Windows AI breaking API changes
  • Adding support for WinAppSDK 1.8 metapackage refactoring

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

This PR restores the Windows AI CMake sample to support the WinAppSDK 1.8 Experimental 2 release by updating packaging, CMake configuration, and main application code. Key changes include:

  • Adding and updating vcpkg port files for WindowsAppSDK support.
  • Modifying main.cpp to accommodate Windows AI breaking API changes.
  • Adjusting project configuration files (CMakeLists.txt, AppxManifest.xml, etc.) to align with experimental package requirements.

Reviewed Changes

Copilot reviewed 23 out of 23 changed files in this pull request and generated no comments.

Show a summary per file
File Description
Samples/WindowsAIFoundry/cpp-console-sparse/vcpkg_ports/windowsappsdk/windowsappsdk-config.cmake Added imported target configurations for WindowsAppSdk libraries.
Samples/WindowsAIFoundry/cpp-console-sparse/vcpkg_ports/windowsappsdk/vcpkg.json Introduced a new package configuration for WindowsAppSDK experimental version.
Samples/WindowsAIFoundry/cpp-console-sparse/vcpkg_ports/windowsappsdk/portfile.cmake Updated portfile to acquire and install WindowsAppSDK and generate C++/WinRT headers.
Samples/WindowsAIFoundry/cpp-console-sparse/main.cpp Updated sample code to handle Windows AI API changes and process command-line arguments.
Other project files (vcpkg.json, vcpkg-configuration.json, AppxManifest.xml, etc.) Modified to support the new package identity and experimental package deployment.
Comments suppressed due to low confidence (2)

Samples/WindowsAIFoundry/cpp-console-sparse/main.cpp:27

  • [nitpick] The variable name 'instructions' could be more descriptive; consider renaming it to 'systemPrompt' to clearly indicate its purpose as the static system prompt.
std::wstring instructions = L"You are a clever storyteller. You write engaging one-paragraph stories that grab the imagination of an 8th grader. Tell a story about a dragon who says: ";

Samples/WindowsAIFoundry/cpp-console-sparse/CMakeLists.txt:43

  • [nitpick] The variable 'ONEFILE' is ambiguous; renaming it to 'dllFile' or a similar descriptive name would improve code clarity.
foreach(ONEFILE ${TARGET_RUNTIME_DLLS})

"generator": "Ninja",
"binaryDir": "${sourceDir}/out/build/${presetName}",
"architecture": {
"value": "x64",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Turns out that Ninja does not support setting the architecture, so all these are effectively the same (Ninja uses the values that vcvarsall.bat set from the "x64 native tools prompt" you're running in.)

Don't change anything now, but you can't actually use Ninja to "cross compile" target architectures. Cc Duncan Horn (@dunhor)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In theory you can get it to work with a properly crafted toolchain file. That said, using the proper vcvars initialization script is significantly easier.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It looks like maybe https://github.com/search?q=CMAKE_SYSTEM_PROCESSOR+Ninja+path%3A**%2F*.cmake&type=code can be used in the CMakePresets.json? Like https://github.com/StereoKit/sk_gpu/blob/14a354bde53d412743c032e98656877300929075/CMakePresets.json#L92 maybe? I'll have to experiment with this in that "make cmake for wil work" thing.

}

#if defined(_M_ARM64)
const auto g_packageArchitecture = PackageDependencyProcessorArchitectures_Arm64;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These are leftovers from the before times, probably not needed anymore.

"sparse packaging" the app from an external location.

To loose deploy (directly from an AppxManifest.xml) a sparse package for the sample,
run the **install.ps1** script after a successful build.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Quick question: Where is the install.ps1 script located? Should this step be mentioned here since the cmake project will register the package (with external location flag) post-build using PowerShell? Thanks!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Drat! Thanks, I'll fix this - there's no install.ps1 needed anymore, the cmakelist autoregisters the output.

@jonwis
Jon Wiswall (jonwis) merged commit 1b5c314 into release/experimental Jun 2, 2025
@jonwis
Jon Wiswall (jonwis) deleted the user/jonwis/sparse-packaged branch June 2, 2025 17:35
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.

5 participants